-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormMain.cs
More file actions
2446 lines (2221 loc) · 92.6 KB
/
Copy pathFormMain.cs
File metadata and controls
2446 lines (2221 loc) · 92.6 KB
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
#define Debug
using GitAutoUpdateGUI.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Linq;
using Tools;
namespace GitAutoUpdateGUI
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private readonly Dictionary<string, string> _languageDicoEn = new Dictionary<string, string>();
private readonly Dictionary<string, string> _languageDicoFr = new Dictionary<string, string>();
private string _currentLanguage = "english";
private float _fontSize;
private bool settingsHaveChanged;
private List<string> _previousUpdateFileList = new List<string>();
private void QuitToolStripMenuItemClick(object sender, EventArgs e)
{
SaveWindowValue();
Application.Exit();
}
private void AboutToolStripMenuItemClick(object sender, EventArgs e)
{
AboutBoxApplication aboutBoxApplication = new AboutBoxApplication();
aboutBoxApplication.ShowDialog();
}
/// <summary>Add the version to the title of the main form</summary>
private static string GetApplicationVersion()
{
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
return $" V{fvi.FileMajorPart}.{fvi.FileMinorPart}.{fvi.FileBuildPart}.{fvi.FilePrivatePart}";
}
private void FormMainLoad(object sender, EventArgs e)
{
LoadSettingsAtStartup();
}
private void LoadSettingsAtStartup()
{
Text += GetApplicationVersion();
LoadComboBoxVsVersions(comboBoxVSVersion);
LoadCheckedListBoxVsVersion();
LoadLanguages();
SetLanguage(Settings.Default.LastLanguageUsed);
GetWindowValue();
AdjustAllControls();
CheckGitBashBinary();
CheckGitBashPathInWinPath();
EnableDisableButtons(listViewVSProjects, buttonCheckAll, buttonClearAll, buttonCheckUncheckAll, buttonUpdateVSProjects);
VerifyCheckedVersion();
buttonUpdateCheckedVersion.Enabled = checkedListBoxVSVersion.CheckedItems.Count != 0;
}
private void VerifyCheckedVersion()
{
// disable all versions that don't have an update cmd script
List<string> checkedVersion = GetCheckedItemFromCheckedListBox(checkedListBoxVSVersion);
settingsHaveChanged = true;
string userProfile = Environment.GetEnvironmentVariable("USERPROFILE"); // C:\Users\userName
if (userProfile == string.Empty)
{
DisplayMessageOk(Translate("The USERPROFILE variable cannot be empty"),
Translate("USERPROFILE variable empty"), MessageBoxButtons.OK);
return;
}
string vsVersion = GetNumbers(comboBoxVSVersion.SelectedItem.ToString());
string documentsPath = Environment.SpecialFolder.MyDocuments.ToString();
if (userProfile != null && !Directory.Exists(Path.Combine(userProfile, documentsPath)))
{
documentsPath = Environment.SpecialFolder.MyDocuments.ToString().Substring(2);
}
foreach (var item in checkedVersion)
{
string vsPath = Path.Combine(userProfile, documentsPath, item, "Projects");
if (File.Exists(Path.Combine(vsPath, GetLatestFile(vsPath, "update*.bat"))))
{
// enable item
}
else
{
// disable item
}
}
}
public static string GetLatestFile(string directoryPath, string patternFileName)
{
var directory = new DirectoryInfo(directoryPath);
//string[] allFiles = Directory.GetFiles(directoryPath, searchPattern: patternFileName);
if (Directory.Exists(directoryPath))
{
var result = (from f in directory.GetFiles(patternFileName, SearchOption.TopDirectoryOnly)
orderby f.LastWriteTime descending
select f).FirstOrDefault();
if (result != null)
{
return result.Name;
}
}
return string.Empty;
}
private static List<string> GetCheckedItemFromCheckedListBox(CheckedListBox checkedListBoxVsVersion)
{
List<string> result = new List<string>();
foreach (var item in checkedListBoxVsVersion.CheckedItems)
{
result.Add(item.ToString());
}
return result;
}
/// <summary>Enable or Disable all passed-in controls</summary>
/// <param name="conditionalListView">The list view</param>
/// <param name="listOfControls">The list of controls</param>
private static void EnableDisableButtons(ListView conditionalListView, params Control[] listOfControls)
{
if (conditionalListView.Items.Count == 0)
{
foreach (var control in listOfControls)
{
control.Enabled = false;
}
}
else
{
foreach (var control in listOfControls)
{
control.Enabled = true;
}
}
}
private void CheckGitBashPathInWinPath()
{
checkBoxGitInPath.Enabled = true;
if (IsInWinPath("\\Git\\bin") || GitIsInstalled())
{
checkBoxGitInPath.Checked = true;
checkBoxGitInPath.Text = Translate("GitBash binary path in Windows Path variable");
checkBoxGitInPath.BackColor = Color.LightGreen;
#if Debug
// buttonAddGitBinaryToWinPath.Enabled = true;
#else
buttonAddGitBinaryToWinPath.Enabled = false;
#endif
}
else
{
checkBoxGitInPath.Checked = false;
checkBoxGitInPath.Text = Translate("GitBash binary path not in Windows Path variable");
checkBoxGitInPath.BackColor = Color.Red;
buttonAddGitBinaryToWinPath.Enabled = true;
}
checkBoxGitInPath.Enabled = false;
}
private static bool GitIsInstalled()
{
bool result = false;
List<string> listOfGitInstallation = new List<string>
{
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\cmd",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\mingw32\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\mingw32\\libexec\\git-core",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\cmd",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\mingw32\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Microsoft Visual Studio 14.0\\Web\\External\\git",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\Atlassian\\SourceTree\\git_local\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\Atlassian\\SourceTree\\git_local\\cmd",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\Atlassian\\SourceTree\\git_local\\libexec\\git-core",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\atom\\app-1.20.1\\resources\\app\\node_modules\\dugite\\git\\mingw64\\bin"
};
foreach (string file in listOfGitInstallation)
{
if (!File.Exists($"{file}\\git.exe")) continue;
result = true;
break;
}
return result;
}
private static string GetGitPath()
{
string result = string.Empty;
List<string> listOfGitInstallation = new List<string>
{
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\cmd",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\mingw32\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Git\\mingw32\\libexec\\git-core",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\cmd",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\mingw32\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\\Microsoft Visual Studio 14.0\\Web\\External\\git",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\Atlassian\\SourceTree\\git_local\\bin",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\Atlassian\\SourceTree\\git_local\\cmd",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\Atlassian\\SourceTree\\git_local\\libexec\\git-core",
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Substring(0,21)}\\Local\\atom\\app-1.20.1\\resources\\app\\node_modules\\dugite\\git\\mingw64\\bin"
};
foreach (string file in listOfGitInstallation)
{
if (!File.Exists($"{file}\\git.exe")) continue;
result = $"{file}\\";
break;
}
return result;
}
/// <summary>Check if parameter is in Windows Path</summary>
/// <param name="substring">The string to check</param>
/// <returns>A boolean stating if the string is in Windows path</returns>
private static bool IsInWinPath(string substring)
{
bool result = false;
string winPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
if (winPath != null) result = winPath.Contains(substring);
return result;
}
private static void ClearComboBox(ComboBox comboBox)
{
comboBox.Items.Clear();
}
private void LoadCheckedListBoxVsVersion()
{
checkedListBoxVSVersion.Items.Clear();
if (!File.Exists(Settings.Default.VisualStudioVersionsFileName))
{
CreateVsVersionFile();
}
XDocument xmlDoc;
try
{
xmlDoc = XDocument.Load(Settings.Default.VisualStudioVersionsFileName);
}
catch (Exception exception)
{
MessageBox.Show("Error while loading the " + Settings.Default.VisualStudioVersionsFileName +
" xml file: " + exception.Message);
CreateVsVersionFile();
return;
}
var result = from node in xmlDoc.Descendants("VSVersion")
where node.HasElements
let xElement = node.Element("name")
where xElement != null
select new
{
vsNameValue = xElement.Value,
};
foreach (var q in result)
{
if (!checkedListBoxVSVersion.Items.Contains(q.vsNameValue))
{
checkedListBoxVSVersion.Items.Add(q.vsNameValue, false);
}
}
}
private void LoadComboBoxVsVersions(ComboBox comboBox)
{
ClearComboBox(comboBox);
if (!File.Exists(Settings.Default.VisualStudioVersionsFileName))
{
CreateVsVersionFile();
}
XDocument xmlDoc;
try
{
xmlDoc = XDocument.Load(Settings.Default.VisualStudioVersionsFileName);
}
catch (Exception exception)
{
MessageBox.Show("Error while loading the " + Settings.Default.VisualStudioVersionsFileName + " xml file: " + exception.Message);
CreateVsVersionFile();
return;
}
var result = from node in xmlDoc.Descendants("VSVersion")
where node.HasElements
let xElement = node.Element("name")
where xElement != null
select new
{
vsNameValue = xElement.Value,
};
foreach (var q in result)
{
if (!comboBoxVSVersion.Items.Contains(q.vsNameValue))
{
comboBoxVSVersion.Items.Add(q.vsNameValue);
}
}
comboBoxVSVersion.SelectedIndex = comboBoxVSVersion.Items.Count - 1; // select last item which is the latest version of VS
}
/// <summary>Create a default file if none exist</summary>
private static void CreateVsVersionFile()
{
var minimumVersion = new List<string>
{
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>",
"<VSVersions>",
"<VSVersion>",
"<name>Visual Studio 2003</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2005</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2008</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2010</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2012</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2013</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2015</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2017</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2019</name>",
"</VSVersion>",
"<VSVersion>",
"<name>Visual Studio 2022</name>",
"</VSVersion>",
"</VSVersions>"
};
StreamWriter sw = new StreamWriter(Settings.Default.VisualStudioVersionsFileName);
foreach (string item in minimumVersion)
{
sw.WriteLine(item);
}
sw.Close();
}
/// <summary>Load all languages</summary>
private void LoadLanguages()
{
if (!File.Exists(Settings.Default.LanguageFileName))
{
CreateLanguageFile();
}
// read the translation file and feed the language
XDocument xDoc;
try
{
xDoc = XDocument.Load(Settings.Default.LanguageFileName);
}
catch (Exception exception)
{
MessageBox.Show("Error while loading " + Settings.Default.LanguageFileName +
"xml file " + exception.Message);
CreateLanguageFile();
return;
}
var result = from node in xDoc.Descendants("term")
where node.HasElements
let xElementName = node.Element("name")
where xElementName != null
let xElementEnglish = node.Element("englishValue")
where xElementEnglish != null
let xElementFrench = node.Element("frenchValue")
where xElementFrench != null
select new
{
name = xElementName.Value,
englishValue = xElementEnglish.Value,
frenchValue = xElementFrench.Value
};
foreach (var i in result)
{
if (!_languageDicoEn.ContainsKey(i.name))
{
_languageDicoEn.Add(i.name, i.englishValue);
}
else
{
MessageBox.Show("Your xml file has duplicate like: " + i.name);
}
if (!_languageDicoFr.ContainsKey(i.name))
{
_languageDicoFr.Add(i.name, i.frenchValue);
}
else
{
MessageBox.Show("Your xml file has duplicate like: " + i.name);
}
}
}
/// <summary>Create a new language file if none exist</summary>
private static void CreateLanguageFile()
{
var minimumVersion = new List<string>
{
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>",
"<terms>",
"<term>",
"<name>MenuFile</name>",
"<englishValue>File</englishValue>",
"<frenchValue>Fichier</frenchValue>",
"</term>",
"<term>",
"<name>MenuFileNew</name>",
"<englishValue>New</englishValue>",
"<frenchValue>Nouveau</frenchValue>",
"</term>",
"<term>",
"<name>MenuFileOpen</name>",
"<englishValue>Open</englishValue>",
"<frenchValue>Ouvrir</frenchValue>",
"</term>",
"<term>",
"<name>MenuFileSave</name>",
"<englishValue>Save</englishValue>",
"<frenchValue>Enregistrer</frenchValue>",
"</term>",
"<term>",
"<name>MenuFileSaveAs</name>",
"<englishValue>Save as ...</englishValue>",
"<frenchValue>Enregistrer sous ...</frenchValue>",
"</term>",
"<term>",
"<name>MenuFilePrint</name>",
"<englishValue>Print ...</englishValue>",
"<frenchValue>Imprimer ...</frenchValue>",
"</term>",
"<term>",
"<name>MenufilePageSetup</name>",
"<englishValue>Page setup</englishValue>",
"<frenchValue>Aperçu avant impression</frenchValue>",
"</term>",
"<term>",
"<name>MenufileQuit</name>",
"<englishValue>Quit</englishValue>",
"<frenchValue>Quitter</frenchValue>",
"</term>",
"<term>",
"<name>MenuEdit</name>",
"<englishValue>Edit</englishValue>",
"<frenchValue>Edition</frenchValue>",
"</term>",
"<term>",
"<name>MenuEditCancel</name>",
"<englishValue>Cancel</englishValue>",
"<frenchValue>Annuler</frenchValue>",
"</term>",
"<term>",
"<name>MenuEditRedo</name>",
"<englishValue>Redo</englishValue>",
"<frenchValue>Rétablir</frenchValue>",
"</term>",
"<term>",
"<name>MenuEditCut</name>",
"<englishValue>Cut</englishValue>",
"<frenchValue>Couper</frenchValue>",
"</term>",
"<term>",
"<name>MenuEditCopy</name>",
"<englishValue>Copy</englishValue>",
"<frenchValue>Copier</frenchValue>",
"</term>",
"<term>",
"<name>MenuEditPaste</name>",
"<englishValue>Paste</englishValue>",
"<frenchValue>Coller</frenchValue>",
"</term>",
"<term>",
"<name>MenuEditSelectAll</name>",
"<englishValue>Select All</englishValue>",
"<frenchValue>Sélectionner tout</frenchValue>",
"</term>",
"<term>",
"<name>MenuTools</name>",
"<englishValue>Tools</englishValue>",
"<frenchValue>Outils</frenchValue>",
"</term>",
"<term>",
"<name>MenuToolsCustomize</name>",
"<englishValue>Customize ...</englishValue>",
"<frenchValue>Personaliser ...</frenchValue>",
"</term>",
"<term>",
"<name>MenuToolsOptions</name>",
"<englishValue>Options</englishValue>",
"<frenchValue>Options</frenchValue>",
"</term>",
"<term>",
"<name>MenuLanguage</name>",
"<englishValue>Language</englishValue>",
"<frenchValue>Langage</frenchValue>",
"</term>",
"<term>",
"<name>MenuLanguageEnglish</name>",
"<englishValue>English</englishValue>",
"<frenchValue>Anglais</frenchValue>",
"</term>",
"<term>",
"<name>MenuLanguageFrench</name>",
"<englishValue>French</englishValue>",
"<frenchValue>Français</frenchValue>",
"</term>",
"<term>",
"<name>MenuHelp</name>",
"<englishValue>Help</englishValue>",
"<frenchValue>Aide</frenchValue>",
"</term>",
"<term>",
"<name>MenuHelpSummary</name>",
"<englishValue>Summary</englishValue>",
"<frenchValue>Sommaire</frenchValue>",
"</term>",
"<term>",
"<name>MenuHelpIndex</name>",
"<englishValue>Index</englishValue>",
"<frenchValue>Index</frenchValue>",
"</term>",
"<term>",
"<name>MenuHelpSearch</name>",
"<englishValue>Search</englishValue>",
"<frenchValue>Rechercher</frenchValue>",
"</term>",
"<term>",
"<name>MenuHelpAbout</name>",
"<englishValue>About</englishValue>",
"<frenchValue>A propos de ...</frenchValue>",
"</term>",
"</terms>"
};
StreamWriter sw = new StreamWriter(Settings.Default.LanguageFileName);
foreach (string item in minimumVersion)
{
sw.WriteLine(item);
}
sw.Close();
}
private void GetWindowValue()
{
Width = Settings.Default.WindowWidth;
Height = Settings.Default.WindowHeight;
Top = Settings.Default.WindowTop < 0 ? 0 : Settings.Default.WindowTop;
Left = Settings.Default.WindowLeft < 0 ? 0 : Settings.Default.WindowLeft;
comboBoxVSVersion.SelectedIndex = Settings.Default.comboBoxVSVersion;
textBoxVSProjectPath.Text = Settings.Default.textBoxVSProjectPath;
checkBoxGitBashInstalled.Checked = Settings.Default.checkBoxGitBashInstalled;
textBoxGitBashBinariesPath.Text = Settings.Default.textBoxGitBashBinariesPath;
checkBoxOnlyGenerateScriptFile.Checked = Settings.Default.checkBoxCreateUpdateFile;
checkBoxUnlistVSSolution.Checked = Settings.Default.checkBoxUnlistVSSolution;
textBoxUnlistOldSolution.Text = Settings.Default.textBoxUnlistOldSolution;
checkBoxCaseSensitive.Checked = Settings.Default.checkBoxCaseSensitive;
checkBoxGitInPath.Checked = Settings.Default.checkBoxGitInPath;
_fontSize = Settings.Default._fontSize;
for (int i = 0; i < checkedListBoxVSVersion.Items.Count; i++)
{
switch (i)
{
case 0:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2003);
break;
case 1:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2005);
break;
case 2:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2008);
break;
case 3:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2010);
break;
case 4:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2012);
break;
case 5:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2013);
break;
case 6:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2015);
break;
case 7:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2017);
break;
case 8:
checkedListBoxVSVersion.SetItemChecked(i, Settings.Default.Visual_Studio_2019);
break;
}
}
}
private void SaveWindowValue()
{
Settings.Default.WindowHeight = Height;
Settings.Default.WindowWidth = Width;
Settings.Default.WindowLeft = Left;
Settings.Default.WindowTop = Top;
Settings.Default.LastLanguageUsed = frenchToolStripMenuItem.Checked ? "French" : "English";
Settings.Default.comboBoxVSVersion = comboBoxVSVersion.SelectedIndex;
Settings.Default.textBoxVSProjectPath = textBoxVSProjectPath.Text;
Settings.Default.checkBoxGitBashInstalled = checkBoxGitBashInstalled.Checked;
Settings.Default.textBoxGitBashBinariesPath = textBoxGitBashBinariesPath.Text;
Settings.Default.checkBoxCreateUpdateFile = checkBoxOnlyGenerateScriptFile.Checked;
Settings.Default.checkBoxUnlistVSSolution = checkBoxUnlistVSSolution.Checked;
Settings.Default.textBoxUnlistOldSolution = textBoxUnlistOldSolution.Text;
Settings.Default.checkBoxCaseSensitive = checkBoxCaseSensitive.Checked;
Settings.Default.checkBoxGitInPath = checkBoxGitInPath.Checked;
Settings.Default._fontSize = _fontSize;
Settings.Default.Visual_Studio_2003 = false;
Settings.Default.Visual_Studio_2005 = false;
Settings.Default.Visual_Studio_2008 = false;
Settings.Default.Visual_Studio_2010 = false;
Settings.Default.Visual_Studio_2012 = false;
Settings.Default.Visual_Studio_2013 = false;
Settings.Default.Visual_Studio_2015 = false;
Settings.Default.Visual_Studio_2017 = false;
Settings.Default.Visual_Studio_2019 = false;
Settings.Default.Visual_Studio_2022 = false;
foreach (string vsVersion in ChangeCharacterInList(GetCheckedVsVersion(checkedListBoxVSVersion)))
{
if (vsVersion == "Visual_Studio_2003")
{
Settings.Default.Visual_Studio_2003 = true;
}
else if (vsVersion == "Visual_Studio_2005")
{
Settings.Default.Visual_Studio_2005 = true;
}
else if (vsVersion == "Visual_Studio_2008")
{
Settings.Default.Visual_Studio_2008 = true;
}
else if (vsVersion == "Visual_Studio_2010")
{
Settings.Default.Visual_Studio_2010 = true;
}
else if (vsVersion == "Visual_Studio_2012")
{
Settings.Default.Visual_Studio_2012 = true;
}
else if (vsVersion == "Visual_Studio_2013")
{
Settings.Default.Visual_Studio_2013 = true;
}
else if (vsVersion == "Visual_Studio_2015")
{
Settings.Default.Visual_Studio_2015 = true;
}
else if (vsVersion == "Visual_Studio_2017")
{
Settings.Default.Visual_Studio_2017 = true;
}
else if (vsVersion == "Visual_Studio_2019")
{
Settings.Default.Visual_Studio_2019 = true;
}
else if (vsVersion == "Visual_Studio_2022")
{
Settings.Default.Visual_Studio_2022 = true;
}
}
Settings.Default.Save();
}
/// <summary>Save all window values before exiting</summary>
/// <param name="sender">Sender is the main form</param>
/// <param name="e">Form closing event arguments</param>
private void FormMainFormClosing(object sender, FormClosingEventArgs e)
{
SaveWindowValue();
}
private void FrenchToolStripMenuItemClick(object sender, EventArgs e)
{
_currentLanguage = Language.French.ToString();
SetLanguage(Language.French.ToString());
AdjustAllControls();
}
private void EnglishToolStripMenuItemClick(object sender, EventArgs e)
{
_currentLanguage = Language.English.ToString();
SetLanguage(Language.English.ToString());
AdjustAllControls();
}
/// <summary>Adjust all controls length when translating controls label</summary>
private void AdjustAllControls()
{
AdjustControls(labelChooseVSVersion, comboBoxVSVersion, labelPickDirectory, buttonVSVersionGetPath,
textBoxVSProjectPath);
AdjustControls(checkBoxGitInPath, buttonAddGitBinaryToWinPath, buttonCreateBackupScript);
AdjustControls(checkBoxGitBashInstalled, buttonGitBashBinPath, textBoxGitBashBinariesPath);
AdjustControls(buttonClearLogTextBox, buttonScannWholePC, buttonLoadVSProjects, buttonUpdateVSProjects,
checkBoxOnlyGenerateScriptFile);
AdjustControls(checkBoxUnlistVSSolution, textBoxUnlistOldSolution, checkBoxCaseSensitive);
AdjustControls(buttonClearAll, buttonCheckAll, buttonCheckUncheckAll, labelSelectVSProjects);
}
private void AdjustControls(params Control[] listOfControls)
{
if (listOfControls.Length == 0)
{
return;
}
int position = listOfControls[0].Width + 33; // 33 is the initial padding
bool isFirstControl = true;
if (_fontSize == 0.0f)
{
_fontSize = 10.0f;
}
foreach (Control control in listOfControls)
{
if (isFirstControl)
{
control.Font = new Font(new FontFamily("Verdana"), _fontSize);
isFirstControl = false;
}
else
{
control.Left = position + 25;
position += control.Width + 10;
control.Font = new Font(new FontFamily("Verdana"), _fontSize);
}
}
}
private void SetLanguage(string myLanguage)
{
switch (myLanguage)
{
case "English":
frenchToolStripMenuItem.Checked = false;
englishToolStripMenuItem.Checked = true;
fileToolStripMenuItem.Text = _languageDicoEn["MenuFile"];
newToolStripMenuItem.Text = _languageDicoEn["MenuFileNew"];
openToolStripMenuItem.Text = _languageDicoEn["MenuFileOpen"];
saveToolStripMenuItem.Text = _languageDicoEn["MenuFileSave"];
saveasToolStripMenuItem.Text = _languageDicoEn["MenuFileSaveAs"];
printPreviewToolStripMenuItem.Text = _languageDicoEn["MenuFilePrint"];
printPreviewToolStripMenuItem.Text = _languageDicoEn["MenufilePageSetup"];
quitToolStripMenuItem.Text = _languageDicoEn["MenufileQuit"];
editToolStripMenuItem.Text = _languageDicoEn["MenuEdit"];
cancelToolStripMenuItem.Text = _languageDicoEn["MenuEditCancel"];
redoToolStripMenuItem.Text = _languageDicoEn["MenuEditRedo"];
cutToolStripMenuItem.Text = _languageDicoEn["MenuEditCut"];
copyToolStripMenuItem.Text = _languageDicoEn["MenuEditCopy"];
pasteToolStripMenuItem.Text = _languageDicoEn["MenuEditPaste"];
selectAllToolStripMenuItem.Text = _languageDicoEn["MenuEditSelectAll"];
toolsToolStripMenuItem.Text = _languageDicoEn["MenuTools"];
personalizeToolStripMenuItem.Text = _languageDicoEn["MenuToolsCustomize"];
optionsToolStripMenuItem.Text = _languageDicoEn["MenuToolsOptions"];
languagetoolStripMenuItem.Text = _languageDicoEn["MenuLanguage"];
englishToolStripMenuItem.Text = _languageDicoEn["MenuLanguageEnglish"];
frenchToolStripMenuItem.Text = _languageDicoEn["MenuLanguageFrench"];
helpToolStripMenuItem.Text = _languageDicoEn["MenuHelp"];
summaryToolStripMenuItem.Text = _languageDicoEn["MenuHelpSummary"];
indexToolStripMenuItem.Text = _languageDicoEn["MenuHelpIndex"];
searchToolStripMenuItem.Text = _languageDicoEn["MenuHelpSearch"];
aboutToolStripMenuItem.Text = _languageDicoEn["MenuHelpAbout"];
labelSelectVSProjects.Text = _languageDicoEn["Select the Visual Studio projects you want to update"];
labelChooseVSVersion.Text = _languageDicoEn["Choose the Visual Studio version:"];
labelPickDirectory.Text = _languageDicoEn["or pick directory:"];
buttonUpdateVSProjects.Text = _languageDicoEn["Update selected Visual Studio Projects"];
buttonScannWholePC.Text = _languageDicoEn["Scan whole Pc"];
buttonLoadVSProjects.Text = _languageDicoEn["Search for Visual Studio Projects"];
checkBoxOnlyGenerateScriptFile.Text = _languageDicoEn["Generate only the script file"];
buttonClearLogTextBox.Text = _languageDicoEn["Clear log"];
checkBoxUnlistVSSolution.Text =
_languageDicoEn["Unlist Visual Studio Solution having the following terms separated with a comma"];
checkBoxCaseSensitive.Text = _languageDicoEn["Case sensitive"];
buttonClearAll.Text = _languageDicoEn["Uncheck all"];
buttonCheckAll.Text = _languageDicoEn["Check all"];
buttonCheckUncheckAll.Text = _languageDicoEn["Toggle items"];
buttonListBoxVSVersionUncheck.Text = _languageDicoEn["Uncheck all"];
buttonListBoxVSVersionCheck.Text = _languageDicoEn["Check all"];
buttonListBoxVSVersionToggle.Text = _languageDicoEn["Toggle items"];
buttonUpdateCheckedVersion.Text = _languageDicoEn["Update"];
checkBoxGitBashInstalled.Text = _languageDicoEn[CheckOrUncheck(checkBoxGitBashInstalled, "GitBash installed")];
checkBoxGitInPath.Text =
_languageDicoEn[CheckOrUncheck(checkBoxGitInPath, "GitBash binary path in Windows Path variable")];
buttonCreateBackupScript.Text =
_languageDicoEn["Create git clone backup script for gitted Visual Studio Solutions"];
_currentLanguage = "English";
break;
case "French":
frenchToolStripMenuItem.Checked = true;
englishToolStripMenuItem.Checked = false;
fileToolStripMenuItem.Text = _languageDicoFr["MenuFile"];
newToolStripMenuItem.Text = _languageDicoFr["MenuFileNew"];
openToolStripMenuItem.Text = _languageDicoFr["MenuFileOpen"];
saveToolStripMenuItem.Text = _languageDicoFr["MenuFileSave"];
saveasToolStripMenuItem.Text = _languageDicoFr["MenuFileSaveAs"];
printPreviewToolStripMenuItem.Text = _languageDicoFr["MenuFilePrint"];
printPreviewToolStripMenuItem.Text = _languageDicoFr["MenufilePageSetup"];
quitToolStripMenuItem.Text = _languageDicoFr["MenufileQuit"];
editToolStripMenuItem.Text = _languageDicoFr["MenuEdit"];
cancelToolStripMenuItem.Text = _languageDicoFr["MenuEditCancel"];
redoToolStripMenuItem.Text = _languageDicoFr["MenuEditRedo"];
cutToolStripMenuItem.Text = _languageDicoFr["MenuEditCut"];
copyToolStripMenuItem.Text = _languageDicoFr["MenuEditCopy"];
pasteToolStripMenuItem.Text = _languageDicoFr["MenuEditPaste"];
selectAllToolStripMenuItem.Text = _languageDicoFr["MenuEditSelectAll"];
toolsToolStripMenuItem.Text = _languageDicoFr["MenuTools"];
personalizeToolStripMenuItem.Text = _languageDicoFr["MenuToolsCustomize"];
optionsToolStripMenuItem.Text = _languageDicoFr["MenuToolsOptions"];
languagetoolStripMenuItem.Text = _languageDicoFr["MenuLanguage"];
englishToolStripMenuItem.Text = _languageDicoFr["MenuLanguageEnglish"];
frenchToolStripMenuItem.Text = _languageDicoFr["MenuLanguageFrench"];
helpToolStripMenuItem.Text = _languageDicoFr["MenuHelp"];
summaryToolStripMenuItem.Text = _languageDicoFr["MenuHelpSummary"];
indexToolStripMenuItem.Text = _languageDicoFr["MenuHelpIndex"];
searchToolStripMenuItem.Text = _languageDicoFr["MenuHelpSearch"];
aboutToolStripMenuItem.Text = _languageDicoFr["MenuHelpAbout"];
labelChooseVSVersion.Text = _languageDicoFr["Choose the Visual Studio version:"];
labelPickDirectory.Text = _languageDicoFr["or pick directory:"];
buttonUpdateVSProjects.Text = _languageDicoFr["Update selected Visual Studio Projects"];
labelSelectVSProjects.Text = _languageDicoFr["Select the Visual Studio projects you want to update"];
buttonScannWholePC.Text = _languageDicoFr["Scan whole Pc"];
buttonLoadVSProjects.Text = _languageDicoFr["Search for Visual Studio Projects"];
checkBoxOnlyGenerateScriptFile.Text = _languageDicoFr["Generate only the script file"];
buttonCheckUncheckAll.Text = _languageDicoFr["Toggle items"];
buttonClearLogTextBox.Text = _languageDicoFr["Clear log"];
buttonListBoxVSVersionUncheck.Text = _languageDicoFr["Uncheck all"];
buttonListBoxVSVersionCheck.Text = _languageDicoFr["Check all"];
buttonListBoxVSVersionToggle.Text = _languageDicoFr["Toggle items"];
checkBoxUnlistVSSolution.Text =
_languageDicoFr["Unlist Visual Studio Solution having the following terms separated with a comma"];
checkBoxCaseSensitive.Text = _languageDicoFr["Case sensitive"];
buttonClearAll.Text = _languageDicoFr["Uncheck all"];
buttonCheckAll.Text = _languageDicoFr["Check all"];
buttonUpdateCheckedVersion.Text = _languageDicoFr["Update"];
checkBoxGitBashInstalled.Text = _languageDicoFr[CheckOrUncheck(checkBoxGitBashInstalled, "GitBash installed")];
checkBoxGitInPath.Text =
_languageDicoFr[CheckOrUncheck(checkBoxGitInPath, "GitBash binary path in Windows Path variable")];
buttonCreateBackupScript.Text =
_languageDicoFr["Create git clone backup script for gitted Visual Studio Solutions"];
_currentLanguage = "French";
break;
}
}
private static string CheckOrUncheck(CheckBox checkbox, string positiveString)
{
switch (positiveString)
{
case "GitBash installed":
return checkbox.Checked ? "GitBash installed" : "GitBash not installed";
case "GitBash binary path in Windows Path variable":
return checkbox.Checked
? "GitBash binary path in Windows Path variable"
: "GitBash binary path not in Windows Path variable";
default:
return "error";
}
}
private void CutToolStripMenuItemClick(object sender, EventArgs e)
{
var listOfCtrl = new List<Control> { textBoxVSProjectPath, textBoxGitBashBinariesPath };
Control focusedControl = FindFocusedControl(listOfCtrl);
var tb = focusedControl as TextBox;
if (tb != null)
{
CutToClipboard(tb);
}
}
private void CopyToolStripMenuItemClick(object sender, EventArgs e)
{
Control focusedControl = FindFocusedControl(new List<Control> { textBoxVSProjectPath, textBoxGitBashBinariesPath });
var tb = focusedControl as TextBox;
if (tb != null)
{
CopyToClipboard(tb);
}
}
private void PasteToolStripMenuItemClick(object sender, EventArgs e)
{
Control focusedControl = FindFocusedControl(new List<Control> { textBoxVSProjectPath, textBoxGitBashBinariesPath });
var tb = focusedControl as TextBox;
if (tb != null)
{
PasteFromClipboard(tb);
}
}
private void SelectAllToolStripMenuItemClick(object sender, EventArgs e)
{
Control focusedControl = FindFocusedControl(new List<Control> { textBoxVSProjectPath, textBoxGitBashBinariesPath });
TextBox control = focusedControl as TextBox;
control?.SelectAll();
}
private void CutToClipboard(TextBoxBase textBox, string errorMessage = "nothing")
{
if (textBox != ActiveControl) return;
if (textBox.Text == string.Empty)
{
DisplayMessageOk(Translate("ThereIs") + Punctuation.OneSpace +
Translate(errorMessage) + Punctuation.OneSpace +
Translate("ToCut") + Punctuation.OneSpace, Translate(errorMessage),
MessageBoxButtons.OK);
return;
}
if (textBox.SelectedText == string.Empty)
{
DisplayMessageOk(Translate("NoTextHasBeenSelected"),
Translate(errorMessage), MessageBoxButtons.OK);
return;
}
Clipboard.SetText(textBox.SelectedText);
textBox.SelectedText = string.Empty;
}
private void CopyToClipboard(TextBoxBase textBox, string message = "nothing")
{
if (textBox != ActiveControl) return;
if (textBox.Text == string.Empty)
{
DisplayMessageOk(Translate("ThereIsNothingToCopy") + Punctuation.OneSpace,
Translate(message), MessageBoxButtons.OK);
return;
}
if (textBox.SelectedText == string.Empty)
{
DisplayMessageOk(Translate("NoTextHasBeenSelected"),
Translate(message), MessageBoxButtons.OK);
return;
}
Clipboard.SetText(textBox.SelectedText);
}
private void PasteFromClipboard(TextBoxBase tb)
{
if (tb != ActiveControl) return;
var selectionIndex = tb.SelectionStart;
tb.SelectedText = Clipboard.GetText();
tb.SelectionStart = selectionIndex + Clipboard.GetText().Length;