@@ -22,7 +22,13 @@ public partial class MainWindow : Window
2222 bool _isUpgradeInstall = false ;
2323 int _currentPage = 0 ;
2424 bool _createDesktopShortcuts = true ;
25-
25+ string _currentLauncherKitPath = String . Empty ;
26+ string [ ] _launcherkitExecutables = new string [ ]
27+ {
28+ "Spore ModAPI Easy Installer.exe" ,
29+ "Spore ModAPI Easy Uninstaller.exe" ,
30+ "Spore ModAPI Launcher.exe"
31+ } ;
2632 CircleEase _ease = new CircleEase ( )
2733 {
2834 EasingMode = EasingMode . EaseOut
@@ -49,6 +55,8 @@ public MainWindow()
4955 if ( RootGrid . Children . IndexOf ( p ) != _currentPage )
5056 p . Visibility = Visibility . Collapsed ;
5157 }
58+
59+ FindExistingLauncherKit ( ) ;
5260 }
5361
5462 private void CancelButton_Click ( object sender , RoutedEventArgs e )
@@ -67,6 +75,30 @@ private void NextButton_Click(object sender, RoutedEventArgs e)
6775 BeginInstallation ( ) ;
6876 }
6977
78+ private void FindExistingLauncherKit ( )
79+ {
80+ try
81+ {
82+ string pathInfo = Environment . ExpandEnvironmentVariables ( @"%appdata%\Spore ModAPI Launcher\path.info" ) ;
83+ string launcherKitPath ;
84+ if ( File . Exists ( pathInfo ) )
85+ {
86+ launcherKitPath = File . ReadAllText ( pathInfo ) ;
87+ if ( VerifyPath ( launcherKitPath , true ) )
88+ {
89+ _currentLauncherKitPath = launcherKitPath ;
90+
91+ // when found, redirect directly to the upgrade page
92+ UpgradeInstallButton_Click ( this , null ) ;
93+ }
94+ }
95+ }
96+ catch ( Exception )
97+ {
98+ // do nothing
99+ }
100+ }
101+
70102 private void UnzipLauncherKit ( string path )
71103 {
72104 using ( MemoryStream unmStream = new MemoryStream ( ModApi . InterimSetup . Properties . Resources . ModApiUpdate ) )
@@ -173,7 +205,7 @@ private void UpgradeInstallButton_Click(object sender, RoutedEventArgs e)
173205 _pathAcceptableText = "This path is valid. An existing ModAPI Launcher was found." ;
174206 _pathNotAcceptableText = "This path is not valid. No existing ModAPI Launcher was found to upgrade." ;
175207 PageOneInstructionsTextBlock . Text = _pageOneInstructionsUpgradeInstallText ;
176- PathTextBox . Text = string . Empty ;
208+ PathTextBox . Text = _currentLauncherKitPath ;
177209 CyclePage ( 1 ) ;
178210 }
179211
@@ -271,16 +303,14 @@ private void PathBrowseButton_Click(object sender, RoutedEventArgs e)
271303 OpenFileDialog dialog = new OpenFileDialog ( )
272304 {
273305 Title = "Select the path to your existing Spore ModAPI Launcher." ,
274- Filter = "Spore ModAPI Executable (*.exe)|*.exe" ,
306+ Filter = "Spore ModAPI Executable (*.exe)|" + String . Join ( ";" , _launcherkitExecutables ) ,
275307 FilterIndex = 0 ,
276308 CheckPathExists = true
277309 } ;
278310
279311 if ( dialog . ShowDialog ( ) == System . Windows . Forms . DialogResult . OK )
280312 {
281- string path = dialog . FileName ;
282- bool verified = VerifyPath ( path ) ;
283- PathTextBox . Text = Environment . ExpandEnvironmentVariables ( path ) ;
313+ PathTextBox . Text = dialog . FileName ;
284314 }
285315 }
286316 else
@@ -296,23 +326,45 @@ private void PathBrowseButton_Click(object sender, RoutedEventArgs e)
296326
297327 if ( dialog . ShowDialog ( ) == System . Windows . Forms . DialogResult . OK )
298328 {
299- string path = dialog . SelectedPath ;
300- bool verified = VerifyPath ( path ) ;
301- string expandedPath = Environment . ExpandEnvironmentVariables ( path ) ;
302- if ( ! expandedPath . ToLowerInvariant ( ) . EndsWith ( _pathSuffix . ToLowerInvariant ( ) ) )
303- expandedPath = Path . Combine ( expandedPath , _pathSuffix ) ;
304-
305- PathTextBox . Text = expandedPath ;
329+ PathTextBox . Text = dialog . SelectedPath ;
306330 }
307331 }
308332 }
309333
310- bool VerifyPath ( string path )
334+ bool VerifyPath ( string path , bool forceUpgradeCheck = false )
311335 {
312- if ( _isUpgradeInstall )
336+ if ( forceUpgradeCheck || _isUpgradeInstall )
313337 {
314- string fileName = Path . GetFileName ( path ) . ToLowerInvariant ( ) ;
315- return File . Exists ( path ) && fileName . StartsWith ( "spore modapi" ) && fileName . EndsWith ( ".exe" ) ;
338+ try
339+ {
340+ if ( File . Exists ( path ) )
341+ {
342+ path = Path . GetFileName ( path ) . ToLower ( ) ;
343+ foreach ( var executable in _launcherkitExecutables )
344+ {
345+ if ( path == executable . ToLower ( ) )
346+ {
347+ return true ;
348+ }
349+ }
350+ }
351+ else
352+ {
353+ foreach ( var executable in _launcherkitExecutables )
354+ {
355+ if ( File . Exists ( Path . Combine ( path , executable ) ) )
356+ {
357+ return true ;
358+ }
359+ }
360+ }
361+ }
362+ catch ( Exception )
363+ {
364+ // do nothing
365+ }
366+
367+ return false ;
316368 }
317369 else
318370 {
0 commit comments