@@ -86,30 +86,10 @@ static void Main()
8686 LauncherSettings . Load ( ) ;
8787 ModList . Load ( ) ;
8888
89- /*Application.ApplicationExit += (sneder, args) => {
90- ModList.Save();
91- Thread thread = new Thread(() =>
92- {
93- var win = ModInstalledWindow.GetDialog(outcome, Strings.InstallationCompleted);
94- win.Closed += (snedre, rags) => Process.GetCurrentProcess().Kill();
95- win.Show();
96- Application.Run();
97- });
98- thread.SetApartmentState(ApartmentState.STA);
99- thread.Start();
100- thread.Join();
101- };*/
102-
103-
104-
105-
106-
107-
10889 var cmdArgs = Environment . GetCommandLineArgs ( ) ;
10990 if ( ( cmdArgs . Length == 4 ) && bool . TryParse ( cmdArgs [ 2 ] , out bool configResult ) && bool . TryParse ( cmdArgs [ 3 ] , out bool uninstall ) )
11091 {
11192 string modName = cmdArgs [ 1 ] ;
112- //MessageBox.Show(modName, "modName");
11393
11494 if ( configResult )
11595 {
@@ -259,10 +239,6 @@ static FileType GetFileType(string fileName)
259239 // default to GA Data
260240 return FileType . Package ;
261241 }
262- /*else if (fileName.EndsWith(".exe"))
263- {
264- return FileType.EXE;
265- }*/
266242 else if ( fileName . EndsWith ( ".dll" ) )
267243 {
268244 return FileType . DLL ;
@@ -491,18 +467,6 @@ private static ResultType ExtractSporemodZip(string inputFile, ModConfiguration
491467 return ResultType . Success ;
492468 }
493469
494- private static string ConvertToArgument ( string path )
495- {
496- if ( path == null )
497- {
498- return "null" ;
499- }
500- else
501- {
502- return "\" " + path + "\" " ;
503- }
504- }
505-
506470 [ DllImport ( "user32.dll" , ExactSpelling = true ) ]
507471 static extern bool IsWindow ( IntPtr hWnd ) ;
508472
@@ -543,44 +507,22 @@ static ResultType TryExecuteInstaller(string inputFile, string modName)
543507 return ResultType . ModNotInstalled ;
544508 }
545509
546- /*XmlDocument Document = new XmlDocument();
547- archive.GetEntry("ModInfo.xml").Open();
548- modName*/
549510 string modPath = Path . Combine ( Directory . GetParent ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) . ToString ( ) , "ModConfigs" , modName ) ;
550511 if ( Directory . Exists ( modPath ) )
551512 DeleteFolder ( modPath ) ;
552513
553514 Directory . CreateDirectory ( modPath ) ;
554515
555- string revealInstallerInfoPath = Path . Combine ( Directory . GetParent ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) . ToString ( ) , "RevealXmlInstaller.info" ) ;
556- if ( File . Exists ( revealInstallerInfoPath ) )
557- File . Delete ( revealInstallerInfoPath ) ;
558516
559- /*XmlInstallerWindow win = */
560- //bool installCancelled = false;
561517 Thread installerThread = GetXmlInstaller ( modName , false , false , true , out XmlInstallerWindow win ) ;
562- //_showXmlInstaller = true;//Thread showThread = new Thread(() => xmlWin.Show());// xmlWin.Dispatcher.Invoke(new Action(() => xmlWin.Show())));
563- /*showThread.SetApartmentState(ApartmentState.STA);
564- showThread.Start();
565- showThread.Join();*/
566- //if (archive.GetEntry("Theme.xaml"))
518+
567519 foreach ( var fileEntry in archive . Entries )
568520 {
569521 fileEntry . ExtractToFile ( Path . Combine ( modPath , fileEntry . Name ) , true ) ;
570- /*if (Path.GetFileName(fileEntry.Name).ToLowerInvariant() == "theme.xaml")
571- File.WriteAllText(themeInfoPath, string.Empty);*/
572522 }
573- //win.InstallCancelled += (sneder, args) => installCancelled = true;
574- File . WriteAllText ( revealInstallerInfoPath , string . Empty ) ;
575- /*if (win != null)
576- win.Closed += (sneder, args) =>
577- {installCancelled = win.cancelled;
578- installerThread.Abort();
579- };
580- else
581- MessageBox.Show("win == null");*/
582- //RevealXmlInstaller = true; //Thread revealThread = new Thread(() => xmlWin.RevealInstaller()); //xmlWin.Dispatcher.Invoke(new Action(() => xmlWin.RevealInstaller())));
583- //revealThread.SetApartmentState(ApartmentState.STA); revealThread.Start(); xmlWin.Closed += (sneder, args) => System.Windows.Application.Current.Shutdown(); revealThread.Join();
523+
524+ win . SignalRevealInstaller ( ) ;
525+
584526 installerThread . Join ( ) ;
585527
586528 if ( ! XmlInstallerCancellation . Cancellation [ modName . Trim ( '"' ) ] )
@@ -591,61 +533,11 @@ static ResultType TryExecuteInstaller(string inputFile, string modName)
591533 else if ( entry != null )
592534 {
593535 return ResultType . UnsupportedFile ;
594- /*tempFile = Path.GetTempFileName();
595- try
596- {
597- entry.ExtractToFile(tempFile, true);
598- }
599- catch (Exception ex)
600- {
601- // delete the temp file and propagate the exception
602- File.Delete(tempFile);
603- throw ex;
604- }
605-
606- string validInstaller = "!!!!!2017_DI_9_r_Beta2-1-6";
607- bool modNameValid = modName == validInstaller;
608- bool modInstallerSizeValid = new FileInfo(tempFile).Length == 13023232;
609- //MessageBox.Show("modName: " + modName + "\ninputFile: " + inputFile + "\n\nmodNameValid: " + modNameValid + "\nmodInstallerSizeValid: " + modInstallerSizeValid);
610-
611- if (modNameValid && modInstallerSizeValid)
612- {
613- var startInfo = new ProcessStartInfo()
614- {
615- UseShellExecute = false, // we need this to execute a temp file
616- FileName = tempFile,
617- Arguments =
618- ConvertToArgument(inputFile) + " " +
619- ConvertToArgument(GetOutputPath(FileType.DLL)) + " " +
620- ConvertToArgument(GetOutputPath(FileType.Package)) + " " +
621- ConvertToArgument(GetOutputPath(FileType.Spore_Package))
622- };
623-
624- var process = Process.Start(startInfo);
625- process.WaitForExit();
626-
627- File.Delete(tempFile);
628-
629- return ResultType.InstallerExecuted;
630- }
631- else
632- {
633- MessageBox.Show("For security reasons, EXE custom installers have been disabled. If you believe this mod is safe, inform its developer of the issue, and tell them to look into \"XML Custom Installers\".");
634- return ResultType.UnsupportedFile;
635- }*/
636536 }
637537 else
638538 {
639539 return ResultType . Success ;
640540 }
641-
642- /*
643- // there's no exe custom installer, check for an xml one
644- if (xmlEntry == null)
645- {
646- // there's no custom installer of any kind
647- return ResultType.Success;
648- }*/
649541 }
650542 }
651543
@@ -660,30 +552,27 @@ public static void DeleteFolder(string path)
660552 Directory . Delete ( path ) ;
661553 }
662554
663- //static bool _showXmlInstaller = false;
664- public static bool RevealXmlInstaller = false ;
665-
666- //[STAThread]
667555 static Thread GetXmlInstaller ( string modName , bool configure , bool uninstall , bool show , out XmlInstallerWindow win )
668556 {
669557 XmlInstallerWindow xmlWin = null ;
670558 Thread thread = new Thread ( ( ) =>
671559 {
672- //MessageBox.Show(modName, "modName");
673560 xmlWin = new XmlInstallerWindow ( modName , configure , uninstall ) ;
674- if ( show ) // && (!xmlWin.IsVisible))
561+ if ( show )
675562 {
676- xmlWin . ShowDialog ( ) ; //.Show();
677- //Application.Run(xmlWin);
678- //Application.Run();
563+ xmlWin . ShowDialog ( ) ;
679564 }
680565 } ) ;
681566 thread . SetApartmentState ( ApartmentState . STA ) ;
682567 thread . Start ( ) ;
683- //thread.Join();
568+
569+ // wait until xmlWin has been set
570+ while ( xmlWin == null )
571+ {
572+ Thread . Sleep ( 10 ) ;
573+ }
574+
684575 win = xmlWin ;
685-
686-
687576 return thread ;
688577 }
689578
@@ -831,7 +720,6 @@ static void ShowProgressDialog()
831720 } ) ;
832721 thread . SetApartmentState ( ApartmentState . STA ) ;
833722 thread . Start ( ) ;
834- //thread.Join();
835723 }
836724 static string GetResultText ( ResultType result , string modName , string errorString )
837725 {
@@ -860,13 +748,6 @@ static string GetResultText(ResultType result, string modName, string errorStrin
860748
861749 static void WaitForExit ( )
862750 {
863- //MessageBox.Show("WAITING FOR EXIT");
864- /*if (XmlInstallerWindow.installerWindows.Count == 0)
865- {
866- ShowExitMessageBox();
867- }
868- else
869- {*/
870751 int counter = 0 ;
871752 System . Timers . Timer timer = new System . Timers . Timer ( 10 ) ;
872753 timer . Elapsed += ( sneder , args ) =>
@@ -882,14 +763,12 @@ static void WaitForExit()
882763 } ;
883764 timer . Start ( ) ;
884765 Application . Run ( ) ;
885- //}
886766 }
887767
888768 static void ShowExitMessageBox ( )
889769 {
890770 Thread thread = new Thread ( ( ) =>
891771 {
892- //ModList.Save();
893772 var win = ModInstalledWindow . GetDialog ( outcome , Strings . InstallationCompleted ) ; //"Your selected mods are done installing.\n" +
894773 win . Closed += ( snedre , rags ) => Process . GetCurrentProcess ( ) . Kill ( ) ;
895774 win . ShowDialog ( ) ;
0 commit comments