Beispiel #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)
                {
                    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);
        }