@@ -14,18 +14,18 @@ namespace UnityMultiLauncher.ViewModels
1414 public class UnityViewModel : ViewModel
1515 {
1616 protected List < Uri > extraProjectLoctions = new List < Uri > ( ) ;
17-
18- protected void LaunchUnityVersion ( Uri unityExe )
17+ #region Methods
18+ protected void LaunchUnityVersion ( Uri unityExe , params string [ ] args )
1919 {
2020
21- System . Diagnostics . Process . Start ( unityExe . LocalPath ) ;
22- UpdateProperty ( nameof ( unityProjectLocations ) ) ;
21+ System . Diagnostics . Process . Start ( unityExe . LocalPath , string . Join ( " " , args ) ) ;
22+ UpdateProperty ( nameof ( UnityProjectLocations ) ) ;
2323 }
2424
2525 protected void SearchUnityVersions ( )
2626 {
2727 var a = new System . Windows . Forms . FolderBrowserDialog ( ) ;
28- if ( a . ShowDialog ( ) == DialogResult . OK )
28+ if ( a . ShowDialog ( ) == DialogResult . OK )
2929 {
3030 var path = new System . IO . DirectoryInfo ( a . SelectedPath ) ;
3131
@@ -35,27 +35,29 @@ protected void SearchUnityVersions()
3535 {
3636 AddUnityExe ( location . FullName ) ;
3737 }
38-
38+
3939 stopwatch . Stop ( ) ;
40-
41-
40+
41+
4242 }
4343 }
4444
45- private void AddUnityExe ( string location )
45+ protected void AddUnityExe ( string location )
4646 {
4747 ProgramConfig . conf . unityExeLocations . Add ( new Uri ( location ) ) ;
48- unityLocations . Add ( new Uri ( location ) ) ;
49- UpdateProperty ( nameof ( unityLocations ) ) ;
48+ UnityLocations . Add ( new Uri ( location ) ) ;
49+ UpdateProperty ( nameof ( UnityLocations ) ) ;
5050 ProgramConfig . conf . Save ( ) ;
5151 }
5252
5353 protected void AddUnityVersion ( object param )
5454 {
5555 //FileSelectDialog();
5656 //return;
57- var a = new System . Windows . Forms . OpenFileDialog ( ) ;
58- a . Filter = "Programs (.exe)|*.exe|All Files (*.*)|*.*" ;
57+ var a = new System . Windows . Forms . OpenFileDialog ( )
58+ {
59+ Filter = "Programs (.exe)|*.exe|All Files (*.*)|*.*"
60+ } ;
5961 //a.Filter = "exe";
6062 if ( a . ShowDialog ( ) == DialogResult . OK )
6163 {
@@ -67,22 +69,23 @@ protected void AddUnityVersion(object param)
6769 protected void RemoveUnityVersion ( object param )
6870 {
6971 ProgramConfig . conf . ValidUnityExeLocations . Remove ( param as Uri ) ;
70- unityLocations . Remove ( param as Uri ) ;
72+ UnityLocations . Remove ( param as Uri ) ;
7173 ProgramConfig . conf . Save ( ) ;
72- UpdateProperty ( nameof ( unityLocations ) ) ;
74+ UpdateProperty ( nameof ( UnityLocations ) ) ;
7375 }
7476
7577 protected void LaunchProject ( Uri projectLocation , Uri unityExe = null )
7678 {
7779 var projectVersion = Util . UnityProjectVersion ( projectLocation ) ;
78- if ( unityExe == null )
80+ if ( unityExe == null )
7981 {
8082 unityExe = Util . GetUnityExecutableFromVersion ( projectVersion ) ;
8183 }
8284 if ( unityExe != null )
8385 {
84- System . Diagnostics . Process . Start ( unityExe . LocalPath , $ "-projectpath \" { projectLocation . LocalPath } \" " ) ;
85- UpdateProperty ( nameof ( unityProjectLocations ) ) ;
86+ LaunchUnityVersion ( unityExe , "-projectpath" , $ "\" { projectLocation . LocalPath } \" ") ;
87+ //System.Diagnostics.Process.Start(unityExe.LocalPath, $"-projectpath \"{}\"" );
88+ UpdateProperty ( nameof ( UnityProjectLocations ) ) ;
8689 }
8790 else
8891 {
@@ -94,51 +97,62 @@ protected void LaunchProject(Uri projectLocation, Uri unityExe = null)
9497 dialogSettings
9598 ) . ContinueWith (
9699 // HACK: This makes the screen oddly flash (This could either be the thread switch or the animate show affecting it oddly
97- ( a ) => System . Windows . Application . Current . Dispatcher . Invoke ( ( ) => SelectUnityVersionDialog ( projectLocation , new MetroDialogSettings { AnimateShow = false } ) )
100+ ( a ) => System . Windows . Application . Current . Dispatcher . Invoke ( ( ) => SelectUnityVersionDialog ( projectLocation , new MetroDialogSettings { AnimateShow = false } ) )
98101 ) ;
99102 }
100103 if ( unityExe == null )
101104 {
102- selectedVersion = null ;
103- selectedProject = null ;
105+ SelectedVersion = null ;
106+ SelectedProject = null ;
104107 }
105108 }
106109
107110 protected void AddUnityProject ( )
108111 {
109112 var a = new FolderBrowserDialog ( ) ;
110-
113+
111114 if ( a . ShowDialog ( ) == DialogResult . OK )
112115 {
113116 extraProjectLoctions . Add ( new Uri ( a . SelectedPath ) ) ;
114- UpdateProperty ( nameof ( unityProjectLocations ) ) ;
117+ UpdateProperty ( nameof ( UnityProjectLocations ) ) ;
115118 }
116119 }
117120
118121 protected void DuplicateUnityProject ( Uri param )
119122 {
120123 ProgramConfig . conf . ValidUnityExeLocations . Remove ( param ) ;
121- unityLocations . Remove ( param ) ;
124+ UnityLocations . Remove ( param ) ;
122125 ProgramConfig . conf . Save ( ) ;
123- UpdateProperty ( nameof ( unityLocations ) ) ;
126+ UpdateProperty ( nameof ( UnityLocations ) ) ;
124127 }
125128
126129 protected void SelectUnityVersionDialog ( Uri project , MetroDialogSettings dialogSettings = null )
127130 {
128131 var cd = MainWindow . cwin . TryFindResource ( "CustomLaunchDialog" ) ;
129132 MainWindow . cwin . ShowMetroDialogAsync ( cd as CustomDialog , dialogSettings ) ;
130- selectedProject = project ;
131- selectedVersion = Util . GetUnityExecutableFromVersion ( Util . UnityProjectVersion ( project ) ) ;
133+ SelectedProject = project ;
134+ SelectedVersion = Util . GetUnityExecutableFromVersion ( Util . UnityProjectVersion ( project ) ) ;
132135 }
133136
134137 protected void FileSelectDialog ( )
135138 {
136139 var cd = MainWindow . cwin . TryFindResource ( "FileBrowser" ) ;
137140 MainWindow . cwin . ShowMetroDialogAsync ( cd as CustomDialog ) ;
138-
141+
139142 }
140143
141- public ObservableCollection < Uri > unityLocations
144+ public void DumpUnityExeInfoFunc ( object uri )
145+ {
146+ Util . DumpUnityVersionInfo ( uri as Uri ) ;
147+ }
148+
149+ public void OpenUnityProjectLocation ( object param )
150+ {
151+ System . Diagnostics . Process . Start ( ( param as Uri ) . LocalPath ) ;
152+ }
153+ #endregion
154+ #region Properties
155+ public ObservableCollection < Uri > UnityLocations
142156 {
143157 get
144158 {
@@ -153,7 +167,7 @@ public System.ComponentModel.ICollectionView UnityLocationsSorted
153167 ListCollectionView prop = GetProperty ( ) as ListCollectionView ;
154168 if ( prop == null )
155169 {
156- var p = CollectionViewSource . GetDefaultView ( ( IList < Uri > ) unityLocations ) as ListCollectionView ;
170+ var p = CollectionViewSource . GetDefaultView ( ( IList < Uri > ) UnityLocations ) as ListCollectionView ;
157171 prop = SetProperty ( p as ListCollectionView ) ;
158172 prop . CustomSort = Comparer < Uri > . Create (
159173 ( A , B ) => Util . GetUnityVersionFromExecutable ( B ) . CompareTo ( Util . GetUnityVersionFromExecutable ( A ) )
@@ -166,7 +180,7 @@ public System.ComponentModel.ICollectionView UnityLocationsSorted
166180 }
167181 }
168182
169- public IEnumerable < Tuple < Uri , string , string > > unityProjectLocations
183+ public IEnumerable < Tuple < Uri , string , string > > UnityProjectLocations
170184 {
171185 get
172186 {
@@ -182,14 +196,14 @@ public IEnumerable<Tuple<Uri, string, string>> unityProjectLocations
182196 }
183197#else
184198 var unityKeys = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Unity Technologies\Unity Editor 5.x\" , false ) ;
185- if ( unityKeys == null )
186- {
187- yield break ;
188- }
199+ if ( unityKeys == null )
200+ {
201+ yield break ;
202+ }
189203 var matchingKeys = unityKeys . GetValueNames ( ) . Where ( key => key . Contains ( "RecentlyUsedProjectPaths" ) ) ;
190204
191205 var pos = matchingKeys . Select ( key => new Uri ( Encoding . UTF8 . GetString ( unityKeys . GetValue ( key ) as byte [ ] ) . TrimEnd ( ( char ) 0 ) ) ) ;
192- foreach ( var project in extraProjectLoctions . Concat ( pos ) )
206+ foreach ( var project in extraProjectLoctions . Concat ( pos ) )
193207 {
194208 if ( System . IO . Directory . Exists ( project . LocalPath ) && System . IO . Directory . Exists ( System . IO . Path . Combine ( project . LocalPath , "Assets" ) ) )
195209 {
@@ -207,7 +221,7 @@ public IEnumerable<Tuple<Uri, string, string>> unityProjectLocations
207221 }
208222 }
209223
210- public Uri selectedProject
224+ public Uri SelectedProject
211225 {
212226 get
213227 {
@@ -219,7 +233,7 @@ public Uri selectedProject
219233 }
220234 }
221235
222- public Uri selectedVersion
236+ public Uri SelectedVersion
223237 {
224238 get
225239 {
@@ -233,108 +247,108 @@ public Uri selectedVersion
233247
234248 public bool SupportUnitySubversion { get ; set ; }
235249
236- public ViewCommand launchUnity
250+ public bool UseUnitySubVersion
251+ {
252+ get
253+ {
254+ return ProgramConfig . conf . ShouldUseUnitySubVersion ;
255+ }
256+ set
257+ {
258+ ProgramConfig . conf . ShouldUseUnitySubVersion = value ;
259+ ProgramConfig . conf . Save ( ) ;
260+ UpdateProperty ( ) ;
261+ }
262+ }
263+ #endregion
264+ #region Commands
265+ public ViewCommand CmdLaunchUnity
237266 {
238267 get
239268 {
240269 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => LaunchUnityVersion ( param as Uri ) ) ) ;
241270 }
242271 }
243272
244- public ViewCommand launchUnityProject
273+ public ViewCommand CmdLaunchUnityProject
245274 {
246275 get
247276 {
248277 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => LaunchProject ( param as Uri ) ) ) ;
249278 }
250279 }
251280
252- public ViewCommand addUnityProject
281+ public ViewCommand CmdAddUnityProject
253282 {
254283 get
255284 {
256285 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => AddUnityProject ( ) ) ) ;
257286 }
258287 }
259288
260- public ViewCommand launchUnityProjectWithVersion
289+ public ViewCommand CmdLaunchUnityProjectWithVersion
261290 {
262291 get
263292 {
264- return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => { LaunchProject ( selectedProject , selectedVersion ) ; UtilViewModel . HideDialogFunc ( param ) ; } ) ) ;
293+ return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => { LaunchProject ( SelectedProject , SelectedVersion ) ; UtilViewModel . HideDialogFunc ( param ) ; } ) ) ;
265294 }
266295 }
267296
268- public ViewCommand addUnityVersion
297+ public ViewCommand CmdAddUnityVersion
269298 {
270299 get
271300 {
272301 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => SearchUnityVersions ( ) ) ) ;
273302 }
274303 }
275304
276- public ViewCommand removeUnityVersion
305+ public ViewCommand CmdRemoveUnityVersion
277306 {
278307 get
279308 {
280309 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => RemoveUnityVersion ( param ) ) ) ;
281310 }
282311 }
283312
284- public ViewCommand duplicateUnityProject
313+ public ViewCommand CmdDuplicateUnityProject
285314 {
286315 get
287316 {
288317 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => DuplicateUnityProject ( param as Uri ) ) ) ;
289318 }
290319 }
291320
292- public ViewCommand unitySelectVersionDialog
321+ public ViewCommand CmdUnitySelectVersionDialog
293322 {
294323 get
295324 {
296325 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => SelectUnityVersionDialog ( param as Uri ) ) ) ;
297326 }
298327 }
299328
300- public bool UseUnitySubVersion
329+ public ViewCommand CmdDumpUnityExeInfo
301330 {
302331 get
303332 {
304- return ProgramConfig . conf . ShouldUseUnitySubVersion ;
305- }
306- set
307- {
308- ProgramConfig . conf . ShouldUseUnitySubVersion = value ;
309- ProgramConfig . conf . Save ( ) ;
310- UpdateProperty ( ) ;
333+ return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( DumpUnityExeInfoFunc ) ) ;
311334 }
312335 }
313336
314- public void DumpUnityExeInfoFunc ( object uri )
315- {
316- Util . DumpUnityVersionInfo ( uri as Uri ) ;
317- }
318-
319- public ViewCommand DumpUnityExeInfo
337+ public ViewCommand CmdCreateTemporaryProject
320338 {
321339 get
322340 {
323- return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( DumpUnityExeInfoFunc ) ) ;
341+ return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( obj => LaunchUnityVersion ( ( Uri ) obj , "-temporary" ) ) ) ;
324342 }
325343 }
326344
327- public void OpenUnityProjectLocation ( object param )
328- {
329- System . Diagnostics . Process . Start ( ( param as Uri ) . LocalPath ) ;
330- }
331-
332- public ViewCommand OpenUnityProjectLocaitonCommand
345+ public ViewCommand CmdOpenUnityProjectLocaiton
333346 {
334347 get
335348 {
336349 return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( OpenUnityProjectLocation ) ) ;
337350 }
338- }
351+ }
352+ #endregion
339353 }
340354}
0 commit comments