示例#1
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);
        }
示例#2
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 { }
        }
示例#3
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);
        }