@@ -15,7 +15,7 @@ namespace UnityLauncher
15
15
public partial class Form1 : Form
16
16
{
17
17
// version,exe path (example: 5.6.1f1,c:\prog\unity561\editor\unity.exe)
18
- Dictionary < string , string > unityList = new Dictionary < string , string > ( ) ;
18
+ public static Dictionary < string , string > unityList = new Dictionary < string , string > ( ) ;
19
19
20
20
const int settingsTabIndex = 3 ;
21
21
const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
@@ -296,8 +296,8 @@ void LaunchProject(string pathArg = null, bool openProject = true)
296
296
var version = GetProjectVersion ( pathArg ) ;
297
297
//Console.WriteLine("Detected project version: " + version);
298
298
299
- bool installed = HaveExactVersionInstalled ( version ) ;
300
- if ( installed == true )
299
+ bool haveExactVersion = HaveExactVersionInstalled ( version ) ;
300
+ if ( haveExactVersion == true )
301
301
{
302
302
//Console.WriteLine("Opening unity version " + version);
303
303
SetStatus ( "Launching project in unity " + version ) ;
@@ -370,8 +370,15 @@ string GetDownloadUrlForUnityVersion(string releaseUrl)
370
370
string html = client . DownloadString ( releaseUrl ) ;
371
371
Regex regex = new Regex ( @"(http).+(UnityDownloadAssistant)+[^\s*]*(.exe)" ) ;
372
372
Match match = regex . Match ( html ) ;
373
- url = match . Groups [ 0 ] . Captures [ 0 ] . Value ;
374
- Console . WriteLine ( url ) ;
373
+ if ( match . Success == true )
374
+ {
375
+ url = match . Groups [ 0 ] . Captures [ 0 ] . Value ;
376
+ // Console.WriteLine(url);
377
+ }
378
+ else
379
+ {
380
+ SetStatus ( "Cannot find UnityDownloadAssistant.exe for this version.." ) ;
381
+ }
375
382
}
376
383
return url ;
377
384
}
@@ -825,6 +832,76 @@ private void btnRunUnityOnly_Click(object sender, EventArgs e)
825
832
LaunchSelectedProject ( openProject : false ) ;
826
833
}
827
834
828
- #endregion
835
+ private void btnUpgradeProject_Click ( object sender , EventArgs e )
836
+ {
837
+ UpgradeProject ( ) ;
838
+ }
839
+ #endregion UI events
840
+
841
+
842
+ public static string FindNearestVersion ( string version , List < string > allAvailable )
843
+ {
844
+ if ( version . Contains ( "2017" ) )
845
+ {
846
+ return FindNearestVersionFromSimilarVersions ( version , allAvailable . Where ( x => x . Contains ( "2017" ) ) ) ;
847
+ }
848
+ return FindNearestVersionFromSimilarVersions ( version , allAvailable . Where ( x => ! x . Contains ( "2017" ) ) ) ;
849
+ }
850
+
851
+ private static string FindNearestVersionFromSimilarVersions ( string version , IEnumerable < string > allAvailable )
852
+ {
853
+ Dictionary < string , string > stripped = new Dictionary < string , string > ( ) ;
854
+ var enumerable = allAvailable as string [ ] ?? allAvailable . ToArray ( ) ;
855
+
856
+ foreach ( var t in enumerable )
857
+ {
858
+ stripped . Add ( new Regex ( "[a-zA-z]" ) . Replace ( t , "." ) , t ) ;
859
+ }
860
+
861
+ var comparableVersion = new Regex ( "[a-zA-z]" ) . Replace ( version , "." ) ;
862
+ if ( ! stripped . ContainsKey ( comparableVersion ) )
863
+ {
864
+ stripped . Add ( comparableVersion , version ) ;
865
+ Console . WriteLine ( comparableVersion + " : " + version ) ;
866
+ }
867
+
868
+ var comparables = stripped . Keys . OrderBy ( x => x ) . ToList ( ) ;
869
+ var actualIndex = comparables . IndexOf ( comparableVersion ) ;
870
+
871
+ if ( actualIndex < stripped . Count ) return stripped [ comparables [ actualIndex + 1 ] ] ;
872
+ return null ;
873
+ }
874
+
875
+ void UpgradeProject ( )
876
+ {
877
+ var selected = gridRecent . CurrentCell . RowIndex ;
878
+ if ( selected > - 1 )
879
+ {
880
+ SetStatus ( "Upgrading project.." ) ;
881
+
882
+ var path = gridRecent . Rows [ selected ] . Cells [ "_path" ] . Value . ToString ( ) ;
883
+ var currentVersion = GetProjectVersion ( path ) ;
884
+
885
+ bool haveExactVersion = HaveExactVersionInstalled ( currentVersion ) ;
886
+ if ( haveExactVersion == true )
887
+ {
888
+ // you already have same version, are you sure?
889
+ }
890
+
891
+ Form2 upgradeDialog = new Form2 ( ) ;
892
+ Form2 . currentVersion = currentVersion ;
893
+
894
+ if ( upgradeDialog . ShowDialog ( this ) == DialogResult . OK )
895
+ {
896
+ // yes, upgrade
897
+ }
898
+ else
899
+ {
900
+ // cancelled
901
+ }
902
+ upgradeDialog . Close ( ) ;
903
+
904
+ }
905
+ }
829
906
}
830
907
}
0 commit comments