FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
UnityLauncher/UnityLauncher/Form1.cs at master · satesdel/UnityLauncher · GitHub
satesdel
UnityLauncher
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
UnityLauncher
/
UnityLauncher
/
Form1.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
1479 lines (1287 loc) · 58.9 KB
Breadcrumbs
UnityLauncher
/
UnityLauncher
/
Form1.cs
Copy path
File metadata and controls
1479 lines (1287 loc) · 58.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
Microsoft
.
Win32
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Diagnostics
;
using
System
.
Drawing
;
using
System
.
IO
;
using
System
.
Linq
;
using
System
.
Net
;
using
System
.
Reflection
;
using
System
.
Text
;
using
System
.
Text
.
RegularExpressions
;
using
System
.
Windows
.
Forms
;
using
UnityLauncherTools
;
namespace
UnityLauncher
{
public
partial
class
Form1
:
Form
{
public
static
Dictionary
<
string
,
string
>
unityList
=
new
Dictionary
<
string
,
string
>
(
)
;
const
string
contextRegRoot
=
"Software
\\
Classes
\\
Directory
\\
Background
\\
shell"
;
const
string
launcherArgumentsFile
=
"LauncherArguments.txt"
;
const
string
githubReleasesLinkURL
=
"https://github.com/unitycoder/UnityLauncher/releases"
;
bool
isDownloadingUnityList
=
false
;
string
previousGitRelease
=
"0"
;
public
Form1
(
)
{
InitializeComponent
(
)
;
}
private
void
Form1_Load
(
object
sender
,
EventArgs
e
)
{
Start
(
)
;
}
void
Start
(
)
{
SetStatus
(
"Initializing ..."
)
;
// check installations folder
var
root
=
GetUnityInstallationsRootFolder
(
)
;
if
(
root
==
null
||
root
.
Length
==
0
)
{
SetStatus
(
"Missing root folder ..."
)
;
AddUnityInstallationRootFolder
(
)
;
SetStatus
(
"Ready"
)
;
}
LoadSettings
(
)
;
// scan installed unitys
bool
foundUnitys
=
ScanUnityInstallations
(
)
;
if
(
foundUnitys
==
false
)
{
SetStatus
(
"Error> Did not find any Unity installations, try setting correct root folder ..."
)
;
UpdateRecentProjectsList
(
)
;
tabControl1
.
SelectedIndex
=
tabControl1
.
TabCount
-
1
;
// last tab is settings
return
;
}
// 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"
)
{
SetStatus
(
"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
]
;
}
// check if force-update button is down
if
(
(
Control
.
ModifierKeys
&
Keys
.
Shift
)
!=
0
)
{
DisplayUpgradeDialog
(
version
,
projectPathArgument
,
launchProject
:
true
,
commandLineArguments
:
commandLineArguments
)
;
}
else
{
// try launching it
LaunchProject
(
projectPathArgument
,
version
,
openProject
:
true
,
commandLineArguments
:
commandLineArguments
)
;
}
// quit after launch if enabled in settings
if
(
Properties
.
Settings
.
Default
.
closeAfterExplorer
==
true
)
{
Application
.
Exit
(
)
;
}
//SetStatus("Ready");
}
else
{
SetStatus
(
"Error> Invalid arguments:"
+
args
[
1
]
)
;
}
}
UpdateRecentProjectsList
(
)
;
// preselect grid
gridRecent
.
Select
(
)
;
// get previous version build info string
// this string is release tag for latest release when this app was compiled
using
(
Stream
stream
=
Assembly
.
GetExecutingAssembly
(
)
.
GetManifestResourceStream
(
"UnityLauncher."
+
"PreviousVersion.txt"
)
)
using
(
StreamReader
reader
=
new
StreamReader
(
stream
)
)
{
previousGitRelease
=
reader
.
ReadToEnd
(
)
.
Trim
(
)
;
}
}
void
LoadSettings
(
)
{
// form size
this
.
Width
=
Properties
.
Settings
.
Default
.
formWidth
;
this
.
Height
=
Properties
.
Settings
.
Default
.
formHeight
;
// update settings window
chkMinimizeToTaskbar
.
Checked
=
Properties
.
Settings
.
Default
.
minimizeToTaskbar
;
chkQuitAfterCommandline
.
Checked
=
Properties
.
Settings
.
Default
.
closeAfterExplorer
;
ChkQuitAfterOpen
.
Checked
=
Properties
.
Settings
.
Default
.
closeAfterProject
;
chkShowLauncherArgumentsColumn
.
Checked
=
Properties
.
Settings
.
Default
.
showArgumentsColumn
;
chkShowGitBranchColumn
.
Checked
=
Properties
.
Settings
.
Default
.
showGitBranchColumn
;
chkDarkSkin
.
Checked
=
Properties
.
Settings
.
Default
.
useDarkSkin
;
// update optional grid columns, hidden or visible
gridRecent
.
Columns
[
"_launchArguments"
]
.
Visible
=
chkShowLauncherArgumentsColumn
.
Checked
;
gridRecent
.
Columns
[
"_gitBranch"
]
.
Visible
=
chkShowGitBranchColumn
.
Checked
;
// update installations folder listbox
lstRootFolders
.
Items
.
Clear
(
)
;
lstRootFolders
.
Items
.
AddRange
(
Properties
.
Settings
.
Default
.
rootFolders
.
Cast
<
string
>
(
)
.
ToArray
(
)
)
;
// update packages folder listbox
lstPackageFolders
.
Items
.
AddRange
(
Properties
.
Settings
.
Default
.
packageFolders
.
Cast
<
string
>
(
)
.
ToArray
(
)
)
;
// restore data grid view widths
int
[
]
gridColumnWidths
=
Properties
.
Settings
.
Default
.
gridColumnWidths
;
if
(
gridColumnWidths
!=
null
)
{
for
(
int
i
=
0
;
i
<
gridColumnWidths
.
Length
;
++
i
)
{
gridRecent
.
Columns
[
i
]
.
Width
=
gridColumnWidths
[
i
]
;
}
}
// TODO assign colors for dark theme
if
(
chkDarkSkin
.
Checked
==
true
)
{
var
darkBg
=
Color
.
FromArgb
(
32
,
37
,
41
)
;
var
darkRaised
=
Color
.
FromArgb
(
50
,
56
,
61
)
;
var
darkBright
=
Color
.
FromArgb
(
161
,
180
,
196
)
;
this
.
BackColor
=
darkBg
;
tabProjects
.
BackColor
=
darkRaised
;
gridRecent
.
BackgroundColor
=
darkRaised
;
gridRecent
.
GridColor
=
darkBg
;
var
dgs
=
new
DataGridViewCellStyle
(
)
;
dgs
.
BackColor
=
darkRaised
;
dgs
.
ForeColor
=
darkBright
;
gridRecent
.
DefaultCellStyle
=
dgs
;
statusStrip1
.
BackColor
=
darkRaised
;
}
}
/// <summary>
/// returns true if we have exact version installed
/// </summary>
/// <param name="version"></param>
/// <returns></returns>
bool
HaveExactVersionInstalled
(
string
version
)
{
return
string
.
IsNullOrEmpty
(
version
)
==
false
&&
unityList
.
ContainsKey
(
version
)
;
}
void
AddUnityInstallationRootFolder
(
)
{
folderBrowserDialog1
.
Description
=
"Select Unity installations root folder"
;
var
d
=
folderBrowserDialog1
.
ShowDialog
(
)
;
var
newRoot
=
folderBrowserDialog1
.
SelectedPath
;
if
(
String
.
IsNullOrWhiteSpace
(
newRoot
)
==
false
&&
Directory
.
Exists
(
newRoot
)
==
true
)
{
lstRootFolders
.
Items
.
Add
(
newRoot
)
;
Properties
.
Settings
.
Default
.
rootFolders
.
Add
(
newRoot
)
;
Properties
.
Settings
.
Default
.
Save
(
)
;
}
}
bool
ScanUnityInstallations
(
)
{
SetStatus
(
"Scanning Unity installations ..."
)
;
// dictionary to keep version and path
unityList
.
Clear
(
)
;
// installed unitys list in other tab
gridUnityList
.
Rows
.
Clear
(
)
;
// iterate all root folders
foreach
(
string
root
in
lstRootFolders
.
Items
)
{
if
(
String
.
IsNullOrWhiteSpace
(
root
)
==
false
&&
Directory
.
Exists
(
root
)
==
true
)
{
// parse all folders here, and search for unity editor files
var
directories
=
Directory
.
GetDirectories
(
root
)
;
for
(
int
i
=
0
,
length
=
directories
.
Length
;
i
<
length
;
i
++
)
{
var
uninstallExe
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
,
"Uninstall.exe"
)
;
if
(
File
.
Exists
(
uninstallExe
)
==
true
)
{
var
unityExe
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
,
"Unity.exe"
)
;
if
(
File
.
Exists
(
unityExe
)
==
true
)
{
// get full version number from uninstaller
var
unityVersion
=
Tools
.
GetFileVersionData
(
uninstallExe
)
.
Replace
(
"Unity"
,
""
)
.
Trim
(
)
;
if
(
unityList
.
ContainsKey
(
unityVersion
)
==
false
)
{
unityList
.
Add
(
unityVersion
,
unityExe
)
;
var
dataFolder
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
,
"Data"
)
;
DateTime
?
installDate
=
Tools
.
GetLastModifiedTime
(
dataFolder
)
;
// TODO add platforms: PC|iOS|tvOS|Android|UWP|WebGL|Facebook|XBox|PSVita|PS4
gridUnityList
.
Rows
.
Add
(
unityVersion
,
unityExe
,
installDate
)
;
}
}
// have unity.exe
}
// have uninstaller.exe
else
// no uninstaller, probably preview builds
{
var
unityExe
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
,
"Unity.exe"
)
;
if
(
File
.
Exists
(
unityExe
)
==
true
)
{
// get full version number from uninstaller
var
unityVersion
=
Tools
.
GetFileVersionData
(
unityExe
)
.
Replace
(
"Unity"
,
""
)
.
Trim
(
)
;
if
(
unityList
.
ContainsKey
(
unityVersion
)
==
false
)
{
unityList
.
Add
(
unityVersion
,
unityExe
)
;
var
dataFolder
=
Path
.
Combine
(
directories
[
i
]
,
"Editor"
,
"Data"
)
;
DateTime
?
installDate
=
Tools
.
GetLastModifiedTime
(
dataFolder
)
;
// TODO add platforms: PC|iOS|tvOS|Android|UWP|WebGL|Facebook|XBox|PSVita|PS4
gridUnityList
.
Rows
.
Add
(
unityVersion
,
unityExe
,
installDate
)
;
}
}
// have unity.exe
}
}
// got folders
}
// failed check
}
// all root folders
lbl_unityCount
.
Text
=
"Found "
+
unityList
.
Count
.
ToString
(
)
+
" versions"
;
SetStatus
(
"Finished scanning"
)
;
// found any Unity installations?
return
unityList
.
Count
>
0
;
}
void
FilterRecentProject
(
object
sender
,
EventArgs
e
)
{
SetStatus
(
"Filtering recent projects list ..."
)
;
string
searchString
=
tbSearchBar
.
Text
;
foreach
(
DataGridViewRow
row
in
gridRecent
.
Rows
)
{
if
(
row
.
Cells
[
"_project"
]
.
Value
.
ToString
(
)
.
IndexOf
(
searchString
,
StringComparison
.
OrdinalIgnoreCase
)
>
-
1
)
{
row
.
Visible
=
true
;
}
else
{
row
.
Visible
=
false
;
}
}
lblClearSearchField
.
Visible
=
tbSearchBar
.
Text
.
Length
>
0
;
}
void
FilterUnityUpdates
(
object
sender
,
EventArgs
e
)
{
SetStatus
(
"Filtering Unity updates list ..."
)
;
string
searchString
=
tbSearchUpdates
.
Text
;
foreach
(
DataGridViewRow
row
in
gridUnityUpdates
.
Rows
)
{
if
(
row
.
Cells
[
"_UnityUpdateVersion"
]
.
Value
.
ToString
(
)
.
IndexOf
(
searchString
,
StringComparison
.
OrdinalIgnoreCase
)
>
-
1
)
{
row
.
Visible
=
true
;
}
else
{
row
.
Visible
=
false
;
}
}
}
/// <summary>
/// scans registry for recent projects and adds to project grid list
/// </summary>
void
UpdateRecentProjectsList
(
)
{
SetStatus
(
"Updating recent projects list ..."
)
;
gridRecent
.
Rows
.
Clear
(
)
;
var
hklm
=
RegistryKey
.
OpenBaseKey
(
RegistryHive
.
CurrentUser
,
RegistryView
.
Registry64
)
;
string
[
]
registryPathsToCheck
=
new
string
[
]
{
@"SOFTWARE\Unity Technologies\Unity Editor 5.x"
,
@"SOFTWARE\Unity Technologies\Unity Editor 4.x"
}
;
// check each version path
for
(
int
i
=
0
,
len
=
registryPathsToCheck
.
Length
;
i
<
len
;
i
++
)
{
RegistryKey
key
=
hklm
.
OpenSubKey
(
registryPathsToCheck
[
i
]
)
;
if
(
key
==
null
)
{
continue
;
}
else
{
//Console.WriteLine("Null registry key at " + registryPathsToCheck[i]);
}
// parse recent project path
foreach
(
var
valueName
in
key
.
GetValueNames
(
)
)
{
if
(
valueName
.
IndexOf
(
"RecentlyUsedProjectPaths-"
)
==
0
)
{
string
projectPath
=
""
;
// check if binary or not
var
valueKind
=
key
.
GetValueKind
(
valueName
)
;
if
(
valueKind
==
RegistryValueKind
.
Binary
)
{
byte
[
]
projectPathBytes
=
(
byte
[
]
)
key
.
GetValue
(
valueName
)
;
projectPath
=
Encoding
.
UTF8
.
GetString
(
projectPathBytes
,
0
,
projectPathBytes
.
Length
-
1
)
;
}
else
// should be string then
{
projectPath
=
(
string
)
key
.
GetValue
(
valueName
)
;
}
// first check if whole folder exists, if not, skip
if
(
Directory
.
Exists
(
projectPath
)
==
false
)
{
//Console.WriteLine("Recent project directory not found, skipping: " + projectPath);
continue
;
}
string
projectName
=
""
;
// get project name from full path
if
(
projectPath
.
IndexOf
(
Path
.
DirectorySeparatorChar
)
>
-
1
)
{
projectName
=
projectPath
.
Substring
(
projectPath
.
LastIndexOf
(
Path
.
DirectorySeparatorChar
)
+
1
)
;
}
else
if
(
projectPath
.
IndexOf
(
Path
.
AltDirectorySeparatorChar
)
>
-
1
)
{
projectName
=
projectPath
.
Substring
(
projectPath
.
LastIndexOf
(
Path
.
AltDirectorySeparatorChar
)
+
1
)
;
}
else
// no path separator found
{
projectName
=
projectPath
;
}
string
csprojFile
=
Path
.
Combine
(
projectPath
,
projectName
+
".csproj"
)
;
// solution only
if
(
File
.
Exists
(
csprojFile
)
==
false
)
{
csprojFile
=
Path
.
Combine
(
projectPath
,
projectName
+
".sln"
)
;
}
// editor only project
if
(
File
.
Exists
(
csprojFile
)
==
false
)
{
csprojFile
=
Path
.
Combine
(
projectPath
,
projectName
+
".Editor.csproj"
)
;
}
// maybe 4.x project
if
(
File
.
Exists
(
csprojFile
)
==
false
)
{
csprojFile
=
Path
.
Combine
(
projectPath
,
"Assembly-CSharp.csproj"
)
;
}
// get last modified date
DateTime
?
lastUpdated
=
Tools
.
GetLastModifiedTime
(
csprojFile
)
;
// get project version
string
projectVersion
=
Tools
.
GetProjectVersion
(
projectPath
)
;
// get custom launch arguments, only if column in enabled
string
customArgs
=
""
;
if
(
chkShowLauncherArgumentsColumn
.
Checked
==
true
)
{
customArgs
=
Tools
.
ReadCustomLaunchArguments
(
projectPath
,
launcherArgumentsFile
)
;
}
// get git branchinfo, only if column in enabled
string
gitBranch
=
""
;
if
(
chkShowGitBranchColumn
.
Checked
==
true
)
{
gitBranch
=
Tools
.
ReadGitBranchInfo
(
projectPath
)
;
}
gridRecent
.
Rows
.
Add
(
projectName
,
projectVersion
,
projectPath
,
lastUpdated
,
customArgs
,
gitBranch
)
;
gridRecent
.
Rows
[
gridRecent
.
Rows
.
Count
-
1
]
.
Cells
[
1
]
.
Style
.
ForeColor
=
HaveExactVersionInstalled
(
projectVersion
)
?
Color
.
Green
:
Color
.
Red
;
}
}
}
//SetStatus("Ready");
}
void
LaunchProject
(
string
projectPath
,
string
version
,
bool
openProject
=
true
,
string
commandLineArguments
=
""
)
{
if
(
Directory
.
Exists
(
projectPath
)
==
true
)
{
// no assets path, probably we want to create new project then
var
assetsFolder
=
Path
.
Combine
(
projectPath
,
"Assets"
)
;
if
(
Directory
.
Exists
(
assetsFolder
)
==
false
)
{
// TODO could ask if want to create project..
Directory
.
CreateDirectory
(
assetsFolder
)
;
}
// when opening project, check for crashed backup scene first
if
(
openProject
==
true
)
{
var
cancelLaunch
=
CheckCrashBackupScene
(
projectPath
)
;
if
(
cancelLaunch
==
true
)
{
return
;
}
}
if
(
HaveExactVersionInstalled
(
version
)
==
true
)
{
if
(
openProject
==
true
)
{
SetStatus
(
"Launching project in Unity "
+
version
)
;
}
else
{
SetStatus
(
"Launching Unity "
+
version
)
;
}
try
{
Process
myProcess
=
new
Process
(
)
;
var
cmd
=
"
\"
"
+
unityList
[
version
]
+
"
\"
"
;
myProcess
.
StartInfo
.
FileName
=
cmd
;
if
(
openProject
==
true
)
{
var
pars
=
" -projectPath "
+
"
\"
"
+
projectPath
+
"
\"
"
;
// check for custom launch parameters and append them
string
customArguments
=
GetSelectedRowData
(
"_launchArguments"
)
;
if
(
string
.
IsNullOrEmpty
(
customArguments
)
==
false
)
{
pars
+=
" "
+
customArguments
;
}
myProcess
.
StartInfo
.
Arguments
=
pars
+
commandLineArguments
;
}
myProcess
.
Start
(
)
;
if
(
Properties
.
Settings
.
Default
.
closeAfterProject
)
{
Environment
.
Exit
(
0
)
;
}
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
)
;
}
}
else
// we dont have this version installed (or no version info available)
{
SetStatus
(
"Missing Unity version: "
+
version
)
;
// if only running only, stop here
if
(
openProject
==
true
)
DisplayUpgradeDialog
(
version
,
projectPath
)
;
}
}
else
// given path doesnt exists, strange
{
SetStatus
(
"Invalid path: "
+
projectPath
)
;
}
}
bool
CheckCrashBackupScene
(
string
projectPath
)
{
var
cancelRunningUnity
=
false
;
var
recoveryFile
=
Path
.
Combine
(
projectPath
,
"Temp"
,
"__Backupscenes"
,
"0.backup"
)
;
if
(
File
.
Exists
(
recoveryFile
)
)
{
DialogResult
dialogResult
=
MessageBox
.
Show
(
"Crash recovery scene found, do you want to copy it into Assets/_Recovery/-folder?"
,
"UnityLauncher - Scene Recovery"
,
MessageBoxButtons
.
YesNoCancel
)
;
if
(
dialogResult
==
DialogResult
.
Yes
)
// restore
{
var
restoreFolder
=
Path
.
Combine
(
projectPath
,
"Assets"
,
"_Recovery"
)
;
if
(
Directory
.
Exists
(
restoreFolder
)
==
false
)
{
Directory
.
CreateDirectory
(
restoreFolder
)
;
}
if
(
Directory
.
Exists
(
restoreFolder
)
==
true
)
{
Int32
unixTimestamp
=
(
Int32
)
(
DateTime
.
UtcNow
.
Subtract
(
new
DateTime
(
1970
,
1
,
1
)
)
)
.
TotalSeconds
;
var
uniqueFileName
=
"Recovered_Scene"
+
unixTimestamp
+
".unity"
;
File
.
Copy
(
recoveryFile
,
Path
.
Combine
(
restoreFolder
,
uniqueFileName
)
)
;
SetStatus
(
"Recovered crashed scene into: "
+
restoreFolder
)
;
}
else
{
SetStatus
(
"Error: Failed to create restore folder: "
+
restoreFolder
)
;
cancelRunningUnity
=
true
;
}
}
else
if
(
dialogResult
==
DialogResult
.
Cancel
)
// dont do restore, but run Unity
{
cancelRunningUnity
=
true
;
}
}
return
cancelRunningUnity
;
}
// parse Unity installer exe from release page
// thanks to https://github.com/softfruit
string
ParseDownloadURLFromWebpage
(
string
version
)
{
string
url
=
""
;
using
(
WebClient
client
=
new
WebClient
(
)
)
{
// get correct page url
string
website
=
"https://unity3d.com/get-unity/download/archive"
;
if
(
Tools
.
VersionIsPatch
(
version
)
)
website
=
"https://unity3d.com/unity/qa/patch-releases"
;
if
(
Tools
.
VersionIsBeta
(
version
)
)
website
=
"https://unity3d.com/unity/beta/"
+
version
;
if
(
Tools
.
VersionIsAlpha
(
version
)
)
website
=
"https://unity3d.com/unity/alpha/"
+
version
;
// download html
string
sourceHTML
=
client
.
DownloadString
(
website
)
;
string
[
]
lines
=
sourceHTML
.
Split
(
new
[
]
{
"
\r
\n
"
,
"
\r
"
,
"
\n
"
}
,
StringSplitOptions
.
None
)
;
// patch version download assistant finder
if
(
Tools
.
VersionIsPatch
(
version
)
)
{
for
(
int
i
=
0
;
i
<
lines
.
Length
;
i
++
)
{
if
(
lines
[
i
]
.
Contains
(
"UnityDownloadAssistant-"
+
version
+
".exe"
)
)
{
int
start
=
lines
[
i
]
.
IndexOf
(
'"'
)
+
1
;
int
end
=
lines
[
i
]
.
IndexOf
(
'"'
,
start
)
;
url
=
lines
[
i
]
.
Substring
(
start
,
end
-
start
)
;
break
;
}
}
}
else
if
(
Tools
.
VersionIsArchived
(
version
)
)
{
// archived version download assistant finder
for
(
int
i
=
0
;
i
<
lines
.
Length
;
i
++
)
{
// find line where full installer is (from archive page)
if
(
lines
[
i
]
.
Contains
(
"UnitySetup64-"
+
version
)
)
{
// take previous line, which contains download assistant url
string
line
=
lines
[
i
-
1
]
;
int
start
=
line
.
IndexOf
(
'"'
)
+
1
;
int
end
=
line
.
IndexOf
(
'"'
,
start
)
;
url
=
@"https://unity3d.com"
+
line
.
Substring
(
start
,
end
-
start
)
;
break
;
}
}
}
else
// alpha or beta version download assistant finder
{
for
(
int
i
=
0
;
i
<
lines
.
Length
;
i
++
)
{
if
(
lines
[
i
]
.
Contains
(
"UnityDownloadAssistant.exe"
)
)
{
int
start
=
lines
[
i
]
.
IndexOf
(
'"'
)
+
1
;
int
end
=
lines
[
i
]
.
IndexOf
(
'"'
,
start
)
;
url
=
lines
[
i
]
.
Substring
(
start
,
end
-
start
)
+
"#version="
+
version
;
break
;
}
}
}
}
// didnt find installer
if
(
string
.
IsNullOrEmpty
(
url
)
)
{
SetStatus
(
"Cannot find UnityDownloadAssistant.exe for this version."
)
;
}
return
url
;
}
/// <summary>
/// launches browser to download installer
/// </summary>
/// <param name="url">full url to installer</param>
void
DownloadInBrowser
(
string
url
,
string
version
)
{
string
exeURL
=
ParseDownloadURLFromWebpage
(
version
)
;
if
(
string
.
IsNullOrEmpty
(
exeURL
)
==
false
)
{
SetStatus
(
"Download installer in browser: "
+
exeURL
)
;
Process
.
Start
(
exeURL
)
;
}
else
// not found
{
SetStatus
(
"Error> Cannot find installer executable ... opening website instead"
)
;
url
=
"https://unity3d.com/get-unity/download/archive"
;
Process
.
Start
(
url
+
"#installer-not-found---version-"
+
version
)
;
}
}
/// <summary>
/// get rootfolder from settings, default is c:\program files\
/// </summary>
/// <returns></returns>
string
[
]
GetUnityInstallationsRootFolder
(
)
{
string
[
]
rootFolders
=
null
;
try
{
// if settings exists, use that value
rootFolders
=
new
string
[
Properties
.
Settings
.
Default
.
rootFolders
.
Count
]
;
Properties
.
Settings
.
Default
.
rootFolders
.
CopyTo
(
rootFolders
,
0
)
;
}
catch
(
Exception
e
)
{
MessageBox
.
Show
(
"Rare error while checking Unity installation folder settings: "
+
e
.
Message
,
"UnityLauncher"
,
MessageBoxButtons
.
OK
)
;
// this doesnt work?
Properties
.
Settings
.
Default
.
Reset
(
)
;
Properties
.
Settings
.
Default
.
Save
(
)
;
}
return
rootFolders
;
}
void
SetStatus
(
string
msg
)
{
toolStripStatusLabel1
.
Text
=
msg
;
this
.
Refresh
(
)
;
}
private
void
ShowForm
(
)
{
this
.
WindowState
=
FormWindowState
.
Minimized
;
this
.
Show
(
)
;
this
.
WindowState
=
FormWindowState
.
Normal
;
notifyIcon
.
Visible
=
false
;
}
void
LaunchSelectedProject
(
bool
openProject
=
true
)
{
FixSelectedRow
(
)
;
var
selected
=
gridRecent
?
.
CurrentCell
?
.
RowIndex
;
if
(
selected
.
HasValue
&&
selected
>
-
1
)
{
var
projectPath
=
gridRecent
.
Rows
[
(
int
)
selected
]
.
Cells
[
"_path"
]
.
Value
.
ToString
(
)
;
var
version
=
Tools
.
GetProjectVersion
(
projectPath
)
;
Console
.
WriteLine
(
"version: '"
+
version
+
"'"
)
;
LaunchProject
(
projectPath
,
version
,
openProject
)
;
//SetStatus("Ready");
}
}
void
LaunchSelectedUnity
(
)
{
var
selected
=
gridUnityList
?
.
CurrentCell
?
.
RowIndex
;
if
(
selected
.
HasValue
&&
selected
>
-
1
)
{
var
version
=
gridUnityList
.
Rows
[
(
int
)
selected
]
.
Cells
[
"_unityVersion"
]
.
Value
.
ToString
(
)
;
SetStatus
(
"Launching Unity: "
+
version
)
;
try
{
Process
myProcess
=
new
Process
(
)
;
var
cmd
=
"
\"
"
+
unityList
[
version
]
+
"
\"
"
;
myProcess
.
StartInfo
.
FileName
=
cmd
;
myProcess
.
Start
(
)
;
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
)
;
}
//SetStatus("Ready");
}
}
void
AddPackageFolder
(
)
{
folderBrowserDialog1
.
Description
=
"Select package folder"
;
var
d
=
folderBrowserDialog1
.
ShowDialog
(
)
;
var
newPackageFolder
=
folderBrowserDialog1
.
SelectedPath
;
if
(
String
.
IsNullOrWhiteSpace
(
newPackageFolder
)
==
false
&&
Directory
.
Exists
(
newPackageFolder
)
==
true
)
{
lstPackageFolders
.
Items
.
Add
(
newPackageFolder
)
;
Properties
.
Settings
.
Default
.
packageFolders
.
Add
(
newPackageFolder
)
;
Properties
.
Settings
.
Default
.
Save
(
)
;
}
}
#region Buttons and UI events
private
void
btnRemoveRegister_Click
(
object
sender
,
EventArgs
e
)
{
Tools
.
RemoveContextMenuRegistry
(
contextRegRoot
)
;
}
private
void
chkMinimizeToTaskbar_CheckedChanged
(
object
sender
,
EventArgs
e
)
{
Properties
.
Settings
.
Default
.
minimizeToTaskbar
=
chkMinimizeToTaskbar
.
Checked
;
Properties
.
Settings
.
Default
.
Save
(
)
;
}
private
void
btnAddPackageFolder_Click
(
object
sender
,
EventArgs
e
)
{
AddPackageFolder
(
)
;
}
private
void
btnRemovePackFolder_Click
(
object
sender
,
EventArgs
e
)
{
if
(
lstPackageFolders
.
SelectedIndex
>
-
1
)
{
lstPackageFolders
.
Items
.
RemoveAt
(
lstPackageFolders
.
SelectedIndex
)
;
}
}
private
void
btnOpenReleasePage_Click
(
object
sender
,
EventArgs
e
)
{
var
selected
=
gridUnityList
?
.
CurrentCell
?
.
RowIndex
;
if
(
selected
.
HasValue
&&
selected
>
-
1
)
{
var
version
=
gridUnityList
.
Rows
[
(
int
)
selected
]
.
Cells
[
"_unityVersion"
]
.
Value
.
ToString
(
)
;
if
(
Tools
.
OpenReleaseNotes
(
version
)
==
true
)
{
SetStatus
(
"Opening release notes for version "
+
version
)
;
}
else
{
SetStatus
(
"Failed opening Release Notes URL for version "
+
version
)
;
}
}
}
private
void
btnLaunchUnity_Click
(
object
sender
,
EventArgs
e
)
{
LaunchSelectedUnity
(
)
;
}
private
void
btnExploreUnity_Click
(
object
sender
,
EventArgs
e
)
{
var
selected
=
gridUnityList
?
.
CurrentCell
?
.
RowIndex
;
if
(
selected
.
HasValue
&&
selected
>
-
1
)
{
var
unityPath
=
Path
.
GetDirectoryName
(
gridUnityList
.
Rows
[
(
int
)
selected
]
.
Cells
[
"_unityPath"
]
.
Value
.
ToString
(
)
)
;
if
(
Tools
.
LaunchExplorer
(
unityPath
)
==
false
)
{
SetStatus
(
"Error> Directory not found: "
+
unityPath
)
;
}
}
}
private
void
btnAddUnityFolder_Click
(
object
sender
,
EventArgs
e
)
{
AddUnityInstallationRootFolder
(
)
;
ScanUnityInstallations
(
)
;
UpdateRecentProjectsList
(
)
;
}
private
void
btnRemoveInstallFolder_Click
(
object
sender
,
EventArgs
e
)
{
if
(
lstRootFolders
.
SelectedIndex
>
-
1
)
{
Properties
.
Settings
.
Default
.
rootFolders
.
Remove
(
lstRootFolders
.
Items
[
lstRootFolders
.
SelectedIndex
]
.
ToString
(
)
)
;
Properties
.
Settings
.
Default
.
Save
(
)
;
lstRootFolders
.
Items
.
RemoveAt
(
lstRootFolders
.
SelectedIndex
)
;
ScanUnityInstallations
(
)
;
}
}
private
void
btnFetchUnityVersions_Click
(
object
sender
,
EventArgs
e
)
{
FetchListOfUnityUpdates
(
)
;
}
int
lastKnownSelectedRow
=
-
1
;
private
void
unityGridView_KeyDown
(
object
sender
,
KeyEventArgs
e
)
{
switch
(
e
.
KeyCode
)
{
case
Keys
.
Return
:
// launch selected Unity
e
.
SuppressKeyPress
=
true
;
LaunchSelectedUnity
(
)
;
break
;
case
Keys
.
F5
:
// refresh installed Unity versions list
ScanUnityInstallations
(
)
;
UpdateRecentProjectsList
(
)
;
break
;
default
:
break
;
}
}
/// <summary>
/// global keys
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
Form1_KeyPress
(
object
sender
,
KeyPressEventArgs
e
)
{
// if editing cells, dont focus on search
if
(
gridRecent
.
IsCurrentCellInEditMode
==
true
)
return
;
switch
(
(
int
)
e
.
KeyChar
)
{
case
27
:
// ESCAPE - clear search
if
(
tabControl1
.
SelectedIndex
==
0
&&
tbSearchBar
.
Text
!=
""
)
{
tbSearchBar
.
Text
=
""
;
lblClearSearchField
.
Visible
=
false
;
}
else
if
(
tabControl1
.
SelectedIndex
==
3
&&
tbSearchUpdates
.
Text
!=
""
)
{
tbSearchUpdates
.
Text
=
""
;
}
break
;
default
:
// any key
// activate searchbar if not active and we are in tab#1
if
(
tabControl1
.
SelectedIndex
==
0
&&
tbSearchBar
.
Focused
==
false
)
{
// skip tab key on search field
if
(
(
int
)
e
.
KeyChar
==
9
)
{
break
;
}
tbSearchBar
.
Focus
(
)
;
tbSearchBar
.
Text
+=
e
.
KeyChar
;
tbSearchBar
.
Select
(
tbSearchBar
.
Text
.
Length
,
0
)
;
lblClearSearchField
.
Visible
=
tbSearchBar
.
Text
.
Length
>
0
;
}
break
;
}
}
/// <summary>
/// grid keys
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
gridRecent_KeyDown
(
object
sender
,
KeyEventArgs
e
)
{
// if editing cells, dont search or launch
if
(
gridRecent
.
IsCurrentCellInEditMode
==
true
)
return
;
switch
(
e
.
KeyCode
)
{
case
Keys
.
Return
:
// launch selected project
e
.
SuppressKeyPress
=
true
;
LaunchSelectedProject
(
)
;
break
;
case
Keys
.
F5
:
// refresh recent projects list
lastKnownSelectedRow
=
GetSelectedRowIndex
(
)
;
Console
.
WriteLine
(
lastKnownSelectedRow
)
;
UpdateRecentProjectsList
(
)
;
SetSelectedRowIndex
(
lastKnownSelectedRow
)
;
break
;
default
:
break
;
}
}
//Checks if you are doubleclicking the current cell
private
void
GridRecent_CellMouseDoubleClick
(
object
sender
,
DataGridViewCellMouseEventArgs
e
)
{
if
(
e
.
Button
==
MouseButtons
.
Left
&&
e
.
RowIndex
==
gridRecent
.
CurrentCell
.
RowIndex
)
{
LaunchSelectedProject
(
)
;
}
}
// set basefolder of all Unity installations
private
void
btn_setinstallfolder_Click
(
object
sender
,
EventArgs
e
)
{
AddUnityInstallationRootFolder
(
)
;
ScanUnityInstallations
(
)
;
UpdateRecentProjectsList
(
)
;
}
private
void
btnLaunch_Click
(
object
sender
,
EventArgs
e
)
{
LaunchSelectedProject
(
)
;
}
private
void
Form1_Resize
(
object
sender
,
EventArgs
e
)
{
if
(
chkMinimizeToTaskbar
.
Checked
==
true
)
{
if
(
FormWindowState
.
Minimized
==
this
.
WindowState
)
{
notifyIcon
.
Visible
=
true
;
this
.
Hide
(
)
;
}
else
if
(
FormWindowState
.
Normal
==
this
.
WindowState
)
{
notifyIcon
.
Visible
=
false
;
}
}
}
private
void
btnRefresh_Click
(
object
sender
,
EventArgs
e
)
{
ScanUnityInstallations
(
)
;
UpdateRecentProjectsList
(
)
;
}
private
void
notifyIcon_MouseClick
(
object
sender
,
MouseEventArgs
e
)
{
ShowForm
(
)
;
}
private
void
btn_openFolder_Click
(
object
sender
,
EventArgs
e
)
{
FixSelectedRow
(
)
;
var
selected
=
gridRecent
?
.
CurrentCell
?
.
RowIndex
;
if
(
selected
.
HasValue
&&
selected
>
-
1
)
{
string
folder
=
gridRecent
.
Rows
[
(
int
)
selected
]
.
Cells
[
"_path"
]
.
Value
.
ToString
(
)
;
if
(
Tools
.
LaunchExplorer
(
folder
)
==
false
)
{
SetStatus
(
"Error> Directory not found: "
+
folder
)
;
}
}
}
private
void
btnExplorePackageFolder_Click
(
object
sender
,
EventArgs
e
)
{
var
selected
=
lstPackageFolders
.
SelectedIndex
;
//Console.WriteLine(lstPackageFolders.Items[selected].ToString());
if
(
selected
>
-
1
)
{
string
folder
=
lstPackageFolders
.
Items
[
selected
]
.
ToString
(
)
;
if
(
Tools
.
LaunchExplorer
(
folder
)
==
false
)
{
SetStatus
(
"Error> Directory not found: "
+
folder
)
;
}
}
}
private
void
btnAddAssetStoreFolder_Click
(
object
sender
,
EventArgs
e
)
{
var
path
=
Path
.
Combine
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
,
"Unity"
,
"Asset Store-5.x"
)
;
if
(
Directory
.
Exists
(
path
)
==
true
)
{
if
(
lstPackageFolders
.
Items
.
Contains
(
path
)
==
false
)
{
lstPackageFolders
.
Items
.
Add
(
path
)
;
Properties
.
Settings
.
Default
.
packageFolders
.
Add
(
path
)
;
Properties
.
Settings
.
Default
.
Save
(
)
;
}
}
}
private
void
btnAddRegister_Click
(
object
sender
,
EventArgs
e
)
{
Tools
.
AddContextMenuRegistry
(
contextRegRoot
)
;
}
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL