Exemple #1
0
        public GameManager()
        {
            var s = new Stopwatch();

            s.Start();
            Utils.Log("Initializing GTA manager...");

            var gamePath = GetSteamGameInstallationFolder();

            if (gamePath.Equals(string.Empty))
            {
                gamePath = GetRockstarGameInstallationFolder();
                if (!gamePath.Equals(string.Empty))
                {
                    this.IsSteam       = false;
                    this.InstallFolder = gamePath;
                }
                else
                {
                    // game detection failed
                    // TODO: prompt user to manually select directory
                    this.IsSteam       = true;
                    this.InstallFolder = string.Empty;
                }
            }
            else
            {
                this.IsSteam       = true;
                this.InstallFolder = gamePath;
            }

            if (string.IsNullOrEmpty(this.InstallFolder))
            {
                MainWindow.ShowInitErrorAndExit();
            }

            // game directory is found, all good
            var edition = IsSteam ? "Steam" : "Rockstar Warehouse";

            Utils.Log($"Game found! Edition: {edition}");
            Utils.Log($"Installation folder: {InstallFolder}");

            var gtaFileVersionInfo = FileVersionInfo.GetVersionInfo(InstallFolder + @"\GTA5.exe");

            this.PatchVersion = gtaFileVersionInfo.ProductVersion;
            this.Language     = gtaFileVersionInfo.Language;

            if (File.Exists(this.InstallFolder + @"\commandline.txt"))
            {
                this.CommandlinePath = this.InstallFolder + @"\commandline.txt";
            }
            else
            {
                File.Create(this.InstallFolder + @"\commandline.txt");
                this.CommandlinePath = this.CommandlinePath + @"\commandline.txt";
                Utils.Log("Commandline.txt doesn't exitst, creating...");
            }

            if (!Directory.Exists(this.InstallFolder + Utils.MOD_STORAGE_FOLDER_ENDPOINT))
            {
                Utils.Log("ToolsV mods folder doesn't exist, creating...");
                Directory.CreateDirectory(this.InstallFolder + Utils.MOD_STORAGE_FOLDER_ENDPOINT);
            }
            this.ModStorageFolder = this.InstallFolder + Utils.MOD_STORAGE_FOLDER_ENDPOINT;

            if (Directory.Exists(this.InstallFolder + Utils.MOD_FOLDER_ENDPOINT))
            {
                if (GetMods(false).Count > 0)
                {
                    this.IsModded = true;
                }
            }
            if (!IsModded && GetMods(false).Count != 0 || GetModdedRpfs().Count != 0)
            {
                this.IsModded = true;
            }
            this.GameProperties = GetGameProperties();

            s.Stop();
            Utils.Log("Patch version: " + PatchVersion);
            Utils.Log("Language: " + Language);
            Utils.Log("Enabled mods: " + GetMods(false).Count);
            Utils.Log("Total mods: " + GetMods(true).Count);
            Utils.Log("RPF mods: " + GetModdedRpfs().Count);
            Utils.Log($"Game installation initialized in {Math.Round(s.Elapsed.TotalMilliseconds / 1000, 3)} seconds");
            s.Reset();
        }