Esempio n. 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (Settings.ForceSoftwareRendering)
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            MessageDisplay.ErrorOccurred += (sender, args) =>
            {
                App_Exit(this, null);
                CommonUI.MessageDisplay.ShowException(args.Exception);
            };
            MessageDisplay.MessageBoxShown  += (sneder, args) => Dispatcher.BeginInvoke(new Action(() => CommonUI.MessageDisplay.ShowMessageBox(args.Content, args.Title)));
            MessageDisplay.DebugMessageSent += (sneder, args) => Dispatcher.BeginInvoke(new Action(() => CommonUI.MessageDisplay.ShowMessageBox(args.Content, args.Title)));

            Settings.EnsureDllsAreExtracted();
            CommonUI.Updater.CheckForUpdates();
            Settings.ManagerInstallLocationPath = Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString();

            Exit += App_Exit;

            if (CommonUI.VersionValidation.IsConfigVersionCompatible(true, out Version previousModMgrVersion))
            {
                if (ServantCommands.RunLkImporter() == null)
                {
                    if (Permissions.IsAtleastWindowsVista() && (!Permissions.IsAdministrator()))
                    {
                        if (Permissions.AreAnyOtherModManagersRunning())
                        {
                            if (Environment.GetCommandLineArgs().Length > 1)
                            {
                                List <string> files = new List <string>();
                                foreach (string s in Environment.GetCommandLineArgs().Skip(1))
                                {
                                    string path = s.Trim('\"', ' ');
                                    if (File.Exists(path))
                                    {
                                        files.Add(path);
                                    }
                                }
                                string draggedFilesPath = Path.Combine(Settings.TempFolderPath, "draggedFiles");
                                File.WriteAllLines(draggedFilesPath, files);
                                Permissions.GrantAccessFile(draggedFilesPath);
                            }
                            else
                            {
                                MessageBox.Show(Settings.GetLanguageString("CloseSporeModManagerFirst"));
                            }
                            Process.GetCurrentProcess().Kill();
                        }

                        /*foreach (Process proc in Process.GetProcessesByName("SporeMods.DragServant").ToList())
                         *  proc.Kill();*/
                        string  parentDirectoryPath = Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString();
                        Process p    = Process.Start(Path.Combine(parentDirectoryPath, "SporeMods.DragServant.exe"), Process.GetCurrentProcess().Id.ToString());
                        string  args = Permissions.GetProcessCommandLineArgs();
                        args += " " + DragServantIdArg + p.Id;
                        if (!Environment.GetCommandLineArgs().Contains(UpdaterService.IgnoreUpdatesArg))
                        {
                            args += " " + UpdaterService.IgnoreUpdatesArg;
                        }
                        try
                        {
                            while (p.MainWindowHandle == IntPtr.Zero)
                            {
                            }

                            Permissions.RerunAsAdministrator(args);
                        }
                        catch (Exception ex)
                        {
                            //MessageBox.Show(ex.GetType().FullName + "\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Fatal error");
                            foreach (Process proc in Process.GetProcessesByName("SporeMods.DragServant").ToList())
                            {
                                proc.Kill();
                            }
                            Application.Current.Shutdown();
                        }
                    }
                    else// if (Permissions.IsAdministrator())
                    {
                        string[] clArgs = Environment.GetCommandLineArgs();
                        foreach (string arg in clArgs)
                        {
                            string targ = arg.Trim(" ".ToCharArray());
                            if (targ.StartsWith(DragServantIdArg))
                            {
                                DragServantProcess = Process.GetProcessById(int.Parse(targ.Replace(DragServantIdArg, string.Empty)));
                                break;
                            }
                        }

                        bool proceed = true;

                        if (Permissions.IsAtleastWindowsVista() && (DragServantProcess == null))
                        {
                            proceed = false;
                            if (Settings.NonEssentialIsRunningUnderWine)
                            {
                                proceed = true;
                            }
                            else if (MessageBox.Show(Settings.GetLanguageString(1, "DontRunAsAdmin").Replace("%APPNAME%", "Spore Mod Manager"), String.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                            {
                                proceed = true;
                            }
                        }
                        else if ((!Permissions.IsAtleastWindowsVista()) && (DragServantProcess == null))
                        {
                            DragServantProcess = Process.Start(Path.Combine(Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString(), "SporeMods.DragServant.exe"));
                        }

                        if (proceed)
                        {
                            base.OnStartup(e);

                            //ModInstallation.DoFirstRunVerification();

                            Window         window;
                            ManagerContent content = new ManagerContent();
                            if (Settings.UseCustomWindowDecorations)
                            {
                                window = new Mechanism.Wpf.Core.Windows.DecoratableWindow()
                                {
                                    Content        = content,
                                    TitlebarHeight = 61
                                };
                            }
                            else
                            {
                                window = new Window()
                                {
                                    Content = content
                                };
                            }

                            window.MinWidth         = 700;
                            window.MinHeight        = 400;
                            window.Width            = 800;
                            window.Height           = 450;
                            MainWindow              = window;
                            window.ContentRendered += (sneder, args) => content.MainWindow_OnContentRendered(args);
                            window.Activated       += content.MainWindow_IsActiveChanged;
                            window.Deactivated     += content.MainWindow_IsActiveChanged;
                            window.SizeChanged     += content.MainWindow_SizeChanged;
                            window.PreviewKeyDown  += content.MainWindow_PreviewKeyDown;
                            window.Closing         += content.MainWindow_Closing;
                            window.Show();
                        }
                        else
                        {
                            Application.Current.Shutdown();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] programArgs)
        {
            MessageDisplay.ErrorOccurred += (sender, args) =>
            {
                CommonUI.MessageDisplay.ShowException(args.Exception, false);
                try
                {
                    if (SporeLauncher.IsSporeSuspended(true, out bool killed) && killed)
                    {
                        MessageBox.Show(Settings.GetLanguageString(3, "StartupAborted"));
                    }
                }
                catch { }

                Process.GetCurrentProcess().Close();
            };
            MessageDisplay.MessageBoxShown  += (sender, args) => CommonUI.MessageDisplay.ShowMessageBox(args.Content, args.Title);
            MessageDisplay.DebugMessageSent += (sneder, args) => CommonUI.MessageDisplay.ShowMessageBox(args.Content, args.Title);

            /*{
             *  if (args.Content.IsNullOrEmptyOrWhiteSpace())
             *      MessageBox.Show(args.Exception.ToString(), args.Title);
             *  else
             *      MessageBox.Show(args.Content + "\n\n" + args.Exception.ToString(), args.Title);
             * };*/
            /*{
             *  if (string.IsNullOrEmpty(args.Content) || string.IsNullOrWhiteSpace(args.Content) || args.Exception.ToString().Contains(args.Content))
             *      MessageBox.Show(args.Exception.ToString(), args.Title);
             *  else if (args.Exception == null)
             *      MessageBox.Show(args.Content, args.Title);
             *  else
             *      MessageBox.Show(args.Content + "\n\n" + args.Exception.ToString(), args.Title);
             * };*/

            if (CommonUI.VersionValidation.IsConfigVersionCompatible(false, out Version previousModMgrVersion))
            {
                if (ServantCommands.RunLkImporter() == null)
                {
                    if (programArgs.Length > 1 && programArgs[0] == "--modapifix")
                    {
                        ExtractModAPIFix();
                        return;
                    }
                    else
                    {
                        if (Settings.ForceSoftwareRendering)
                        {
                            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
                        }
                        //uncomment below to test ProgressDialog appearance

                        /*var progressDialog = CommonUI.Updater.GetProgressDialog(string.Empty, null, true);
                         * Application.Run();*/
                        if (File.Exists(Path.Combine(Settings.TempFolderPath, "InstallingSomething")))
                        {
                            MessageBox.Show(Settings.GetLanguageString(3, "CantRunSporeWhileInstallingMods"));
                            Process.GetCurrentProcess().Kill();
                        }


                        if (!Permissions.AreAnyOtherModManagersRunning())
                        {
                            CommonUI.Updater.CheckForUpdates();
                        }

                        Settings.ManagerInstallLocationPath = Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString();

                        bool proceed = true;
                        if (Permissions.IsAtleastWindowsVista() && Permissions.IsAdministrator())
                        {
                            proceed = false;
                            if (Settings.NonEssentialIsRunningUnderWine)
                            {
                                proceed = true;
                            }
                            else if (MessageBox.Show(Settings.GetLanguageString(1, "DontRunAsAdmin").Replace("%APPNAME%", "Spore Mod Launcher"), String.Empty, MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                proceed = true;
                            }
                        }

                        try
                        {
                            if (!Settings.AreDllsPresent())
                            {
                                MessageBox.Show(Settings.GetLanguageString(3, "ModApiDllsNotPresent"));
                                proceed = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(Settings.GetLanguageString(3, "ModApiDllsNotPresent"));
                            proceed = false;
                        }

                        if (proceed)
                        {
                            //GameInfo..badBadGameInstallPath += (sneder, args) =>
                            if (GameInfo.BadGameInstallPaths.Any())
                            {
                                MessageBox.Show(Settings.GetLanguageString(3, "RunModManagerFirst")); //Please run the Spore Mod Manager at least once before running the Spore Mod Launcher.
                                Process.GetCurrentProcess().Kill();
                            }//;

                            SporeLauncher.CaptionHeight = SystemInformation.CaptionHeight;

                            if (SporeLauncher.IsInstalledDarkInjectionCompatible())
                            {
                                SporeLauncher.LaunchGame();
                            }
                        }
                        else
                        {
                            Application.Exit();
                        }
                    }
                }
            }
        }