@@ -16,13 +16,19 @@ public partial class Form1 : Form
16
16
{
17
17
private string pathArg = "" ;
18
18
19
+ Dictionary < string , string > unityList = new Dictionary < string , string > ( ) ;
20
+
21
+
19
22
public Form1 ( )
20
23
{
21
24
InitializeComponent ( ) ;
22
25
}
23
26
24
27
private void Form1_Load ( object sender , EventArgs e )
25
28
{
29
+ // force scan
30
+ btn_setinstallfolder_Click ( null , null ) ;
31
+
26
32
// TODO: setup window to scan for unity installations (give parent folder)
27
33
28
34
// check if any arguments (that means, it should parse something)
@@ -61,11 +67,30 @@ private void Form1_Load(object sender, EventArgs e)
61
67
var version = GetProjectVersion ( versionPath ) ;
62
68
Console . WriteLine ( "Detected project version: " + version ) ;
63
69
64
- bool installed = CheckInstalled ( "Unity " + version ) ;
70
+ bool installed = OpenWithSuitableVersion ( version ) ;
65
71
if ( installed == true )
66
72
{
67
73
// TODO: open?
68
74
Console . WriteLine ( "Opening unity version " + version ) ;
75
+
76
+ try
77
+ {
78
+ Process myProcess = new Process ( ) ;
79
+
80
+ var cmd = "\" " + unityList [ version ] + "\" " ;
81
+ var pars = " -projectPath " + "\" " + pathArg + "\" " ;
82
+
83
+ Console . WriteLine ( "execute: " + cmd ) ;
84
+
85
+ myProcess . StartInfo . FileName = cmd ;
86
+ myProcess . StartInfo . Arguments = pars ;
87
+ myProcess . Start ( ) ;
88
+ }
89
+ catch ( Exception ex )
90
+ {
91
+ Console . WriteLine ( ex ) ;
92
+ }
93
+
69
94
}
70
95
else
71
96
{
@@ -99,6 +124,17 @@ private void Form1_Load(object sender, EventArgs e)
99
124
100
125
}
101
126
127
+ bool OpenWithSuitableVersion ( string version )
128
+ {
129
+ // check if got exact hit
130
+ Console . WriteLine ( "checking: '" + version + "'" ) ;
131
+
132
+ var installedExact = unityList . ContainsKey ( version ) ;
133
+ Console . WriteLine ( "have exact:" + installedExact ) ;
134
+
135
+ return installedExact ;
136
+ }
137
+
102
138
103
139
// read and parse project settings file
104
140
string GetProjectVersion ( string path )
@@ -134,51 +170,14 @@ string GetProjectVersion(string path)
134
170
}
135
171
136
172
137
- // check installed apps from uninstall list in registry https://stackoverflow.com/a/16392220/5452781
138
- // but unity doesnt write there
139
- public static bool CheckInstalled ( string appName )
140
- {
141
- string displayName ;
142
-
143
- string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ;
144
- RegistryKey key = Registry . LocalMachine . OpenSubKey ( registryKey ) ;
145
- if ( key != null )
146
- {
147
- foreach ( RegistryKey subkey in key . GetSubKeyNames ( ) . Select ( keyName => key . OpenSubKey ( keyName ) ) )
148
- {
149
- displayName = subkey . GetValue ( "DisplayName" ) as string ;
150
- if ( displayName != null && displayName . Contains ( appName ) )
151
- {
152
- return true ;
153
- }
154
- }
155
- key . Close ( ) ;
156
- }
157
-
158
- registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ;
159
- key = Registry . LocalMachine . OpenSubKey ( registryKey ) ;
160
- if ( key != null )
161
- {
162
- foreach ( RegistryKey subkey in key . GetSubKeyNames ( ) . Select ( keyName => key . OpenSubKey ( keyName ) ) )
163
- {
164
- displayName = subkey . GetValue ( "DisplayName" ) as string ;
165
- if ( displayName != null && displayName . Contains ( appName ) )
166
- {
167
- return true ;
168
- }
169
- }
170
- key . Close ( ) ;
171
- }
172
- return false ;
173
- }
174
-
175
173
// set basefolder of all unity installations
176
174
private void btn_setinstallfolder_Click ( object sender , EventArgs e )
177
175
{
178
- Dictionary < string , string > unityList = new Dictionary < string , string > ( ) ;
176
+ //var d = folderBrowserDialog1.ShowDialog();
177
+ //var root = folderBrowserDialog1.SelectedPath;
179
178
180
- var d = folderBrowserDialog1 . ShowDialog ( ) ;
181
- var root = folderBrowserDialog1 . SelectedPath ;
179
+ // override
180
+ var root = "D:/Program Files/" ;
182
181
183
182
if ( String . IsNullOrWhiteSpace ( root ) == false )
184
183
{
@@ -190,10 +189,11 @@ private void btn_setinstallfolder_Click(object sender, EventArgs e)
190
189
if ( File . Exists ( uninstallExe ) )
191
190
{
192
191
var unityExe = Path . Combine ( directories [ i ] , "Editor" , "Unity.exe" ) ;
193
- var unityVersion = GetFileVersion ( uninstallExe ) ;
192
+ var unityVersion = GetFileVersion ( uninstallExe ) . Replace ( "Unity" , "" ) . Trim ( ) ;
194
193
// TODO: check if exists, warn
195
194
unityList . Add ( unityVersion , unityExe ) ;
196
195
lst_unitys . Items . Add ( unityVersion + " (" + unityExe + ")" ) ;
196
+ //Console.WriteLine(unityVersion);
197
197
} // have uninstaller
198
198
} // got folders
199
199
} // didnt select anything
0 commit comments