Esempio n. 1
0
        public static bool IsValidExe()
        {
            string errorBase = Settings.GetLanguageString(3, "ExeVersionNotRecognized");

            if (!(Settings.ForcedGameExeType.IsNullOrEmptyOrWhiteSpace()))
            {
                return(true);
            }
            else if (TryGetExeVersion(_executablePath, out Version exeVersion))
            {
                if ((exeVersion < Spore__March2017) && (exeVersion != Spore__1_5_1))
                {
                    MessageDisplay.RaiseError(new ErrorEventArgs(new InvalidOperationException(errorBase + "\n" + Settings.GetLanguageString(3, "SporeVersionTooOld"))));
                    return(false);
                }
                else if (exeVersion > Spore__March2017)
                {
                    MessageDisplay.RaiseError(new ErrorEventArgs(new InvalidOperationException(errorBase + "\n" + Settings.GetLanguageString(3, "DidTheyUpdateSpore"))));
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                MessageDisplay.RaiseError(new ErrorEventArgs(new InvalidOperationException(Settings.GetLanguageString(3, "CouldNotGetExeVersion"))));
                return(false);
            }
        }
Esempio n. 2
0
 public static void ThrowWin32Exception(string info, int error)
 {
     if ((error != 0) && (error != 18))
     {
         var exception = new System.ComponentModel.Win32Exception(error);
         //System.Windows.Forms.MessageBox.Show("Error: " + error.ToString() + "\n" + info);
         MessageDisplay.RaiseError(new ErrorEventArgs(exception));
         throw exception;
     }
 }
        public async Task <bool> UninstallModAsync()
        {
            var task = new Task <bool>(() =>
            {
                try
                {
                    FileWrite.SafeDeleteFile(FileWrite.GetFileOutputPath(Location, RealName, _legacy));
                    ModsManager.RunOnMainSyncContext(state => ModsManager.InstalledMods.Remove(this));
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageDisplay.RaiseError(new ErrorEventArgs(ex));
                    return(false);
                }
            });

            task.Start();
            return(await task);
        }
Esempio n. 4
0
        public static void LaunchGame()
        {
            try
            {
                _executablePath = Path.Combine(SporebinEP1, "SporeApp.exe");
                if (File.Exists(_executablePath))
                {
                    //IEnumerable<int> rawExeSizes = Enum.GetValues(typeof(GameInfo.)).Cast<long>();

                    /*long[] exeSizes = new long[rawExeSizes.Length];
                     * //exeSizes.CopyTo(rawExeSizes, 0);
                     * for (int i = 0; i < rawExeSizes.Length; i++)
                     *  exeSizes[i] = (long)rawExeSizes.GetValue(i);*/

                    bool exeSizeRecognized = ExecutableFileGameTypes.Keys.Contains(new FileInfo(_executablePath).Length);
                    if (IsValidExe())
                    {
                        try
                        {
                            _executableType = GetExecutableType();
                        }
                        catch (Exception ex)
                        {
                            MessageDisplay.RaiseError(new ErrorEventArgs(ex)); //ex.Message + "\n\n" + ex.StackTrace
                            return;
                        }

                        // Steam users need to do something different...something which doesn't even work most of the time.
                        if (!SporeIsInstalledOnSteam())
                        {
                            MessageDisplay.DebugShowMessageBox("2. Executable type: " + _executableType);

                            if (_executableType == GameExecutableType.None)
                            {
                                // don't execute the game if the user closed the dialog
                                return;
                            }

                            // get the correct executable path
                            _executablePath = Path.Combine(SporebinEP1, ExecutableFileNames[_executableType]);

                            if ((_executableType == GameExecutableType.Origin__1_5_1 ||
                                 _executableType == GameExecutableType.Origin__March2017) &&
                                !File.Exists(_executablePath))
                            {
                                var startInfo = new ProcessStartInfo(
                                    Path.Combine(Settings.ManagerInstallLocationPath, "Spore Mod Launcher.exe"),
                                    "--modapifix " + Directory.GetParent(_executablePath).FullName)
                                {
                                    Verb = "runas"
                                };
                                var p = Process.Start(startInfo);
                                p.WaitForExit();
                            }

                            string dllEnding = GetExecutableDllSuffix(_executableType);

                            MessageDisplay.DebugShowMessageBox("4. DLL suffix: " + dllEnding);

                            if (dllEnding == null)
                            {
                                MessageDisplay.DebugShowMessageBox(Settings.GetLanguageString(3, "NullDllSuffix")); //MessageBox.Show(Strings.VersionNotDetected, CommonStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }

                            InjectNormalSporeProcess(dllEnding);
                        }
                        else
                        {
                            InjectSteamSporeProcess();
                        }
                    }
                }

                int lastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

                if ((CurrentError != 0) && (CurrentError != 18) && (CurrentError != 87) && (CurrentError != lastError))
                {
                    try
                    {
                        ThrowWin32Exception("Something went wrong", CurrentError);
                    }
                    catch (Exception ex)
                    {
                        MessageDisplay.RaiseError(new ErrorEventArgs(ex));
                    }
                }

                if ((lastError != 0) && (lastError != 18))
                {
                    ThrowWin32Exception("Something went wrong", lastError);
                }
            }
            catch (Exception ex)
            {
                MessageDisplay.RaiseError(new ErrorEventArgs(ex));
                return;
            }
        }