/
MainWindow.xaml.cs
3644 lines (3130 loc) · 150 KB
/
MainWindow.xaml.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
// Unity Project Launcher by https://unitycoder.com
// https://github.com/unitycoder/UnityLauncherPro
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Drawing; // for notifyicon
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shell;
using UnityLauncherPro.Helpers;
using UnityLauncherPro.Properties;
namespace UnityLauncherPro
{
public partial class MainWindow : Window
{
public const string appName = "UnityLauncherPro";
public static string currentDateFormat = null;
public static bool useHumanFriendlyDateFormat = false;
public static bool searchProjectPathAlso = false;
public static List<Project> projectsSource;
public static List<UnityInstallation> unityInstallationsSource;
public static ObservableDictionary<string, string> unityInstalledVersions = new ObservableDictionary<string, string>(); // versionID and installation folder
public static readonly string launcherArgumentsFile = "LauncherArguments.txt";
public static readonly string projectNameFile = "ProjectName.txt";
public static string preferredVersion = null;
public static int projectNameSetting = 0; // 0 = folder or ProjectName.txt if exists, 1=ProductName
public static readonly string initScriptFileFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts", "InitializeProject.cs");
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
const string resourcesURL = "https://github.com/unitycoder/UnityResources";
const string defaultAdbLogCatArgs = "-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color";
System.Windows.Forms.NotifyIcon notifyIcon;
Updates[] updatesSource;
string _filterString = null;
bool multiWordSearch = false;
string[] searchWords;
int lastSelectedProjectIndex = 0;
Mutex myMutex;
ThemeEditor themeEditorWindow;
internal static int webglPort = 50000;
internal static int maxProjectCount = 40;
string defaultDateFormat = "dd/MM/yyyy HH:mm:ss";
string adbLogCatArgs = defaultAdbLogCatArgs;
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
string currentBuildReportProjectPath = null;
string currentBuildPluginsRelativePath = null;
//List<List<string>> buildReports = new List<List<string>>();
List<BuildReport> buildReports = new List<BuildReport>(); // multiple reports, each contains their own stats and items
int currentBuildReport = 0;
[DllImport("user32", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindow(string cls, string win);
[DllImport("user32")]
static extern IntPtr SetForegroundWindow(IntPtr hWnd);
[DllImport("user32")]
static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32")]
static extern bool OpenIcon(IntPtr hWnd);
public MainWindow()
{
InitializeComponent();
Init();
}
void Init()
{
// disable accesskeys without alt
CoreCompatibilityPreferences.IsAltKeyRequiredInAccessKeyDefaultScope = true;
// make window resizable (this didnt work when used pure xaml to do this)
WindowChrome Resizable_BorderLess_Chrome = new WindowChrome();
Resizable_BorderLess_Chrome.CornerRadius = new CornerRadius(0);
Resizable_BorderLess_Chrome.CaptionHeight = 1.0;
WindowChrome.SetWindowChrome(this, Resizable_BorderLess_Chrome);
Tools.mainWindow = this;
// need to load here to get correct window size early
LoadSettings();
// set version number
if (string.IsNullOrEmpty(Version.Stamp) == false)
{
lblVersion.Content = "Build: " + Version.Stamp;
}
}
void Start()
{
// get unity installations
dataGridUnitys.Items.Clear();
UpdateUnityInstallationsList();
HandleCommandLineLaunch();
// check for duplicate instance, and activate that instead
if (chkAllowSingleInstanceOnly.IsChecked == true)
{
bool aIsNewInstance = false;
myMutex = new Mutex(true, appName, out aIsNewInstance);
if (!aIsNewInstance)
{
// NOTE doesnt work if its minized to tray
ActivateOtherWindow();
App.Current.Shutdown();
}
}
// TEST erase custom history data
//Properties.Settings.Default.projectPaths = null;
//Properties.Settings.Default.Save();
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked, AllProjectPaths: Properties.Settings.Default.projectPaths);
Console.WriteLine("projectsSource.Count: " + projectsSource.Count);
gridRecent.Items.Clear();
gridRecent.ItemsSource = projectsSource;
// clear updates grid
dataGridUpdates.Items.Clear();
// clear buildreport grids
gridBuildReport.Items.Clear();
gridBuildReportData.Items.Clear();
// build notifyicon (using windows.forms)
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Images/icon.ico")).Stream);
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);
// get original colors
foreach (DictionaryEntry item in Application.Current.Resources.MergedDictionaries[0])
{
origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
}
ApplyTheme(txtCustomThemeFile.Text);
// for autostart with minimized
if (Settings.Default.runAutomatically == true && Settings.Default.runAutomaticallyMinimized == true)
{
// if application was system started, then hide, otherwise dont hide (when user started it)
if (Directory.GetCurrentDirectory().ToLower() == @"c:\windows\system32")
{
this.ShowInTaskbar = false; // for some reason, otherwise it will show in taskbar only at start
notifyIcon.Visible = true;
this.Hide();
}
}
// TEST
//themeEditorWindow = new ThemeEditor();
//themeEditorWindow.Show();
isInitializing = false;
}
// bring old window to front, but needs matching appname.. https://stackoverflow.com/a/36804161/5452781
private static void ActivateOtherWindow()
{
var other = FindWindow(null, appName);
if (other != IntPtr.Zero)
{
SetForegroundWindow(other);
if (IsIconic(other)) OpenIcon(other);
}
}
void HandleCommandLineLaunch()
{
// check if received -projectPath argument (that means opening from explorer / cmdline)
string[] args = Environment.GetCommandLineArgs();
if (args != null && args.Length > 2)
{
// first argument needs to be -projectPath
var commandLineArgs = args[1];
if (commandLineArgs == "-projectPath")
{
Console.WriteLine("Launching from commandline...");
// path
var projectPathArgument = args[2];
// resolve full path if path parameter isn't a rooted path
if (!Path.IsPathRooted(projectPathArgument))
{
projectPathArgument = Directory.GetCurrentDirectory() + projectPathArgument;
}
var version = Tools.GetProjectVersion(projectPathArgument);
// take extra arguments also
var commandLineArguments = "";
for (int i = 3, len = args.Length; i < len; i++)
{
commandLineArguments += " " + args[i];
}
var proj = new Project();
proj.Version = version;
proj.Path = projectPathArgument;
proj.Arguments = commandLineArguments;
// no version info or check if force-update button is down
// NOTE if keydown, window doesnt become active and focused
if (string.IsNullOrEmpty(version) || (Keyboard.Modifiers & ModifierKeys.Shift) != 0)
{
if (Directory.Exists(Path.Combine(proj.Path, "Assets")) == true)
{
Tools.DisplayUpgradeDialog(proj, null, false);
}
else // no assets folder here, then its new project
{
//Tools.DisplayUpgradeDialog(proj, null);
CreateNewEmptyProject(proj.Path);
}
}
else
{
// try launching it
var proc = Tools.LaunchProject(proj);
//proj.Process = proc;
//ProcessHandler.Add(proj, proc);
}
// quit after launch if enabled in settings
if (Properties.Settings.Default.closeAfterExplorer == true)
{
Environment.Exit(0);
}
//SetStatus("Ready");
}
else
{
Console.WriteLine("Error> Invalid arguments:" + args[1]);
}
}
}
// main search
void FilterRecentProjects()
{
// https://www.wpftutorial.net/DataViews.html
_filterString = txtSearchBox.Text;
if (_filterString.IndexOf(' ') > -1)
{
multiWordSearch = true;
searchWords = _filterString.Split(' ');
}
else
{
multiWordSearch = false;
}
ICollectionView collection = CollectionViewSource.GetDefaultView(projectsSource);
collection.Filter = ProjectFilter;
// set first row selected, if only 1 row
if (gridRecent.Items.Count == 1)
{
gridRecent.SelectedIndex = 0;
}
}
void FilterUpdates()
{
_filterString = txtSearchBoxUpdates.Text;
ICollectionView collection = CollectionViewSource.GetDefaultView(dataGridUpdates.ItemsSource);
collection.Filter = UpdatesFilter;
if (dataGridUpdates.Items.Count > 0)
{
dataGridUpdates.SelectedIndex = 0;
}
}
void FilterUnitys()
{
_filterString = txtSearchBoxUnity.Text.Trim();
ICollectionView collection = CollectionViewSource.GetDefaultView(dataGridUnitys.ItemsSource);
collection.Filter = UnitysFilter;
if (dataGridUnitys.Items.Count > 0)
{
dataGridUnitys.SelectedIndex = 0;
}
}
void FilterBuildReport()
{
_filterString = txtSearchBoxBuildReport.Text;
ICollectionView collection = CollectionViewSource.GetDefaultView(gridBuildReport.ItemsSource);
collection.Filter = BuildReportFilter;
//if (gridBuildReport.Items.Count > 0)
//{
// gridBuildReport.SelectedIndex = 0;
//}
}
private bool ProjectFilter(object item)
{
Project proj = item as Project;
// split search string by space, if it contains space
if (multiWordSearch == true)
{
bool found = true;
foreach (var word in searchWords)
{
bool titleMatched = proj.Title.IndexOf(word, 0, StringComparison.CurrentCultureIgnoreCase) != -1;
bool pathMatched = searchProjectPathAlso && proj.Path.IndexOf(word, 0, StringComparison.CurrentCultureIgnoreCase) != -1;
found = found && (titleMatched || pathMatched);
}
return found;
}
else // single word search
{
bool titleMatched = proj.Title.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1;
bool pathMatched = searchProjectPathAlso && proj.Path.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1;
return titleMatched || pathMatched;
}
}
private bool UpdatesFilter(object item)
{
Updates unity = item as Updates;
bool haveSearchString = string.IsNullOrEmpty(_filterString) == false;
bool matchString = haveSearchString && unity.Version.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) > -1;
bool checkedAlls = (bool)rdoAll.IsChecked;
bool checkedLTSs = (bool)rdoLTS.IsChecked;
bool checkedAlphas = (bool)rdoAlphas.IsChecked;
bool checkedBetas = (bool)rdoBetas.IsChecked;
bool matchLTS = checkedLTSs && Tools.IsLTS(unity.Version);
bool matchAlphas = checkedAlphas && Tools.IsAlpha(unity.Version);
bool matchBetas = checkedBetas && Tools.IsBeta(unity.Version);
// match search string and some radiobutton
if (haveSearchString)
{
if (checkedAlls) return matchString;
if (checkedLTSs) return matchString && matchLTS;
if (checkedAlphas) return matchString && matchAlphas;
if (checkedBetas) return matchString && matchBetas;
}
else // no search text, filter by radiobuttons
{
if (checkedAlls || matchLTS || matchAlphas || matchBetas) return true;
}
// fallback
return matchString;
}
private bool UnitysFilter(object item)
{
UnityInstallation unity = item as UnityInstallation;
return (unity.Version?.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1) || (unity.ReleaseType?.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1) || (unity.PlatformsCombined?.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1);
}
private bool BuildReportFilter(object item)
{
BuildReportItem reportItem = item as BuildReportItem;
return (reportItem.Path.IndexOf(_filterString, 0, StringComparison.CurrentCultureIgnoreCase) != -1);
}
void LoadSettings()
{
// catch corrupted config file
try
{
Settings.Default.Reload();
// form size
this.Width = Properties.Settings.Default.windowWidth;
this.Height = Properties.Settings.Default.windowHeight;
chkMinimizeToTaskbar.IsChecked = Properties.Settings.Default.minimizeToTaskbar;
chkRegisterExplorerMenu.IsChecked = Properties.Settings.Default.registerExplorerMenu;
// update settings window
chkQuitAfterCommandline.IsChecked = Properties.Settings.Default.closeAfterExplorer;
chkQuitAfterOpen.IsChecked = Properties.Settings.Default.closeAfterProject;
chkShowLauncherArgumentsColumn.IsChecked = Properties.Settings.Default.showArgumentsColumn;
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
chkCheckPlasticBranch.IsChecked = Properties.Settings.Default.checkPlasticBranch;
chkShowMissingFolderProjects.IsChecked = Properties.Settings.Default.showProjectsMissingFolder;
chkAllowSingleInstanceOnly.IsChecked = Properties.Settings.Default.AllowSingleInstanceOnly;
chkAskNameForQuickProject.IsChecked = Properties.Settings.Default.askNameForQuickProject;
chkEnableProjectRename.IsChecked = Properties.Settings.Default.enableProjectRename;
chkStreamerMode.IsChecked = Properties.Settings.Default.streamerMode;
chkShowPlatform.IsChecked = Properties.Settings.Default.showTargetPlatform;
chkUseCustomTheme.IsChecked = Properties.Settings.Default.useCustomTheme;
txtRootFolderForNewProjects.Text = Properties.Settings.Default.newProjectsRoot;
txtWebglRelativePath.Text = Properties.Settings.Default.webglBuildPath;
txtCustomThemeFile.Text = Properties.Settings.Default.themeFile;
useAlphaReleaseNotesSite.IsChecked = Properties.Settings.Default.useAlphaReleaseNotes;
chkEnablePlatformSelection.IsChecked = Properties.Settings.Default.enablePlatformSelection;
chkRunAutomatically.IsChecked = Properties.Settings.Default.runAutomatically;
chkRunAutomaticallyMinimized.IsChecked = Properties.Settings.Default.runAutomaticallyMinimized;
// update optional grid columns, hidden or visible
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
gridRecent.Columns[5].Visibility = (bool)chkShowGitBranchColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
gridRecent.Columns[6].Visibility = (bool)chkShowPlatform.IsChecked ? Visibility.Visible : Visibility.Collapsed;
// update installations folder listbox
lstRootFolders.Items.Clear();
// check if no installation root folders are added, then add default folder(s), this usually happens only on first run (or if user has not added any folders)
if (Properties.Settings.Default.rootFolders.Count == 0)
{
// default hub installation folder
string baseFolder = "\\Program Files\\Unity\\Hub\\Editor";
string baseFolder2 = "\\Program Files\\";
string defaultFolder1 = "C:" + baseFolder;
string defaultFolder2 = "D:" + baseFolder;
string defaultFolder3 = "C:" + baseFolder2;
string defaultFolder4 = "D:" + baseFolder2;
if (Directory.Exists(defaultFolder1))
{
Properties.Settings.Default.rootFolders.Add(defaultFolder1);
}
else if (Directory.Exists(defaultFolder2))
{
Properties.Settings.Default.rootFolders.Add(defaultFolder2);
}
else if (Directory.Exists(defaultFolder3))
{
if (GetUnityInstallations.HasUnityInstallations(defaultFolder3))
{
Properties.Settings.Default.rootFolders.Add(defaultFolder3);
}
else if (GetUnityInstallations.HasUnityInstallations(defaultFolder4))
{
Properties.Settings.Default.rootFolders.Add(defaultFolder4);
}
}
}
lstRootFolders.ItemsSource = Properties.Settings.Default.rootFolders;
// restore recent project datagrid column widths
int[] gridColumnWidths = Properties.Settings.Default.gridColumnWidths;
if (gridColumnWidths != null)
{
for (int i = 0; i < gridColumnWidths.Length; ++i)
{
if (i >= gridRecent.Columns.Count) break; // too many columns were saved, probably some test columns
gridRecent.Columns[i].Width = gridColumnWidths[i];
}
}
// restore buildreport datagrid column widths
gridColumnWidths = Properties.Settings.Default.gridColumnWidthsBuildReport;
if (gridColumnWidths != null)
{
for (int i = 0; i < gridColumnWidths.Length; ++i)
{
if (i >= gridBuildReport.Columns.Count) break; // too many columns were saved, probably some test columns
gridBuildReport.Columns[i].Width = gridColumnWidths[i];
}
}
// other setting vars
preferredVersion = Settings.Default.preferredVersion;
// get last modified date format
chkUseCustomLastModified.IsChecked = Settings.Default.useCustomLastModified;
txtCustomDateTimeFormat.Text = Settings.Default.customDateFormat;
if (Settings.Default.useCustomLastModified)
{
currentDateFormat = Settings.Default.customDateFormat;
}
else // use default
{
currentDateFormat = defaultDateFormat;
}
chkHumanFriendlyDateTime.IsChecked = Settings.Default.useHumandFriendlyLastModified;
// if both enabled, then disable custom
if (chkHumanFriendlyDateTime.IsChecked == true && chkUseCustomLastModified.IsChecked == true)
{
chkUseCustomLastModified.IsChecked = false;
}
useHumanFriendlyDateFormat = Settings.Default.useHumandFriendlyLastModified;
searchProjectPathAlso = Settings.Default.searchProjectPathAlso;
chkSearchProjectPath.IsChecked = searchProjectPathAlso;
// recent grid column display index order
var order = Settings.Default.recentColumnsOrder;
// if we dont have any values, get & set them now
// also, if user has disabled optional columns, saved order must be reset to default
if (order == null || gridRecent.Columns.Count != Settings.Default.recentColumnsOrder.Length)
{
Settings.Default.recentColumnsOrder = new Int32[gridRecent.Columns.Count];
for (int i = 0; i < gridRecent.Columns.Count; i++)
{
Settings.Default.recentColumnsOrder[i] = gridRecent.Columns[i].DisplayIndex;
}
Settings.Default.Save();
}
else // load existing order
{
for (int i = 0; i < gridRecent.Columns.Count; i++)
{
if (Settings.Default.recentColumnsOrder[i] > -1)
{
gridRecent.Columns[i].DisplayIndex = Settings.Default.recentColumnsOrder[i];
}
}
}
adbLogCatArgs = Settings.Default.adbLogCatArgs;
txtLogCatArgs.Text = adbLogCatArgs;
projectNameSetting = Settings.Default.projectName;
switch (projectNameSetting)
{
case 0:
radioProjNameFolder.IsChecked = true;
break;
case 1:
radioProjNameProductName.IsChecked = true;
break;
default:
radioProjNameFolder.IsChecked = true;
break;
}
// set default .bat folder location to appdata/.., if nothing is set, or current one is invalid
if (string.IsNullOrEmpty(txtShortcutBatchFileFolder.Text) || Directory.Exists(txtShortcutBatchFileFolder.Text) == false)
{
Settings.Default.shortcutBatchFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName);
txtShortcutBatchFileFolder.Text = Settings.Default.shortcutBatchFileFolder;
}
chkUseInitScript.IsChecked = Settings.Default.useInitScript;
txtCustomInitFileURL.Text = Settings.Default.customInitFileURL;
// load webgl port
txtWebglPort.Text = "" + Settings.Default.webglPort;
webglPort = Settings.Default.webglPort;
txtMaxProjectCount.Text = Settings.Default.maxProjectCount.ToString();
chkOverride40ProjectCount.IsChecked = Settings.Default.override40ProjectCount;
if ((bool)chkOverride40ProjectCount.IsChecked)
{
maxProjectCount = Settings.Default.maxProjectCount;
}
else
{
maxProjectCount = 40;
}
}
catch (ConfigurationErrorsException ex)
{
string filename = ((ConfigurationErrorsException)ex.InnerException).Filename;
if (MessageBox.Show("This may be due to a Windows crash/BSOD.\n" +
"Click 'Yes' to use automatic backup (if exists, otherwise settings are reset), then start application again.\n\n" +
"Click 'No' to exit now (and delete user.config manually)\n\nCorrupted file: " + filename,
appName + " - Corrupt user settings",
MessageBoxButton.YesNo,
MessageBoxImage.Error) == MessageBoxResult.Yes)
{
// try to use backup
string backupFilename = filename + ".bak";
if (File.Exists(backupFilename))
{
File.Copy(backupFilename, filename, true);
}
else
{
File.Delete(filename);
}
}
// need to restart, otherwise settings not loaded
Process.GetCurrentProcess().Kill();
}
} // LoadSettings()
private void SaveSettingsOnExit()
{
// save recent project column widths
List<int> gridWidths;
// if we dont have any settings yet
if (Properties.Settings.Default.gridColumnWidths != null)
{
gridWidths = new List<int>(Properties.Settings.Default.gridColumnWidths);
}
else
{
gridWidths = new List<int>();
}
// get data grid view widths
var column = gridRecent.Columns[0];
for (int i = 0; i < gridRecent.Columns.Count; ++i)
{
if (Properties.Settings.Default.gridColumnWidths != null && Properties.Settings.Default.gridColumnWidths.Length > i)
{
gridWidths[i] = (int)gridRecent.Columns[i].Width.Value;
}
else
{
gridWidths.Add((int)gridRecent.Columns[i].Width.Value);
}
}
Properties.Settings.Default.gridColumnWidths = gridWidths.ToArray();
Properties.Settings.Default.Save();
// save buildrepot column widths
gridWidths.Clear();
// if we dont have any settings yet
if (Properties.Settings.Default.gridColumnWidthsBuildReport != null)
{
gridWidths = new List<int>(Properties.Settings.Default.gridColumnWidthsBuildReport);
}
else
{
gridWidths = new List<int>();
}
// get data grid view widths
column = gridBuildReport.Columns[0];
for (int i = 0; i < gridBuildReport.Columns.Count; ++i)
{
if (Properties.Settings.Default.gridColumnWidthsBuildReport != null && Properties.Settings.Default.gridColumnWidthsBuildReport.Length > i)
{
gridWidths[i] = (int)gridBuildReport.Columns[i].Width.Value;
}
else
{
gridWidths.Add((int)gridBuildReport.Columns[i].Width.Value);
}
}
Properties.Settings.Default.gridColumnWidthsBuildReport = gridWidths.ToArray();
Properties.Settings.Default.projectName = projectNameSetting;
Properties.Settings.Default.Save();
// make backup
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
var FullFileName = config.FilePath;
File.Copy(FullFileName, FullFileName + ".bak", true);
}
void UpdateUnityInstallationsList()
{
// Reset preferred string, if user changed it
//preferredVersion = "none";
unityInstallationsSource = GetUnityInstallations.Scan();
dataGridUnitys.ItemsSource = unityInstallationsSource;
// Also make dictionary of installed unitys, to search faster
unityInstalledVersions.Clear();
for (int i = 0, len = unityInstallationsSource.Count; i < len; i++)
{
var version = unityInstallationsSource[i].Version;
// NOTE cannot have same version id in 2 places with this
if (string.IsNullOrEmpty(version) == false && unityInstalledVersions.ContainsKey(version) == false)
{
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
}
}
lblFoundXInstallations.Content = "Found " + unityInstallationsSource.Count + " installations";
}
Project GetSelectedProject()
{
return (Project)gridRecent.SelectedItem;
}
UnityInstallation GetSelectedUnity()
{
return (UnityInstallation)dataGridUnitys.SelectedItem;
}
Updates GetSelectedUpdate()
{
return (Updates)dataGridUpdates.SelectedItem;
}
BuildReportItem GetSelectedBuildItem()
{
return (BuildReportItem)gridBuildReport.SelectedItem;
}
void AddUnityInstallationRootFolder()
{
var dialog = new System.Windows.Forms.FolderBrowserDialog();
dialog.Description = "Select Unity installations root folder";
var result = dialog.ShowDialog();
var newRoot = dialog.SelectedPath;
if (String.IsNullOrWhiteSpace(newRoot) == false && Directory.Exists(newRoot) == true)
{
Properties.Settings.Default.rootFolders.Add(newRoot);
lstRootFolders.Items.Refresh();
Properties.Settings.Default.Save();
UpdateUnityInstallationsList();
RefreshRecentProjects();
}
}
// waits for unity update results and assigns to datagrid
async Task CallGetUnityUpdates()
{
dataGridUpdates.ItemsSource = null;
var task = GetUnityUpdates.Scan();
var items = await task;
//Console.WriteLine("CallGetUnityUpdates=" + items == null);
if (items == null) return;
updatesSource = GetUnityUpdates.Parse(items);
if (updatesSource == null) return;
dataGridUpdates.ItemsSource = updatesSource;
}
async void GoLookForUpdatesForThisUnity()
{
// call for updates list fetch
await CallGetUnityUpdates();
var unity = GetSelectedUnity();
if (unity == null) return;
if (dataGridUpdates.ItemsSource != null)
{
tabControl.SelectedIndex = 2;
txtSearchBoxUpdates.Text = ""; // need to clear old results first
// NOTE for now, just set filter to current version, minus patch version "2021.1.7f1" > "2021.1"
txtSearchBoxUpdates.Text = unity.Version.Substring(0, unity.Version.LastIndexOf('.'));
}
}
public void RefreshRecentProjects()
{
// clear search
txtSearchBox.Text = "";
// take currently selected project row
lastSelectedProjectIndex = gridRecent.SelectedIndex;
// rescan recent projects
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked, AllProjectPaths: Settings.Default.projectPaths);
gridRecent.ItemsSource = projectsSource;
// fix sorting on refresh
foreach (DataGridColumn column in gridRecent.Columns)
{
if (column.Header.ToString() == Settings.Default.currentSortColumn)
{
// TODO FIXME, hack for correct direction on refresh only
Settings.Default.currentSortDirectionAscending = !Settings.Default.currentSortDirectionAscending;
var g = new DataGridSortingEventArgs(column);
SortHandlerRecentProjects(gridRecent, g);
break;
}
}
// focus back
Tools.SetFocusToGrid(gridRecent, lastSelectedProjectIndex);
SetStatus("Ready (" + projectsSource.Count + " projects)");
}
//
//
// EVENTS
//
//
// maximize window
void NotifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Show();
this.WindowState = WindowState.Normal;
this.ShowInTaskbar = true;
notifyIcon.Visible = false;
// NOTE workaround for grid not focused when coming back from minimized window
Tools.SetFocusToGrid(gridRecent, gridRecent.SelectedIndex);
}
private void OnRectangleMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) this.DragMove();
}
private void OnSearchTextChanged(object sender, TextChangedEventArgs e)
{
FilterRecentProjects();
// if nothing selected, select first item
if (gridRecent.SelectedIndex < 0) gridRecent.SelectedIndex = 0;
}
private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
{
var folder = Tools.BrowseForOutputFolder("Select Project Folder to Add it Into Projects List");
if (string.IsNullOrEmpty(folder) == false)
{
var proj = GetNewProjectData(folder);
//AddNewProjectToList(proj);
Tools.AddProjectToHistory(proj.Path);
// clear search, so can see added project
txtSearchBox.Text = "";
RefreshRecentProjects();
// NOTE 0 works for sort-by-date only
Tools.SetFocusToGrid(gridRecent, 0);
}
}
Project GetNewProjectData(string folder)
{
var p = new Project();
p.Path = folder;
p.Title = Path.GetFileName(folder);
p.Version = Tools.GetProjectVersion(folder);
p.Arguments = Tools.ReadCustomProjectData(folder, launcherArgumentsFile);
if ((bool)chkShowPlatform.IsChecked == true) p.TargetPlatform = Tools.GetTargetPlatform(folder);
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder);
return p;
}
void AddNewProjectToList(Project proj)
{
projectsSource.Insert(0, proj);
gridRecent.SelectedIndex = 0;
Tools.SetFocusToGrid(gridRecent);
// force refresh
txtSearchBox.Text = proj.Title;
txtSearchBox.Text = "";
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
{
CloseThemeEditor();
// remove focus from minimize button
gridRecent.Focus();
if (chkMinimizeToTaskbar.IsChecked == true)
{
notifyIcon.Visible = true;
this.Hide();
}
else
{
this.WindowState = WindowState.Minimized;
}
}
private void OnGetUnityUpdatesClick(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
button.IsEnabled = false;
// refresh installations, if already added some new ones
UpdateUnityInstallationsList();
txtSearchBoxUpdates.Text = "";
// clear filters, since right now they are not used after updates are loaded
rdoAll.IsChecked = true;
CallGetUnityUpdates();
button.IsEnabled = true;
}
private void OnWindowKeyDown(object sender, KeyEventArgs e)
{
// disable alt key?
/*
if (Keyboard.Modifiers == ModifierKeys.Alt)
{
e.Handled = true;
}*/
switch (tabControl.SelectedIndex)
{
case 0: // Projects
switch (e.Key)
{
case Key.LeftCtrl: // used for ctrl+c
break;
case Key.Escape: // clear project search
if (txtSearchBox.Text == "")
{
// its already clear
}
else // we have text in searchbox, clear it
{
txtSearchBox.Text = "";
}
// try to keep selected row selected and in view
Tools.SetFocusToGrid(gridRecent);
break;
case Key.F5:
txtSearchBox.Text = "";
break;
case Key.Up:
case Key.Down:
case Key.Left:
case Key.Right:
break;
case Key.F2: // edit arguments or project name
if (chkEnableProjectRename.IsChecked == false) return; //if rename not enabled
// if not inside datagrid, cancel
if (Tools.HasFocus(this, gridRecent, true) == false) return;
var cell = gridRecent.CurrentCell;
// if in first cell (or no cell)
if (cell.Column.DisplayIndex == 0)
{
// enable cell edit
cell.Column.IsReadOnly = false;
// start editing that cell
gridRecent.CurrentCell = new DataGridCellInfo(gridRecent.Items[gridRecent.SelectedIndex], gridRecent.Columns[cell.Column.DisplayIndex]);
gridRecent.BeginEdit();
}
break;
default: // any key anykey
// cancel if editing cell
IEditableCollectionView itemsView = gridRecent.Items;
if (itemsView.IsAddingNew || itemsView.IsEditingItem) return;
// skip these keys
if (Keyboard.Modifiers == ModifierKeys.Alt) return;
if (Keyboard.Modifiers == ModifierKeys.Control) return;
// activate searchbar if not active and we are in tab#1
if (txtSearchBox.IsFocused == false)
{
txtSearchBox.Focus();
txtSearchBox.Select(txtSearchBox.Text.Length, 0);
}
break;
}
break;
case 1: // Unitys/Editors
switch (e.Key)
{
case Key.F5: // refresh unitys
UpdateUnityInstallationsList();
break;
case Key.Escape: // clear project search
txtSearchBoxUnity.Text = "";
break;
default:
if (txtSearchBoxUnity.IsFocused == false)
{
txtSearchBoxUnity.Focus();
txtSearchBoxUnity.Select(txtSearchBoxUnity.Text.Length, 0);
}
break;
}
break;
case 2: // Updates
switch (e.Key)
{