Example #1
0
        static void Main()
        {
            AppDomain.CurrentDomain.ProcessExit += OnExit;

            Namespace       = "NOModUninstaller";
            ApplicationPath = new IO.PathContainer(Application.ExecutablePath);

            if (!ReadArguments())
            {
                return;
            }

            if (!Silent)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (!Quick)
                {
                    Application.Run(new Setup());
                    return;
                }
            }

            NOModUninstaller.Main.Run();
        }
Example #2
0
        private void UninstallButton_Click(object sender, EventArgs e)
        {
            try {
                new DirectoryInfo(UserDirectoryTextbox.Text);
            } catch {
                MessageBox.Show(string.Format(Localization.GetString("InvalidDirectory"), UserDirectoryTextbox.Text));
                return;
            }

            IO.PathContainer sims4Path         = new IO.PathContainer(UserDirectoryTextbox.Text);
            string[]         sims4PathSegments = sims4Path.GetSegments();

            if (sims4PathSegments.Length >= 2)
            {
                if (sims4PathSegments[sims4PathSegments.Length - 1].Equals("mods", StringComparison.OrdinalIgnoreCase))
                {
                    if (MessageBox.Show(Localization.GetString("SelectedModsFolderMessageText"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

            Paths.Sims4Path = new IO.PathContainer(UserDirectoryTextbox.Text);

            Hide();
            Main.Run();
            Close();
        }
Example #3
0
        static Paths()
        {
            string appropriateSims4Path = FindAppropriateSims4Path();

            if (appropriateSims4Path != null)
            {
                Sims4Path = new IO.PathContainer(appropriateSims4Path);
            }

            TemporaryPath = new IO.PathContainer(Path.Combine(Path.GetTempPath(), Entry.Namespace + Guid.NewGuid().ToString()));
        }
Example #4
0
        private static bool CheckGame()
        {
            try {
                string sims4InstallPath = (string)Registry.GetValue(Registry.LocalMachine + @"\SOFTWARE\Wow6432Node\Maxis\The Sims 4", "Install Dir", null);

                if (sims4InstallPath == null)
                {
                    return(true);
                }

                IO.PathContainer sims4ApplicationPath   = new IO.PathContainer(Path.Combine(sims4InstallPath, "Game", "Bin", "TS4.exe"));
                IO.PathContainer sims464ApplicationPath = new IO.PathContainer(Path.Combine(sims4InstallPath, "Game", "Bin", "TS4_x64.exe"));

                Process[] processes = Process.GetProcesses();

                bool running = false;

                for (int processIndex = 0; processIndex < processes.Length; processIndex++)
                {
                    try {
                        IO.PathContainer processPath = new IO.PathContainer(Processes.GetPath(processes[processIndex]));

                        if (!string.IsNullOrWhiteSpace(processPath.GetPath()))
                        {
                            if (processPath.Equals(sims4ApplicationPath) || processPath.Equals(sims464ApplicationPath))
                            {
                                running = true;
                                break;
                            }
                        }
                    } catch { }
                }

                if (running)
                {
                    if (!Entry.Silent)
                    {
                        MessageBox.Show(Localization.GetString("Sims4RunningText"));
                    }

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

                return(false);
            }

            return(true);
        }
Example #5
0
        static Mod()
        {
            Name = Properties.Settings.Default.ModName;
            string fileListFileName = Properties.Settings.Default.FileListFileName;

            FileListPath = new IO.PathContainer(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), fileListFileName));
            ConfigPath   = new IO.PathContainer(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Path.GetFileName(Application.ExecutablePath) + ".config"));

            try {
                if (File.Exists(FileListPath.GetPath()))
                {
                    FileList = (FileListType)XML.Read <FileListType>(File.ReadAllText(FileListPath.GetPath()));
                }
            } catch { }
        }
Example #6
0
        public static List <IO.PathContainer> GetValidFilePaths()
        {
            List <IO.PathContainer> validFilePaths = new List <IO.PathContainer>();

            if (FileList == null)
            {
                return(validFilePaths);
            }

            validFilePaths.AddRange(IO.SearchForFilesNamed(Paths.ModsPath.ToString(), FileList.UniqueFileNames, 2));

            for (int fileIndex = 0; fileIndex < FileList.FilePaths.Length; fileIndex++)
            {
                IO.PathContainer filePath = new IO.PathContainer(Path.Combine(Paths.ModsPath.GetPath(), FileList.FilePaths[fileIndex]));

                if (File.Exists(filePath.ToString()) && !validFilePaths.Contains(filePath))
                {
                    validFilePaths.Add(filePath);
                }
            }

            return(validFilePaths);
        }
Example #7
0
        private static bool DeleteFiles()
        {
            try {
                if (Mod.FileList != null)
                {
                    List <IO.PathContainer> files     = Mod.GetValidFilePaths();
                    List <IO.PathContainer> fileRoots = new List <IO.PathContainer>();

                    bool removedFileListPath = false;
                    bool removedConfigPath   = false;

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

                        if (files[fileIndex].Equals(Mod.ConfigPath))
                        {
                            files.RemoveAt(fileIndex);
                            fileIndex--;
                            removedConfigPath = true;
                            continue;
                        }

                        if (files[fileIndex].Equals(Entry.ApplicationPath))
                        {
                            files.RemoveAt(fileIndex);
                            fileIndex--;
                            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 (removedFileListPath || removedConfigPath)
                    {
                        if (File.Exists(Mod.FileListPath.GetPath()))
                        {
                            File.Delete(Mod.FileListPath.GetPath());
                        }

                        if (File.Exists(Mod.ConfigPath.GetPath()))
                        {
                            File.Delete(Mod.ConfigPath.GetPath());
                        }

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

                return(false);
            }

            return(true);
        }
Example #8
0
        public static bool SelfDestruct()
        {
            if (Preserve)
            {
                return(true);
            }

            try {
                IO.PathContainer applicationDirectory = new IO.PathContainer(Path.GetDirectoryName(ApplicationPath.GetPath()));

                if (!ApplicationPath.IsChildOf(Paths.ModsPath))
                {
                    return(true);
                }

                if (applicationDirectory.Equals(Paths.ModsPath))
                {
                    SelfDestructApplication();
                    return(true);
                }

                IO.PathContainer applicationRelativeDirectory = applicationDirectory.GetRelativePathTo(Paths.ModsPath);
                IO.CloseDirectory(Path.Combine(Paths.ModsPath.GetPath(), applicationRelativeDirectory.GetPath(1)));

                List <string>    deletingDirectories = new List <string>();
                IO.PathContainer previousDirectory   = null;

                for (int applicationRelativeDirectoryIndex = applicationRelativeDirectory.Length - 1; applicationRelativeDirectoryIndex >= 0; applicationRelativeDirectoryIndex--)
                {
                    string directoryFullPath = Path.Combine(Paths.ModsPath.GetPath(), applicationRelativeDirectory.GetPath(applicationRelativeDirectoryIndex + 1));

                    if (applicationRelativeDirectoryIndex == applicationRelativeDirectory.Length - 1)
                    {
                        List <string> directoryFiles = new List <string>(Directory.GetFiles(directoryFullPath));

                        for (int directoryFileIndex = 0; directoryFileIndex < directoryFiles.Count; directoryFileIndex++)
                        {
                            if (ApplicationPath.Equals(directoryFiles[directoryFileIndex]))
                            {
                                directoryFiles.RemoveAt(directoryFileIndex);
                                directoryFileIndex--;
                                break;
                            }
                        }

                        if (directoryFiles.Count != 0 || Directory.GetDirectories(directoryFullPath).Length != 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        List <string> directorySubdirectories = new List <string>(Directory.GetDirectories(directoryFullPath));

                        for (int directorySubdirectoryIndex = 0; directorySubdirectoryIndex < directorySubdirectories.Count; directorySubdirectoryIndex++)
                        {
                            if (previousDirectory.Equals(directorySubdirectories[directorySubdirectoryIndex]))
                            {
                                directorySubdirectories.RemoveAt(directorySubdirectoryIndex);
                                directorySubdirectoryIndex--;
                                break;
                            }
                        }

                        if (Directory.GetFiles(directoryFullPath).Length != 0 || directorySubdirectories.Count != 0)
                        {
                            break;
                        }
                    }

                    previousDirectory = new IO.PathContainer(directoryFullPath);
                    deletingDirectories.Add(directoryFullPath);
                }

                if (previousDirectory == null)
                {
                    SelfDestructApplication();
                }
                else
                {
                    SelfDestructDirectory(deletingDirectories);
                }
            } catch (Exception e) {
                if (!Silent)
                {
                    Error errorDialog = new Error(Localization.GetString("SelfDestructFailure"), e.ToString());
                    errorDialog.ShowDialog();
                }

                return(false);
            }

            return(true);
        }