/
Main.cs
1509 lines (1367 loc) · 61.4 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
namespace SortImage
{
public partial class SortImg : Form
{
// Constants
const int dupFold = 32;
const int toolTipRefreshPx = 25;
//Variables used throughout the program
//TODO Make workingFolders/buttonPictureToggle an array of objects/classes
private string[] workingFolders = new string[64]; // 0-31 are source folders, 32 is dup folder, 33-63 are destination folders
private int[] buttonPictureToggle = new int[64];
private int logline;
private int deletype = 0;
private bool deletAll = false;
private int curfold = 33; // start of destenation folders
private int nextCount = 0;
private int firstTag = 0;
private int renameIteration = 0;
private bool isAnimated = false;
private string filepath = null;
private int sourceCount = 0;
private string bwFold = "";
private int progress = 0;
private bool firstImage = false;
private int lastButtonIndex = 999;
private bool allowMove = true;
private bool is64bit = false;
private string currentToolTipText = "N/A";
private int lastToolTipX;
private int lastToolTipY;
private string lastMoveFolder = "";
private Point selectionStart;
private Point selectionEnd;
private Rectangle selection;
private bool mouseDown;
//Initalized Classes
private Utils32 util32;
private Utils64 util64;
private ArrayList fileCopyedSource;
private ArrayList fileCopyedDestination;
private ArrayList buttonDispose;
private Dictionary<string, int> files;
private List<string> checkedTags;
private Logging logger;
private Button buttonFlashing = null;
private FileNameBuilder fileNameCreator;
private SourceDialog sourceAdd;
private DynamicButtons buttonbuilder;
private SortImgSettings storedSettings;
private ThumbnailController thumbController;
private ThumbnailBuilder thumbnailBuilder;
private ImageMatcherSpeed imageMatcher;
private ImageViewer activeImageViewer;
private Button activePreviewButton;
private PreviewLayer previewPanel;
private ProcessingDialog fmProgress = null;
private Panel panelinner;
private Panel panelload;
private ToolTip imageInfo;
private List<ImageViewer> selectedImageViewers;
private event ThumbnailImageEventHandler OnImageSizeChanged;
//Initalized set variables
private int deskHeight = Screen.PrimaryScreen.Bounds.Height;
private int deskWidth = Screen.PrimaryScreen.Bounds.Width;
private int ImageSize
{
get { return (64 * (trackBarSize.Value + 1)); }
}
delegate void DelegateAddImage(string imageFilename);
private DelegateAddImage addImage;
private void thumbControllerStart(object sender, ThumbnailControllerEventArgs e) { }
private void SortImg_Load(object sender, EventArgs e) { }
private void GetSelectedImageViewers()
{
//Clear before next selection
selectedImageViewers.Clear();
foreach (ImageViewer c in flowLayoutPanelMain.Controls) {
if (selection.IntersectsWith(c.Bounds)) {
selectedImageViewers.Add(c);
}
}
if (selectedImageViewers.Count > 0) {
activeImageViewer = selectedImageViewers[0];
SetPicture();
}
FixActiveSelection();
}
private void ThumbControllerAdd(object sender, ThumbnailControllerEventArgs e)
{
AddImage(e.ImageFilename);
Invalidate();
if (firstImage == false) {
activeImageViewer = (ImageViewer) flowLayoutPanelMain.Controls[0];
FixActiveSelection();
SetPicture();
firstImage = true;
}
}
private void ThumbControllerEnd(object sender, ThumbnailControllerEventArgs e)
{
if (InvokeRequired) {
Invoke(new ThumbnailControllerEventHandler(ThumbControllerEnd), sender, e);
}
}
private void AddImage(string imageFilename)
{
if (InvokeRequired) {
Invoke(addImage, imageFilename);
} else {
int size = ImageSize;
ImageViewer imageViewer = new ImageViewer {
Dock = DockStyle.Bottom,
Width = size,
Height = size,
IsThumbnail = true
};
imageViewer.LoadImage(imageFilename, thumbnailBuilder);
imageViewer.MouseClick += new MouseEventHandler(ImageViewer_MouseClick);
imageViewer.MouseDown += new MouseEventHandler(flowLayoutPanelMain_MouseDown);
imageViewer.MouseMove += new MouseEventHandler(flowLayoutPanelMain_MouseMove);
imageViewer.MouseUp += new MouseEventHandler(flowLayoutPanelMain_MouseUp);
OnImageSizeChanged += new ThumbnailImageEventHandler(imageViewer.ImageSizeChanged);
flowLayoutPanelMain.Controls.Add(imageViewer);
}
}
private void FixActiveSelection()
{
foreach (ImageViewer item in flowLayoutPanelMain.Controls) {
if (selectedImageViewers.Count > 0) {
if (selectedImageViewers.Contains(item)) {
item.IsActive = true;
} else {
item.IsActive = false;
}
} else {
if (activeImageViewer == item) {
item.IsActive = true;
} else {
item.IsActive = false;
}
}
}
}
private void ImageViewer_MouseClick(object sender, MouseEventArgs e)
{
ImageViewer selectedViewer = (ImageViewer)sender;
if ((ModifierKeys & Keys.Shift) != Keys.None && (e.Button & MouseButtons.Left) == MouseButtons.Left) {
if (selectedImageViewers.Contains(selectedViewer)) {
selectedImageViewers.Remove(selectedViewer);
if (selectedImageViewers.Count > 0) {
activeImageViewer = selectedImageViewers[0];
} else {
UpdatePreviewPanel(true);
}
} else {
activeImageViewer = selectedViewer;
selectedImageViewers.Add(selectedViewer);
}
FixActiveSelection();
SetPicture();
} else if ((e.Button & MouseButtons.Left) == MouseButtons.Left) {
selectedImageViewers.Clear();
activeImageViewer = selectedViewer;
FixActiveSelection();
SetPicture();
} else {
// Right click, thus is a request to remove the preview image
selectedImageViewers.Clear();
if (selectedViewer.ImageLocation == activeImageViewer.ImageLocation) {
MessageBox.Show("Can't remove a highlighted image from queue");
} else {
selectedViewer.Dispose(); // Remove current highlighted
// activeImageViewer = newImageViewer;
Progressupdate(1);
FixActiveSelection();
}
}
UpdatePreviewPanel(false);
}
private void TrackBarSize_ValueChanged(object sender, EventArgs e)
{
try {
OnImageSizeChanged(this, new ThumbnailImageEventArgs(ImageSize));
} catch (Exception) {
}
}
//Main constructor for the form
public SortImg()
{
InitializeComponent();
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Text = string.Format("SortImg (Ver. {0})", version);
DoubleBuffered = true;
is64bit = Utils.Is64BitOperatingSystem(); //Check address space for recycle bin strut construction diffrences.
if (is64bit) {
util64 = new Utils64();
} else {
util32 = new Utils32();
}
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
thumbnailBuilder = new ThumbnailBuilder();
addImage = new DelegateAddImage(this.AddImage);
thumbController = new ThumbnailController();
thumbController.OnStart += new ThumbnailControllerEventHandler(thumbControllerStart);
thumbController.OnAdd += new ThumbnailControllerEventHandler(ThumbControllerAdd);
thumbController.OnEnd += new ThumbnailControllerEventHandler(ThumbControllerEnd);
KeyUp += new KeyEventHandler(Key);
imageInfo = new ToolTip();
imageMatcher = new ImageMatcherSpeed();
logger = new Logging();
buttonbuilder = new DynamicButtons();
Closing += new CancelEventHandler(SortImg_Closing);
fileCopyedSource = new ArrayList();
fileCopyedDestination = new ArrayList();
buttonDispose = new ArrayList();
fileNameCreator = new FileNameBuilder(false);
checkedTags = new List<string>();
selectedImageViewers = new List<ImageViewer>();
storedSettings = new SortImgSettings(Application.StartupPath, logger);
storedSettings.loadSettings(true, true);
sourceAdd = new SourceDialog(storedSettings);
}
private void SortImg_Closing(object sender, CancelEventArgs e)
{
try {
logger.closeLog(logline);
} catch {
System.Diagnostics.Debug.WriteLine("Logger not started");
}
System.Diagnostics.Debug.WriteLine("Closing");
}
private void Delete_Click(object sender, EventArgs e)
{
if (deletAll) {
CopyDelete();
} else {
string deleteOp = "INCORRECT";
DeleteDialog dDialog = new DeleteDialog();
dDialog.StartPosition = FormStartPosition.CenterParent;
if (dDialog.ShowDialog() == DialogResult.OK) {
deleteOp = dDialog.GetString();
}
logger.writeConsole(deleteOp);
if (deleteOp == "INCORRECT") {
logger.writeConsole("No delete type given");
} else if (deleteOp == "CANCEL") {
logger.writeConsole("Delete pick canceled");
} else if (deleteOp == "ALLBIN") {
deletAll = true;
deletype = 1; //Bin
CopyDelete();
} else if (deleteOp == "THISBIN") {
deletype = 1; //Bin
CopyDelete();
} else if (deleteOp == "ALLMARK") {
deletAll = true;
deletype = 0; //Bin
CopyDelete();
} else if (deleteOp == "THISMARK") {
deletype = 0; //Bin
CopyDelete();
} else {
logger.writeConsole("Fall through statment on delete");
}
}
}
//Copy to dup folder button handler
private void ToDupButton_Click(object sender, EventArgs e)
{
Copy(dupFold, null);
}
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
{
logger.closeLog(logline);
Close();
}
private void ResetToolStripMenuItem_Click(object sender, EventArgs e)
{
Appreset();
}
private void AboutToolStripMenuItem_Click_1(object sender, EventArgs e)
{
AboutDialog s = new AboutDialog();
if (s.ShowDialog() == DialogResult.OK) { }
}
private void HelpToolStripMenuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show(Properties.Resources.unimplementedString);
}
private void Undo_Click(object sender, EventArgs e)
{
if (fileCopyedSource.Count != 0 && fileCopyedSource != null) {
string undosource = (string)fileCopyedSource[fileCopyedSource.Count - 1];
string undodest = (string)fileCopyedDestination[fileCopyedDestination.Count - 1];
Button but = (Button)buttonDispose[buttonDispose.Count - 1];
Undoer(undodest, undosource, but);
fileCopyedSource.RemoveAt(fileCopyedSource.Count - 1);
fileCopyedDestination.RemoveAt(fileCopyedDestination.Count - 1);
buttonDispose.RemoveAt(buttonDispose.Count - 1);
} else if (fileCopyedSource.Count == 0 || fileCopyedSource == null) {
MessageBox.Show("No image moves to undo");
} else {
MessageBox.Show("Undo failed");
}
}
// Handler for adding another folder to the list of output folders
private void FoldAdd_Click(object sender, EventArgs e)
{
if (curfold < 63) {
AddNewFolder(curfold);
} else {
MessageBox.Show("Sorry, can't add more folders.");
}
}
private void AddFolders_Click(object sender, EventArgs e)
{
if (sourceAdd.ShowDialog() == DialogResult.OK) {
workingFolders = sourceAdd.GetSourceFolders();
sourceCount = sourceAdd.GetSourceCount();
fileNameCreator.duplicateFolder = workingFolders[dupFold];
storedSettings.saveSettings();
}
DisableButtons(false);
finalFold();
}
private void DisableButtons(bool disable)
{
if (disable == true) {
toDupButton.Enabled = false;
Delete.Enabled = false;
buttonLoadMore.Enabled = false;
skipButton.Enabled = false;
trackBarSize.Enabled = false;
Undo.Enabled = false;
foldAdd.Enabled = false;
toDupButton.Enabled = false;
butOrignText.Enabled = false;
addTag.Enabled = false;
pictureBox1.Enabled = false;
tagList.Enabled = false;
} else if (disable == false) {
toDupButton.Enabled = true;
Delete.Enabled = true;
buttonLoadMore.Enabled = true;
skipButton.Enabled = true;
trackBarSize.Enabled = true;
Undo.Enabled = true;
foldAdd.Enabled = true;
toDupButton.Enabled = true;
butOrignText.Enabled = true;
addTag.Enabled = true;
pictureBox1.Enabled = true;
tagList.Enabled = true;
}
}
/// <summary>
/// Sets the picture box to the picture that the program is currently pointing to. Also the
/// way the picture is displayed
/// </summary>
private void SetPicture()
{
try {
string imagePath = GetFilePath();
if (imagePath == null) {
pictureBox1.Image = Properties.Resources.fill;
} else if (!File.Exists(imagePath)) {
MessageBox.Show("That image has been moved already!");
UpdatePreview(true, null, false);
Progressupdate(1);
} else {
Image tmpImage = Image.FromFile(imagePath);
isAnimated = ImgUtils.IsAnimated(imagePath, tmpImage);
try {
name.Text = "...\\" + Path.GetFileName(imagePath);
newName.Text = "..." + fileNameCreator.fileNameBuilder(GetFilePath(), "", checkedTags, renameIteration)[0];
} catch (InvalidOperationException) { }
try {
pictureBox1.Image = new Bitmap(tmpImage);
tmpImage.Dispose();
Invalidate();
} catch (Exception ex) {
pictureBox1.Image = Properties.Resources.corrupt;
logger.writeLogError("Issue setting picture", ex);
}
}
} catch (IOException e) {
pictureBox1.Image = Properties.Resources.corrupt;
logger.writeLog("Picture Likely Corrupt", 0);
logger.writeConsoleError("Picture likely corrupt", e);
}
}
/// <summary>
/// Get the file path of the current focus of the program
/// </summary>
/// <returns>String containing the file path</returns>
private string GetFilePath()
{
if (activeImageViewer != null) {
allowMove = true;
return activeImageViewer.ImageLocation;
} else {
allowMove = false; // Block moving if no valid image is shown
return null;
}
}
private void processImageDirectory()
{
firstImage = false;
allowMove = true;
thumbController.OrderBy = storedSettings.OrderBy;
for (int i = 0; i < sourceCount; i++) {
if (workingFolders[i] != null) {
thumbController.LoadFolder(workingFolders[i]);
}
}
int tempvar = (thumbController.fileCount + progress);
imagesProgressBar.Maximum = tempvar;
thumbController.LoadSet();
}
private void moveImage(string source, string destination, int iter, Button callbackButton)
{
string[] targetPaths = fileNameCreator.fileNameBuilder(source, destination, checkedTags, iter);
string targetPath = targetPaths[0];
string duplicatePath = targetPaths[1];
try {
if (!File.Exists(source)) {
MessageBox.Show("That image has been moved already!");
// UpdatePreview(true, null, false);
} else if (File.Exists(targetPath)) {
// Duplicate file name check. This is a basic 1 to 1 file check
long sourceSize = imageMatcher.CalcSize(source);
long targetSize = imageMatcher.CalcSize(targetPath);
if ((sourceSize == targetSize) && (iter == 0)) {
// There are the same name and same size and it is not currently iterating
dupPopup(source, targetPath, duplicatePath, destination, callbackButton, targetSize, iter, false, "Same File");
} else {
iter++;
moveImage(source, destination, iter, callbackButton);
}
} else if (allowMove) {
if (storedSettings.DuplicateCheckMode == 1) {
if ((imageMatcher.CheckImage(source, targetPath) == true)) {
logger.writeConsole("File " + targetPath + " is not a duplicate");
ioMove(source, targetPath, callbackButton);
logger.writeLog("Moving File", logline);
logger.writeLog(("Source " + source + "||" + "Dest " + targetPath), logline);
} else {
dupPopup(
source,
imageMatcher.GetLastMatch(),
duplicatePath,
destination,
callbackButton,
imageMatcher.CalcSize(source),
iter,
true,
"Visual Duplicate"
);
}
} else {
logger.writeConsole("File " + targetPath + " is not a duplicate");
ioMove(source, targetPath, callbackButton);
logger.writeLog("Moving File", logline);
logger.writeLog(("Source " + source + "||" + "Dest " + targetPath), logline);
}
} else {
MessageBox.Show("Not allowed to move this file!");
}
} catch (Exception e) {
logger.writeLogError("Issue moving file", e);
}
}
private void dupPopup(string source, string dest, string dest2, string Destination, Button but, long size, int iter, bool noRename, string text)
{
DupDialog dupDia = new DupDialog(Path.GetFileName(source), dest, size, noRename, text);
dupDia.StartPosition = FormStartPosition.CenterParent;
if (dupDia.ShowDialog() == DialogResult.OK) {
string selection = dupDia.GetString();
if (selection == "DELETE") {
Deleter(source);
} else if (selection == "DUP") {
moveDup(source, dest2, iter, but);
logger.writeLog("Double up file moving to dup directory", logline);
logger.writeLog(("Source " + source + "||" + "Dest " + dest2), logline);
} else if (selection == "RENAME") {
iter++;
logger.writeConsole("iterating renamer");
moveImage(source, Destination, iter, but);
}
}
}
private void moveDup(string source, string destination, int iter, Button but)
{
try {
if (File.Exists(destination) == false && allowMove) {
ioMove(source, destination, but);
} else if (!allowMove) {
MessageBox.Show("Not allowed to move this file!");
} else {
iter++;
string tempPath = Path.GetDirectoryName(destination);
string tempFileName = Path.GetFileNameWithoutExtension(destination);
string tempExt = Path.GetExtension(destination);
string newdestination = tempPath + " \\" + tempFileName + "\\" + "_" + iter + tempExt;
moveDup(source, newdestination, iter, but);
}
} catch (Exception e) {
logger.writeLogError("Issue moving duplicate", e);
}
}
private void ioMove(string source, string destination, Button but)
{
try {
fileCopyedSource.Add(source);
fileCopyedDestination.Add(destination);
buttonDispose.Add(but);
logline++;
File.Move(source, destination);
} catch (IOException e) {
logger.writeLogError("Issue moving file", e);
throw;
}
}
/// <summary>
/// Update call for the thumbnail preview
/// </summary>
/// <param name="dispo">dispose the current selected image</param>
/// <param name="filename">file to insert: Accepts null</param>
/// <param name="toFront">Load file to front of que or back</param>
/// <param name="updateProg">Load file to front of que or back</param>
private void UpdatePreview(bool dispo, string filename, bool toFront)
{
// activeImageViewer.IsActive = false;
FixActiveSelection();
if (dispo == true) {
activeImageViewer.Dispose();
}
if (filename != null) {
if (toFront) {
thumbController.PushFile(filename);
} else {
thumbController.QueFile(filename);
}
}
UpdatePreviewPanel(true);
}
private void UpdatePreviewPanel(bool selectFirst)
{
if (flowLayoutPanelMain.Controls.Count < (thumbController.ImageLoadAmount / 2)) //Check if to load more images from the queue
{
thumbController.LoadSet();
}
if (flowLayoutPanelMain.Controls.Count > 0) //Check if there are still images to process
{
if (selectFirst == true) {
activeImageViewer = (ImageViewer) flowLayoutPanelMain.Controls[0];
FixActiveSelection();
SetPicture();
}
} else //No images in the preview panel
{
activeImageViewer = null; //No image, no focus
SetPicture();
MessageBox.Show("Out of images");
DisableButtons(true); //Disable buttons till more folders are added
}
}
/// <summary>
/// Increment the progress bar
/// </summary>
private void Progressupdate(int incdec)
{
if (incdec == 1 && allowMove == true) {
progress++;
imagesProgressBar.Increment(1);
} else if (incdec == -1) {
progress--;
imagesProgressBar.Increment(-1);
}
}
/// <summary>
/// This is the main methord called via buttons to copy file. Handles end of file list special case
/// otherwise just calls mover() and next()
/// </summary>
/// <param name="num">Refrence to the place in array of the dest folder</param>
private void Copy(int num, Button but)
{
String fileName = GetFilePath();
if (fileName == null) {
MessageBox.Show("Can't move nothing!");
} else {
//If there is a mutiselect
if (selectedImageViewers.Count > 0) {
foreach (ImageViewer viewer in selectedImageViewers) {
activeImageViewer = viewer;
//activeImageViewer.IsActive = true;
FixActiveSelection();
moveImage(viewer.ImageLocation, workingFolders[num], 0, but);
Progressupdate(1); //Update the progress bar
UpdatePreview(true, null, false);
}
selectedImageViewers.Clear();
} else {
moveImage(fileName, workingFolders[num], 0, but);
Progressupdate(1); //Update the progress bar
UpdatePreview(true, null, false);
}
}
}
/// <summary>
/// Calls Deleter and the Update
/// </summary>
private void CopyDelete()
{
String fileName = GetFilePath();
if (fileName == null) {
MessageBox.Show("Can't delete nothing!");
} else {
Deleter(fileName);
Progressupdate(1); //Update the progress bar
UpdatePreview(true, null, false);
}
}
/// <summary>
/// Pick new folder
/// </summary>
/// <param name="num">Folder number</param>
private void AddNewFolder(int num)
{
if (lastMoveFolder != "") {
folderBrowserDialog1.SelectedPath = lastMoveFolder;
}
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
if (Directory.Exists(folderBrowserDialog1.SelectedPath)) {
if (StringInArray(workingFolders, folderBrowserDialog1.SelectedPath)) {
MessageBox.Show("The two chosen folders are the same. Please pick different folders");
} else {
try {
workingFolders[num] = folderBrowserDialog1.SelectedPath;
lastMoveFolder = workingFolders[num];
fileNameCreator.duplicateFolder = workingFolders[dupFold];
buttonPictureToggle[num] = 0;
GenerateControl(num);
curfold++;
} catch (IOException e) {
logger.writeLogError("Issue getting folder name from dialog", e);
MessageBox.Show("Issue encountered, please re-pick folder");
}
}
} else {
MessageBox.Show("Directory not created yet, please re-pick folder");
}
}
}
/// <summary>
/// Resets the application
/// </summary>
private void Appreset()
{
try {
logger.closeLog(logline);
} catch (Exception e) {
logger.writeConsoleError("Issue closing log", e);
}
Application.Restart();
return;
}
/// <summary>
/// If string is in array
/// </summary>
/// <param name="haystack">Array of folders</param>
/// <param name="needle">Folder to check against</param>
/// <returns></returns>
private bool StringInArray(string[] haystack, string needle)
{
foreach (string testString in haystack) {
if (testString == needle) {
return true;
}
}
return false;
}
/// <summary>
/// Depending on the setting of the combobox
/// If 0: Copys file to dup folder with the file name taged
/// If 1: Deletes to recyc bin
/// </summary>
/// <param name="fileparth">Parth of file to delete</param>
private void Deleter(string fileparth)
{
if (deletype == 0) {
string name = "zz_DELETE_" + Path.GetFileName(fileparth);
string des = workingFolders[dupFold] + '\\' + name;
moveDup(fileparth, des, 0, null);
logger.writeLog("Marked for deletion", logline);
logger.writeLog(("Source " + fileparth + "||" + "Dest " + des), logline);
} else if (deletype == 1) {
logline++;
if (is64bit) {
util64.moveToRecycle(fileparth);
} else {
util32.moveToRecycle(fileparth);
}
logger.writeLog("Sent to recycling bin", logline);
logger.writeLog(("Source " + fileparth + "||" + "Dest BIN"), logline);
}
}
// Generates the control in this case it is for the output folders
private void GenerateControl(int num)
{
string path = workingFolders[num];
int half = pContainer.Width / 2;
Button dynamicButton = buttonbuilder.DynamicButton(contextMenuStrip1, curfold, half);
dynamicButton.MouseClick += new MouseEventHandler(Button_Click);
dynamicButton.MouseEnter += new EventHandler(dynamicButton_MouseEnter);
Button dynamicPicture = buttonbuilder.DynamicPicture(curfold, Path.GetFileName(path), dynamicButton);
SetbuttonImage(dynamicPicture, path, num);
dynamicPicture.MouseDown += new MouseEventHandler(Picturebox_Click);
pContainer.Controls.Add(dynamicButton);
pContainer.Controls.Add(dynamicPicture);
}
private void dynamicButton_MouseEnter(object sender, EventArgs e)
{
Button clickedButton = (Button) sender; //get the button that was clicked
lastButtonIndex = Convert.ToInt16(clickedButton.Name.Substring("dynamicButton".Length));
}
// Sets the image for the button
private void SetbuttonImage(Button but, string path, int fold)
{
string filepath = Returnfirstimage(path);
if (filepath != null) {
FormHelpers.ApplyButtonImage(but, filepath);
buttonPictureToggle[fold] = 1;
} else {
but.BackgroundImage = global::SortImage.Properties.Resources.zoom_32x32_32;
buttonPictureToggle[fold] = 0;
}
}
private void Button_Click(object sender, MouseEventArgs e)
{
switch (e.Button) {
case MouseButtons.Left:
Button clickedButton = (Button)sender; //get the button that was clicked
string index = clickedButton.Name.Substring("dynamicButton".Length);
Button tempbut = (Button)pContainer.Controls.Find("dynamicPictureBox" + index, true)[0];
Copy(Convert.ToInt16(index), tempbut);
string foldpath = workingFolders[Convert.ToInt16(index)];
if (buttonPictureToggle[Convert.ToInt16(index)] == 0) {
SetbuttonImage(tempbut, foldpath, Convert.ToInt16(index));
}
break;
case MouseButtons.Right:
MessageBox.Show("Unimplemented (Folder re-pick)");
break;
case MouseButtons.Middle:
break;
default:
break;
}
}
private void Hide_Main(bool show)
{
if (show) {
pContainer.Visible = true;
imagesProgressBar.Visible = true;
splitContainer1.Visible = true;
foldAdd.Visible = true;
Undo.Visible = true;
} else {
pContainer.Visible = false;
imagesProgressBar.Visible = false;
splitContainer1.Visible = false;
foldAdd.Visible = false;
Undo.Visible = false;
}
}
// Handler for clicking on the preview pick, showing the folder preview
private void Picturebox_Click(object sender, MouseEventArgs e)
{
switch (e.Button) {
case MouseButtons.Left:
Button clickedButton = (Button)sender;
string index = clickedButton.Name.Substring("dynamicPictureBox".Length);
filepath = workingFolders[Convert.ToInt16(index)];
PreviewBuild(clickedButton);
break;
case MouseButtons.Right:
Button clickeddButton = (Button)sender;
if (clickeddButton.ForeColor == Color.White) {
clickeddButton.ForeColor = Color.Black;
} else {
clickeddButton.ForeColor = Color.White;
}
break;
case MouseButtons.Middle:
break;
default:
break;
}
}
/// <summary>
/// Special case copy for key presses
/// </summary>
/// <param name="buttonPos">This is the index of the button starts at "33"</param>
private void KeyCopy(int buttonPos)
{
string index = Convert.ToString(buttonPos);
Button tempbut = (Button)pContainer.Controls.Find("dynamicPictureBox" + index, true)[0];
flashButtonOn((Button)pContainer.Controls.Find("dynamicButton" + index, true)[0]);
Copy(Convert.ToInt16(index), tempbut);
string foldpath = workingFolders[Convert.ToInt16(index)];
if (buttonPictureToggle[Convert.ToInt16(index)] == 0) {
SetbuttonImage(tempbut, foldpath, Convert.ToInt16(index));
}
}
// Handles key presses. These are hardcoded to the first 6 equivlent buttons on form and delete as well as backspace for undo
private void Key(Object o, KeyEventArgs e)
{
List<int> keyBinds = storedSettings.GetKeyBinds();
if (Convert.ToInt16(keyBinds[0]) == e.KeyValue) {
Delete_Click(null, null);
flashButtonOn(Delete);
} else if (Convert.ToInt16(keyBinds[1]) == e.KeyValue) {
Delete_Click(null, null);
flashButtonOn(Delete);
} else if (Convert.ToInt16(keyBinds[2]) == e.KeyValue) {
Undo_Click(null, null);
flashButtonOn(Undo);
} else if (Convert.ToInt16(keyBinds[3]) == e.KeyValue) {
PreformCopyFromKeyPress(1);
} else if (Convert.ToInt16(keyBinds[4]) == e.KeyValue) {
PreformCopyFromKeyPress(2);
} else if (Convert.ToInt16(keyBinds[5]) == e.KeyValue) {
PreformCopyFromKeyPress(3);
} else if (Convert.ToInt16(keyBinds[6]) == e.KeyValue) {
PreformCopyFromKeyPress(4);
} else if (Convert.ToInt16(keyBinds[7]) == e.KeyValue) {
PreformCopyFromKeyPress(5);
} else if (Convert.ToInt16(keyBinds[8]) == e.KeyValue) {
PreformCopyFromKeyPress(6);
}
}
private void PreformCopyFromKeyPress(int dupFolderOffset)
{
if (workingFolders[dupFold + dupFolderOffset] != null) {
KeyCopy(dupFold + dupFolderOffset);
}
}
// Splash image for when the program is loading the preview
// Note: This is used due to how slow it is loading the thumbnails
// should be changed if I can find how to load thumbnails better
private void Loading()
{
panelload = new Panel() {
Size = mainPanel.Size,
BackgroundImage = global::SortImage.Properties.Resources.loading,
BackgroundImageLayout = ImageLayout.Stretch
};
mainPanel.Controls.Add(panelload);
panelload.BringToFront();
}
// Handeler for the close button for the preview panel
private void ClosePanelButton_Click(object sender, EventArgs e)
{
panelinner.Dispose();
Hide_Main(true);
nextCount = 0;
filepath = null;
}
private void PreviewBuild(Button clickedButton)
{
if (nextCount > 0) {
panelinner.Dispose();
}
activePreviewButton = clickedButton;
panelinner = new TableLayoutPanel();
Loading();
Hide_Main(false);
previewPanel = new PreviewLayer(mainPanel.Size, filepath, activePreviewButton, nextCount);
previewPanel.ClosePanelButton.Text = "Close";
previewPanel.ClosePanelButton.Click += new EventHandler(ClosePanelButton_Click);
previewPanel.nextSetButton.Text = "More...";
previewPanel.nextSetButton.Click += new EventHandler(button1_Click);
mainPanel.Controls.Add(previewPanel.mainpanel);
panelinner = previewPanel.mainpanel;
panelload.Dispose();
panelinner.Dock = DockStyle.Fill;
panelinner.BringToFront();
nextCount++;
}
// Loads the preview panel and creates the buttons for it
private void button1_Click(object sender, EventArgs e)
{
PreviewBuild(activePreviewButton);
}
// Methord to handle the undo, that is moving a file back to where it came from
private void Undoer(String source, String Destination, Button but)
{
try {
if (File.Exists(Destination)) {
logger.writeLog("Error copying back file for undo (Major issue)", logline);
} else {
System.IO.File.Move(source, Destination);
logline++;
logger.writeLog("Moving file (Undo)", logline);