コード例 #1
0
ファイル: Main.cs プロジェクト: NeonOcean/Environment
        private static bool UninstallApplication()
        {
            try {
                IO.PathContainer uninstallerPath = Mod.GetUninstallerFullPath();

                using (Process uninstallProcess = new Process()
                {
                    StartInfo =
                    {
                        FileName  = uninstallerPath.GetPath(),
                        Arguments = "-q " + (Entry.Silent ? "-s " : " ") + "-p -t \"" + Paths.Sims4Path + "\"",
                    }
                }) {
                    uninstallProcess.Start();
                    uninstallProcess.WaitForExit();

                    if (uninstallProcess.ExitCode == 1)
                    {
                        return(false);
                    }

                    if (File.Exists(uninstallerPath.GetPath()))
                    {
                        File.Delete(uninstallerPath.GetPath());
                    }

                    IO.CloseDirectory(Path.Combine(Paths.ModsPath.GetPath(), uninstallerPath.GetRelativePathTo(Paths.ModsPath).GetPath(1)));
                }
            } catch (Exception e) {
                if (!Entry.Silent)
                {
                    Error errorDialog = new Error(Localization.GetString("UninstallFailure"), e.ToString());
                    errorDialog.ShowDialog();
                }

                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: NeonOcean/Environment
        private static bool UninstallAntique()
        {
            IO.PathContainer identifyingFile = null;
            string           version         = null;

            try {
                identifyingFile = Antique.GetIdentifyingFile();
                version         = Antique.GetVersion();
            } catch (Exception e) {
                if (!Entry.Silent)
                {
                    Error errorDialog = new Error(Localization.GetString("UninstallAntiqueReadVersionFailure"), e.ToString());
                    errorDialog.ShowDialog();
                }

                return(false);
            }

            try {
                if (version != null)
                {
                    List <IO.PathContainer> files = null;

                    foreach (Mod.AntiqueFileList antiqueFileList in Mod.AntiqueFileLists)
                    {
                        if (antiqueFileList.Version == version)
                        {
                            files = antiqueFileList.GetFilesFullPaths();
                        }
                    }

                    if (files != null)
                    {
                        List <IO.PathContainer> fileRoots = new List <IO.PathContainer>();

                        bool removedIdentifyingFile = false;

                        for (int fileIndex = 0; fileIndex < files.Count; fileIndex++)
                        {
                            if (files[fileIndex].Equals(identifyingFile))
                            {
                                files.RemoveAt(fileIndex);
                                fileIndex--;
                                removedIdentifyingFile = true;
                                continue;
                            }

                            IO.PathContainer fileRoot = new IO.PathContainer(Path.Combine(Paths.ModsPath.GetPath(), files[fileIndex].GetRelativePathTo(Paths.ModsPath).GetPath(1)));

                            if (!fileRoots.Contains(fileRoot))
                            {
                                fileRoots.Add(fileRoot);
                            }
                        }

                        IO.DeleteFiles(files);

                        for (int fileRootIndex = 0; fileRootIndex < fileRoots.Count; fileRootIndex++)
                        {
                            IO.CloseDirectory(fileRoots[fileRootIndex].GetPath());
                        }

                        if (removedIdentifyingFile)
                        {
                            if (File.Exists(identifyingFile.GetPath()))
                            {
                                File.Delete(identifyingFile.GetPath());
                            }

                            IO.CloseDirectory(Path.Combine(Paths.ModsPath.GetPath(), identifyingFile.GetRelativePathTo(Paths.ModsPath).GetPath(1)));
                        }
                    }
                    else
                    {
                        if (!Entry.Silent)
                        {
                            string errorMessage = Localization.GetString("UninstallAntiqueUnknownVersionFailure");
                            Error  errorDialog  = new Error(errorMessage, errorMessage);
                            errorDialog.ShowDialog();
                        }

                        return(false);
                    }
                }
            } catch (Exception e) {
                if (!Entry.Silent)
                {
                    Error errorDialog = new Error(Localization.GetString("UninstallAntiqueDeleteFailure"), e.ToString());
                    errorDialog.ShowDialog();
                }

                return(false);
            }

            return(true);
        }