55using System . Windows ;
66using UnityMultiLauncher . ViewModels . Utils ;
77using Microsoft . Win32 ;
8+ using System . Windows . Forms ;
89using MahApps . Metro . Controls ;
910using MahApps . Metro . Controls . Dialogs ;
1011using System . Windows . Controls ;
@@ -14,6 +15,8 @@ namespace UnityMultiLauncher.ViewModels
1415{
1516 public class UnityViewModel : ViewModel
1617 {
18+ protected List < Uri > extraProjectLoctions = new List < Uri > ( ) ;
19+
1720 protected void LaunchUnityVersion ( Uri unityExe )
1821 {
1922
@@ -23,11 +26,10 @@ protected void LaunchUnityVersion(Uri unityExe)
2326
2427 protected void AddUnityVersion ( object param )
2528 {
26-
27- var a = new OpenFileDialog ( ) ;
28- a . Filter = "Executable Files (.exe)|*.exe|All Files (*.*)|*.*" ;
29+ var a = new System . Windows . Forms . OpenFileDialog ( ) ;
30+ a . Filter = "Programs (.exe)|*.exe|All Files (*.*)|*.*" ;
2931 //a.Filter = "exe";
30- if ( ( bool ) a . ShowDialog ( ) )
32+ if ( a . ShowDialog ( ) == DialogResult . OK )
3133 {
3234 ProgramConfig . conf . unityExeLocations . Add ( new Uri ( a . FileName ) ) ;
3335 unityLocations . Add ( new Uri ( a . FileName ) ) ;
@@ -64,8 +66,8 @@ protected void LaunchProject(Uri projectLocation, Uri unityExe = null)
6466 MessageDialogStyle . Affirmative ,
6567 dialogSettings
6668 ) . ContinueWith (
67- // This makes the screen oddly flash (This could either be the thread switch or the animate show affecting it oddly
68- ( a ) => Application . Current . Dispatcher . Invoke ( ( ) => SelectUnityVersionDialog ( projectLocation , new MetroDialogSettings { AnimateShow = false } ) )
69+ // HACK: This makes the screen oddly flash (This could either be the thread switch or the animate show affecting it oddly
70+ ( a ) => System . Windows . Application . Current . Dispatcher . Invoke ( ( ) => SelectUnityVersionDialog ( projectLocation , new MetroDialogSettings { AnimateShow = false } ) )
6971 ) ;
7072 }
7173 if ( unityExe == null )
@@ -75,6 +77,17 @@ protected void LaunchProject(Uri projectLocation, Uri unityExe = null)
7577 }
7678 }
7779
80+ protected void AddUnityProject ( )
81+ {
82+ var a = new FolderBrowserDialog ( ) ;
83+
84+ if ( a . ShowDialog ( ) == DialogResult . OK )
85+ {
86+ extraProjectLoctions . Add ( new Uri ( a . SelectedPath ) ) ;
87+ UpdateProperty ( nameof ( unityProjectLocations ) ) ;
88+ }
89+ }
90+
7891 protected void DuplicateUnityProject ( Uri param )
7992 {
8093 ProgramConfig . conf . unityExeLocations . Remove ( param ) ;
@@ -103,7 +116,6 @@ public IEnumerable<Tuple<Uri, string, string>> unityProjectLocations
103116 {
104117 get
105118 {
106-
107119#if EXAMPLE_VIEW
108120 var rng = new Random ( ) ;
109121 foreach ( var idx in Enumerable . Range ( 0 , 10 ) )
@@ -115,14 +127,27 @@ public IEnumerable<Tuple<Uri, string, string>> unityProjectLocations
115127 yield return Tuple . Create ( testUri , testUri . LocalPath . Substring ( testUri . LocalPath . LastIndexOf ( '\\ ' ) + 1 ) , string . Format ( "{0}.{1}.{2}f{3}" , rngExeVersion . Item1 , rngExeVersion . Item2 , rngExeVersion . Item3 , rngExeVersion . Item4 ) ) ;
116128 }
117129#else
118-
119130 var unityKeys = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Unity Technologies\Unity Editor 5.x\" , false ) ;
120131 var matchingKeys = unityKeys . GetValueNames ( ) . Where ( key => key . Contains ( "RecentlyUsedProjectPaths" ) ) ;
132+
121133 var pos = matchingKeys . Select ( key => new Uri ( Encoding . UTF8 . GetString ( unityKeys . GetValue ( key ) as byte [ ] ) . TrimEnd ( ( char ) 0 ) ) ) ;
122- foreach ( var project in pos )
134+ foreach ( var project in extraProjectLoctions . Concat ( pos ) )
123135 {
124- var a = Util . UnityProjectVersion ( project ) ;
125- yield return Tuple . Create ( project , project . LocalPath . Substring ( project . LocalPath . LastIndexOf ( '\\ ' ) + 1 ) , string . Format ( "{0}.{1}.{2}f{3}" , a . Item1 , a . Item2 , a . Item3 , a . Item4 ) ) ;
136+ if ( System . IO . Directory . Exists ( project . LocalPath ) && System . IO . Directory . Exists ( System . IO . Path . Combine ( project . LocalPath , "Assets" ) ) )
137+ {
138+ var projectVersion = Util . UnityProjectVersion ( project ) ;
139+ if ( projectVersion != null )
140+ yield return Tuple . Create (
141+ project ,
142+ project . LocalPath . Substring ( project . LocalPath . LastIndexOf ( '\\ ' ) + 1 ) ,
143+ string . Format ( "{0}.{1}.{2}f{3}" ,
144+ projectVersion . Item1 ,
145+ projectVersion . Item2 ,
146+ projectVersion . Item3 ,
147+ projectVersion . Item4
148+ )
149+ ) ;
150+ }
126151 }
127152#endif
128153
@@ -169,6 +194,14 @@ public ViewCommand launchUnityProject
169194 }
170195 }
171196
197+ public ViewCommand addUnityProject
198+ {
199+ get
200+ {
201+ return GetProperty ( ) as ViewCommand ?? SetProperty ( new ViewCommand ( param => AddUnityProject ( ) ) ) ;
202+ }
203+ }
204+
172205 public ViewCommand launchUnityProjectWithVersion
173206 {
174207 get
0 commit comments