@@ -15,7 +15,7 @@ namespace UnityLauncher
1515 public partial class Form1 : Form
1616 {
1717 // 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 > ( ) ;
1919
2020 const int settingsTabIndex = 3 ;
2121 const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
@@ -296,8 +296,8 @@ void LaunchProject(string pathArg = null, bool openProject = true)
296296 var version = GetProjectVersion ( pathArg ) ;
297297 //Console.WriteLine("Detected project version: " + version);
298298
299- bool installed = HaveExactVersionInstalled ( version ) ;
300- if ( installed == true )
299+ bool haveExactVersion = HaveExactVersionInstalled ( version ) ;
300+ if ( haveExactVersion == true )
301301 {
302302 //Console.WriteLine("Opening unity version " + version);
303303 SetStatus ( "Launching project in unity " + version ) ;
@@ -370,8 +370,15 @@ string GetDownloadUrlForUnityVersion(string releaseUrl)
370370 string html = client . DownloadString ( releaseUrl ) ;
371371 Regex regex = new Regex ( @"(http).+(UnityDownloadAssistant)+[^\s*]*(.exe)" ) ;
372372 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+ }
375382 }
376383 return url ;
377384 }
@@ -825,6 +832,76 @@ private void btnRunUnityOnly_Click(object sender, EventArgs e)
825832 LaunchSelectedProject ( openProject : false ) ;
826833 }
827834
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+ }
829906 }
830907}
0 commit comments