@@ -200,6 +200,7 @@ private void InitLanguage()
200
200
201
201
openBtn . Text = LangMan . Get ( "open" ) ;
202
202
openFileBtn . Text = LangMan . Get ( "open-file" ) ;
203
+ openFolderBtn . Text = LangMan . Get ( "open-folder" ) ;
203
204
openRecursive . Text = LangMan . Get ( "open-recursive" ) ;
204
205
205
206
saveAsButton . Text = LangMan . Get ( "save-as" ) + " | Ctrl+S" ;
@@ -351,7 +352,7 @@ private void showTypeOpsButton(bool show, string type = null)
351
352
} ) ) ;
352
353
}
353
354
354
- private void openFile ( string path )
355
+ private void openFile ( string path , bool goPrev = false )
355
356
{
356
357
try
357
358
{
@@ -435,25 +436,23 @@ private void openFile(string path)
435
436
}
436
437
else
437
438
{
438
- if ( ext == ".gif" )
439
- {
440
- openImage ( new Bitmap ( path ) , Path . GetDirectoryName ( path ) , Path . GetFileName ( path ) ) ;
441
- }
442
- else
443
- {
444
- using ( Image img = Image . FromFile ( path , true ) )
445
- {
446
- openImage ( new Bitmap ( path ) , Path . GetDirectoryName ( path ) , Path . GetFileName ( path ) ) ;
447
- }
448
- }
439
+ openImage ( new Bitmap ( path ) , Path . GetDirectoryName ( path ) , Path . GetFileName ( path ) ) ;
449
440
}
450
441
451
442
if ( ! showTypeOps ) showTypeOpsButton ( false ) ;
452
443
}
453
444
catch
454
445
{
455
- if ( NextFile ( true ) > 1 ) showSuggestion ( LangMan . Get ( "unable-open-file-skipped" ) + ": " + Path . GetFileName ( path ) , SuggestionIcon . Next ) ;
456
- else showSuggestion ( LangMan . Get ( "unable-open-file" ) + ": " + Path . GetFileName ( path ) , SuggestionIcon . Warning ) ;
446
+ if ( goPrev )
447
+ {
448
+ if ( PrevFile ( true ) > 1 ) showSuggestion ( LangMan . Get ( "unable-open-file-skipped" ) + ": " + Path . GetFileName ( path ) , SuggestionIcon . Prev ) ;
449
+ else showSuggestion ( LangMan . Get ( "unable-open-file" ) + ": " + Path . GetFileName ( path ) , SuggestionIcon . Warning ) ;
450
+ }
451
+ else
452
+ {
453
+ if ( NextFile ( true ) > 1 ) showSuggestion ( LangMan . Get ( "unable-open-file-skipped" ) + ": " + Path . GetFileName ( path ) , SuggestionIcon . Next ) ;
454
+ else showSuggestion ( LangMan . Get ( "unable-open-file" ) + ": " + Path . GetFileName ( path ) , SuggestionIcon . Warning ) ;
455
+ }
457
456
}
458
457
}
459
458
@@ -886,37 +885,59 @@ private void saveAsButton_Click(object sender, EventArgs e)
886
885
887
886
if ( saveFileDialog1 . ShowDialog ( ) == DialogResult . OK )
888
887
{
889
- FileStream fs = ( FileStream ) saveFileDialog1 . OpenFile ( ) ;
890
- switch ( saveFileDialog1 . FilterIndex )
888
+ using ( Bitmap bmpToSave = new Bitmap ( originalImage ) )
891
889
{
892
- case 1 :
893
- originalImage . Save ( fs , ImageFormat . Png ) ;
894
- break ;
895
- case 2 :
896
- originalImage . Save ( fs , ImageFormat . Jpeg ) ;
897
- break ;
898
- case 3 :
899
- originalImage . Save ( fs , ImageFormat . Gif ) ;
900
- break ;
901
- case 4 :
902
- originalImage . Save ( fs , ImageFormat . Bmp ) ;
903
- break ;
904
- case 5 :
905
- originalImage . Save ( fs , ImageFormat . Tiff ) ;
906
- break ;
907
- case 6 :
908
- IcoWrapper . ConvertToIcon ( originalImage , fs ) ;
909
- break ;
910
- case 7 :
911
- using ( WebP webp = new WebP ( ) )
890
+ originalImage . Dispose ( ) ;
891
+ originalImage = null ;
892
+ pictureBox . Image . Dispose ( ) ;
893
+ pictureBox . Image = null ;
894
+
895
+ using ( MemoryStream memory = new MemoryStream ( ) )
896
+ {
897
+ using ( FileStream fs = new FileStream ( saveFileDialog1 . FileName , FileMode . OpenOrCreate , FileAccess . ReadWrite ) )
912
898
{
913
- byte [ ] rawWebP = webp . EncodeLossy ( originalImage ) ;
914
- fs . Write ( rawWebP , 0 , rawWebP . Length ) ;
899
+ byte [ ] bytes ;
900
+ switch ( saveFileDialog1 . FilterIndex )
901
+ {
902
+ case 1 :
903
+ bmpToSave . Save ( memory , ImageFormat . Png ) ;
904
+ bytes = memory . ToArray ( ) ;
905
+ fs . Write ( bytes , 0 , bytes . Length ) ;
906
+ break ;
907
+ case 2 :
908
+ bmpToSave . Save ( memory , ImageFormat . Jpeg ) ;
909
+ bytes = memory . ToArray ( ) ;
910
+ fs . Write ( bytes , 0 , bytes . Length ) ;
911
+ break ;
912
+ case 3 :
913
+ bmpToSave . Save ( memory , ImageFormat . Gif ) ;
914
+ bytes = memory . ToArray ( ) ;
915
+ fs . Write ( bytes , 0 , bytes . Length ) ;
916
+ break ;
917
+ case 4 :
918
+ bmpToSave . Save ( memory , ImageFormat . Bmp ) ;
919
+ bytes = memory . ToArray ( ) ;
920
+ fs . Write ( bytes , 0 , bytes . Length ) ;
921
+ break ;
922
+ case 5 :
923
+ bmpToSave . Save ( memory , ImageFormat . Tiff ) ;
924
+ bytes = memory . ToArray ( ) ;
925
+ fs . Write ( bytes , 0 , bytes . Length ) ;
926
+ break ;
927
+ case 6 :
928
+ IcoWrapper . ConvertToIcon ( bmpToSave , memory ) ;
929
+ break ;
930
+ case 7 :
931
+ using ( WebP webp = new WebP ( ) )
932
+ {
933
+ bytes = webp . EncodeLossy ( bmpToSave ) ;
934
+ fs . Write ( bytes , 0 , bytes . Length ) ;
935
+ }
936
+ break ;
937
+ }
915
938
}
916
- break ;
939
+ }
917
940
}
918
- fs . Close ( ) ;
919
-
920
941
setImageChanged ( false ) ;
921
942
CheckRecursiveFolder ( saveFileDialog1 . FileName ) ;
922
943
openFile ( saveFileDialog1 . FileName ) ;
@@ -1271,6 +1292,8 @@ public int NextFile(bool skipNextFile = false)
1271
1292
else
1272
1293
{
1273
1294
if ( skipNextFile ) currentIndex ++ ;
1295
+ if ( currentIndex > filePaths . Length - 1 ) currentIndex = 0 ;
1296
+ if ( skipNextFile ) currentFile = Path . GetFileName ( filePaths [ currentIndex ] ) ;
1274
1297
openFile ( currentIndex == filePaths . Length - 1 ? filePaths [ 0 ] : filePaths [ currentIndex + 1 ] ) ;
1275
1298
return filePaths . Length ;
1276
1299
}
@@ -1281,7 +1304,7 @@ private void nextButton_Click(object sender, EventArgs e)
1281
1304
NextFile ( ) ;
1282
1305
}
1283
1306
1284
- public void PrevFile ( )
1307
+ public int PrevFile ( bool skipPrevFile = false )
1285
1308
{
1286
1309
string [ ] filePaths = GetCurrentFiles ( ) ;
1287
1310
@@ -1295,8 +1318,20 @@ public void PrevFile()
1295
1318
}
1296
1319
}
1297
1320
1298
- if ( currentIndex == - 1 ) showSuggestion ( LangMan . Get ( "cur-file-not-found" ) , SuggestionIcon . Warning ) ;
1299
- else openFile ( currentIndex == 0 ? filePaths [ filePaths . Length - 1 ] : filePaths [ currentIndex - 1 ] ) ;
1321
+ if ( currentIndex == - 1 )
1322
+ {
1323
+ setSlideshow ( false ) ;
1324
+ showSuggestion ( LangMan . Get ( "cur-file-not-found" ) , SuggestionIcon . Warning ) ;
1325
+ return 0 ;
1326
+ }
1327
+ else
1328
+ {
1329
+ if ( skipPrevFile ) currentIndex -- ;
1330
+ if ( currentIndex < 0 ) currentIndex = filePaths . Length - 1 ;
1331
+ if ( skipPrevFile ) currentFile = Path . GetFileName ( filePaths [ currentIndex ] ) ;
1332
+ openFile ( currentIndex == 0 ? filePaths [ filePaths . Length - 1 ] : filePaths [ currentIndex - 1 ] , true ) ;
1333
+ return filePaths . Length ;
1334
+ }
1300
1335
}
1301
1336
1302
1337
private void prevButton_Click ( object sender , EventArgs e )
@@ -1450,6 +1485,7 @@ private void SetDarkMode(bool dark)
1450
1485
1451
1486
openBtn . Image = Properties . Resources . white_open ;
1452
1487
openFileBtn . Image = Properties . Resources . white_imgfile ;
1488
+ openFolderBtn . Image = Properties . Resources . white_picfolder ;
1453
1489
openRecursive . Image = Properties . Resources . white_recursive ;
1454
1490
1455
1491
saveAsButton . Image = Properties . Resources . white_saveas ;
@@ -1665,7 +1701,8 @@ public enum SuggestionIcon
1665
1701
Slideshow = 3 ,
1666
1702
Fullscreen = 4 ,
1667
1703
Next = 5 ,
1668
- Trash = 6
1704
+ Prev = 6 ,
1705
+ Trash = 7
1669
1706
}
1670
1707
1671
1708
public void showSuggestion ( string text , SuggestionIcon icon )
@@ -1691,6 +1728,9 @@ public void showSuggestion(string text, SuggestionIcon icon)
1691
1728
case SuggestionIcon . Next :
1692
1729
suggestionIcon . Image = Properties . Resources . white_next ;
1693
1730
break ;
1731
+ case SuggestionIcon . Prev :
1732
+ suggestionIcon . Image = Properties . Resources . white_prev ;
1733
+ break ;
1694
1734
case SuggestionIcon . Trash :
1695
1735
suggestionIcon . Image = Properties . Resources . white_trash ;
1696
1736
break ;
@@ -2152,7 +2192,7 @@ private void openFileBtn_Click(object sender, EventArgs e)
2152
2192
private void openRecursive_Click ( object sender , EventArgs e )
2153
2193
{
2154
2194
setSlideshow ( false ) ;
2155
- string p = CustomOpenFolderDialog . GetFolder ( ) ;
2195
+ string p = CustomOpenFolderDialog . GetFolder ( LangMan . Get ( "open-recursive" ) ) ;
2156
2196
if ( p != null )
2157
2197
{
2158
2198
recursiveFolder = p ;
@@ -2453,5 +2493,16 @@ private void permDeleteBtn_Click(object sender, EventArgs e)
2453
2493
}
2454
2494
}
2455
2495
}
2496
+
2497
+ private void openFolderBtn_Click ( object sender , EventArgs e )
2498
+ {
2499
+ setSlideshow ( false ) ;
2500
+ string p = CustomOpenFolderDialog . GetFolder ( LangMan . Get ( "open-folder" ) ) ;
2501
+ if ( p != null )
2502
+ {
2503
+ recursiveFolder = null ;
2504
+ openFirstFileInFolder ( p ) ;
2505
+ }
2506
+ }
2456
2507
}
2457
2508
}
0 commit comments