Beispiel #1
0
        static Mod()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            using (StreamReader nameStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Name.txt"))) {
                Name = nameStream.ReadToEnd();
            }

            using (StreamReader uninstallerPathStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Uninstaller Path.txt"))) {
                string[]           uninstallerPathStrings = Tools.NormalizeLineEndings(uninstallerPathStream.ReadToEnd(), "\n").Split('\n');
                IO.PathContainer[] uninstallerPaths       = new IO.PathContainer[uninstallerPathStrings.Length];

                for (int uninstallerPathIndex = 0; uninstallerPathIndex < uninstallerPathStrings.Length; uninstallerPathIndex++)
                {
                    uninstallerPaths[uninstallerPathIndex] = new IO.PathContainer(uninstallerPathStrings[uninstallerPathIndex]);
                }

                UninstallerPaths = uninstallerPaths;
            }

            using (StreamReader antiqueVersionFilesStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Antique Version Files.xml"))) {
                AntiqueVersionFiles = (AntiqueVersionFile[])XML.Read <AntiqueVersionFile[]>(antiqueVersionFilesStream.ReadToEnd());
            }

            using (StreamReader antiqueFileListsStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Antique File Lists.xml"))) {
                AntiqueFileLists = (AntiqueFileList[])XML.Read <AntiqueFileList[]>(antiqueFileListsStream.ReadToEnd());
            }
        }
Beispiel #2
0
        private void InstallButton_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].ToLower() == "mods")
                {
                    if (MessageBox.Show(Localization.GetString("SelectedModsFolderMessageText"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

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


            Hide();
            Main.Run();
            Close();
        }
Beispiel #3
0
        public static IO.PathContainer[] GetUninstallerFullPaths()
        {
            IO.PathContainer[] uninstallerFullPaths = new IO.PathContainer[UninstallerPaths.Length];

            for (int uninstallerPathIndex = 0; uninstallerPathIndex < UninstallerPaths.Length; uninstallerPathIndex++)
            {
                uninstallerFullPaths[uninstallerPathIndex] = new IO.PathContainer(Path.Combine(Paths.ModsPath.GetPath(), UninstallerPaths[uninstallerPathIndex].GetPath()));
            }

            return(uninstallerFullPaths);
        }
Beispiel #4
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()));
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public static IO.PathContainer GetIdentifyingFile()
        {
            IO.PathContainer filePath = null;

            foreach (Mod.AntiqueVersionFile versionFile in Mod.AntiqueVersionFiles)
            {
                if (File.Exists(versionFile.FullPath.GetPath()))
                {
                    if (filePath != null)
                    {
                        throw new Exception("Found multiple version files");
                    }

                    filePath = versionFile.FullPath;
                }
            }

            return(filePath);
        }
Beispiel #7
0
        static Mod()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            using (StreamReader nameStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Name.txt"))) {
                Name = nameStream.ReadToEnd();
            }

            using (StreamReader uninstallerPathStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Uninstaller Path.txt"))) {
                UninstallerPath = new IO.PathContainer(uninstallerPathStream.ReadToEnd());
            }

            using (StreamReader antiqueVersionFilesStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Antique Version Files.xml"))) {
                AntiqueVersionFiles = (AntiqueVersionFile[])XML.Read <AntiqueVersionFile[]>(antiqueVersionFilesStream.ReadToEnd());
            }

            using (StreamReader antiqueFileListsStream = new StreamReader(executingAssembly.GetManifestResourceStream(Entry.Namespace + ".Mod.Antique File Lists.xml"))) {
                AntiqueFileLists = (AntiqueFileList[])XML.Read <AntiqueFileList[]>(antiqueFileListsStream.ReadToEnd());
            }
        }
Beispiel #8
0
            public List <IO.PathContainer> FindValidPaths()
            {
                List <IO.PathContainer> validPaths = new List <IO.PathContainer>();

                if (Type == UninstallerPathType.RelativeToMods)
                {
                    IO.PathContainer uninstallerPathObject = new IO.PathContainer(System.IO.Path.Combine(Paths.ModsPath.ToString(), Path));

                    if (File.Exists(uninstallerPathObject.ToString()))
                    {
                        validPaths.Add(uninstallerPathObject);
                    }
                }
                else if (Type == UninstallerPathType.UniqueFileName)
                {
                    validPaths.AddRange(IO.SearchForFilesNamed(Paths.ModsPath.ToString(), Path, 2));
                }

                return(validPaths);
            }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        static Paths()
        {
            Sims4Path = new IO.PathContainer(Entry.Target ?? Path.Combine(new string[] { Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Electronic Arts", "The Sims 4" }));

            TemporaryPath = new IO.PathContainer(Path.Combine(Path.GetTempPath(), Entry.Namespace + Guid.NewGuid().ToString()));
        }