예제 #1
0
        private void createDefaultProfiles()
        {
            Log.Info("Creating default profiles.");
            if (Directory.Exists(Path.Combine(UserDirPath, "profiles.dat")))
            {
                Directory.Delete(Path.Combine(UserDirPath, "profiles.dat"));
            }

            this.Profiles = new ProfileList();
            this.Profiles.Add("Vanilla");

            bool isModded = GameScanner.IsGTAModded();

            if (isModded)
            {
                Log.Info("GTA V is currently modded.");
                this.Profiles.Add("Modded");
            }
            else
            {
                Log.Info("GTA V is not currently modded");
            }

            this.Profiles.CurrentProfile = isModded ? 1 : 0;

            this.SaveProfiles();
        }
예제 #2
0
        /// <summary>
        /// Does basic checks to the profile (is modded but supposed to be vanilla, are mods in the wrong directory, ...)
        /// </summary>
        /// <returns>true if the game can be launched, false otherwise</returns>
        public bool CheckCurrentProfile()
        {
            if (Instance.Profiles.CurrentProfile == 0 && GameScanner.IsGTAModded())
            {
                Log.Warn("GTA V is modded while the selected profile is \"Vanilla\" !");

                MessageBoxResult result = Messages.Show(this.Window, "ModsOnVanilla", "Warn", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);

                if (result == MessageBoxResult.Yes)
                {
                    string name = Instance.GetNewProfileName();
                    this.Profiles.Add(name);
                    this.Profiles.CurrentProfile = Instance.Profiles.Count - 1;
                    this.UiManager.Profiles.Add(name);
                    this.UiManager.SelectedProfile = this.UiManager.Profiles.Count - 1;
                    this.SaveProfiles();
                    return(true);
                }
                else if (result == MessageBoxResult.No)
                {
                    PopupDeletingMods popup = new PopupDeletingMods();
                    this.CurrentThread = popup.StartThread();
                    popup.ShowDialog();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (Instance.Profiles.CurrentProfile != 0 && Directory.Exists(Path.Combine(this.Settings.GetProfileFolder(), this.Profiles[this.Profiles.CurrentProfile])))
            {
                string path = Path.Combine(this.Settings.GetProfileFolder(), this.Profiles[this.Profiles.CurrentProfile]);

                if (Directory.GetFileSystemEntries(path).GetLength(0) != 0)
                {
                    MessageBoxResult result = Messages.Show(this.Window, "UpdateProfile", "UpdateProfile", MessageBoxButton.YesNo, MessageBoxImage.Question);

                    if (result == MessageBoxResult.Yes)
                    {
                        PopupMoveMods popup = new PopupMoveMods(path);
                        this.CurrentThread = popup.StartThread();
                        popup.ShowDialog();
                    }
                }

                return(true);
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// Change the active profile and move the mods accordingly
        /// </summary>
        /// <param name="selected"></param>
        public void SwitchProfileTo(Profile selected)
        {
            if (this.Config.Profile != selected)
            {
                Profile oldProfile = this.Config.Profile;

                this.UiManager.Working = true;

                Log.Info("Switching from profile '" + oldProfile + "' to '" + selected + "'.");
                this.WorkManager.ProgressDisplay.ProgressState = ProgressState.Indeterminate;

                try
                {
                    if (!oldProfile.IsVanilla)
                    {
                        string profilePath = oldProfile.ExtFolder;
                        GameScanner.ListRootMods(out List <string> modFiles, out List <string> modDirs);
                        List <string> dlcMods = GameScanner.ListDlcMods();

                        foreach (string dir in modDirs)
                        {
                            this.WorkManager.QueueJob(new MoveJob(dir, Path.Combine(profilePath, IOUtil.GetRelativePath(dir, this.Config.SelectedInstall.Path))));
                        }
                        foreach (string file in modFiles)
                        {
                            if (this.Config.DeleteLogs && file.EndsWith(".log"))
                            {
                                this.WorkManager.QueueJob(new DeleteJob(file));
                            }
                            else
                            {
                                this.WorkManager.QueueJob(new MoveJob(file, Path.Combine(profilePath, IOUtil.GetRelativePath(file, this.Config.SelectedInstall.Path))));
                            }
                        }
                        foreach (string mod in dlcMods)
                        {
                            this.WorkManager.QueueJob(new MoveJob(mod, Path.Combine(profilePath, IOUtil.GetRelativePath(mod, this.Config.SelectedInstall.Path))));
                        }
                    }

                    if (!selected.IsVanilla)
                    {
                        string profilePath = selected.ExtFolder;

                        foreach (string entry in Directory.GetFileSystemEntries(profilePath))
                        {
                            this.WorkManager.QueueJob(new MoveJob(entry, Path.Combine(this.Config.SelectedInstall.Path, Path.GetFileName(entry))));
                        }
                    }

                    this.WorkManager.PerformJobs();

                    this.Config.Profile = selected;
                    this.Config.Save();
                    this.UiManager.UpdateActiveProfile();
                }
                catch (IOException e)
                {
                    Log.Error(e.ToString());
                    LocalizedMessage.Show(this.Window, "ProfileSwitchError", "FatalError", DialogIcon.Error, DialogButtons.Ok);
                    Process.GetCurrentProcess().Kill();
                }

                this.WorkManager.ProgressDisplay.ProgressState = ProgressState.NoProgress;
                this.UiManager.Working = false;
            }
        }
        /// <summary>
        /// Do basic checks to the profile (is modded but supposed to be vanilla, are mods in the wrong directory, ...)
        /// </summary>
        /// <returns>true if the game can be launched, false otherwise</returns>
        public bool CheckCurrentProfile()
        {
            Profile currentProfile = this.Config.Profile;

            if (currentProfile.IsVanilla && GameScanner.IsGTAModded())
            {
                Log.Warn("GTA V is modded, but the vanilla profile is selected !");

                DialogStandardResult result = LocalizedMessage.Show(this.Window, "ModsOnVanilla", "Warn", DialogIcon.Warning, DialogButtons.Yes | DialogButtons.No | DialogButtons.Cancel);

                if (result == DialogStandardResult.Yes)
                {
                    string name = this.GetNewProfileName();

                    Profile profile = new Profile(name);
                    this.Config.Profiles.Add(profile);
                    this.Config.Profile = profile;
                    this.Config.Save();
                    this.UiManager.AddProfile(profile);
                    this.UiManager.UpdateActiveProfile();
                    return(true);
                }
                else if (result == DialogStandardResult.No)
                {
                    new PerformJobDialog(this.WorkManager, new DeleteMods()).Show(this.WorkManager);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (!currentProfile.IsVanilla && Directory.Exists(currentProfile.ExtFolder))
            {
                string path = currentProfile.ExtFolder;

                if (Directory.GetFileSystemEntries(path).GetLength(0) != 0)
                {
                    DialogStandardResult result = LocalizedMessage.Show(this.Window, "UpdateProfile", "UpdateProfile", DialogIcon.Information, DialogButtons.Yes | DialogButtons.No);

                    if (result == DialogStandardResult.Yes)
                    {
                        GameScanner.ListRootMods(out List <string> modFiles, out List <string> modDirs);
                        List <string> dlcMods = GameScanner.ListDlcMods();

                        foreach (string dir in modDirs)
                        {
                            this.WorkManager.QueueJob(new MoveJob(dir, Path.Combine(path, IOUtil.GetRelativePath(dir, this.Config.SelectedInstall.Path))));
                        }
                        foreach (string file in modFiles)
                        {
                            if (this.Config.DeleteLogs && file.EndsWith(".log"))
                            {
                                this.WorkManager.QueueJob(new DeleteJob(file));
                            }
                            else
                            {
                                this.WorkManager.QueueJob(new MoveJob(file, Path.Combine(path, IOUtil.GetRelativePath(file, this.Config.SelectedInstall.Path))));
                            }
                        }
                        foreach (string mod in dlcMods)
                        {
                            this.WorkManager.QueueJob(new MoveJob(mod, Path.Combine(path, IOUtil.GetRelativePath(mod, this.Config.SelectedInstall.Path))));
                        }

                        new PerformJobsDialog(this.WorkManager).Show();
                    }
                }

                return(true);
            }
            else
            {
                return(true);
            }
        }
        private void InitLauncher()
        {
            Log.Info("Initializing launcher...");
            SteamHelper.Initialize();

            if (this.Config.SelectedInstall != null && (this.Config.SelectedInstall.Path == null || !Directory.Exists(this.Config.SelectedInstall.Path)))
            {
                this.Config.SelectedInstall = null;
            }

            if (this.Config.SelectedInstall == null)
            {
                GTAInstall[] installs = GTAInstall.FindInstalls();

                if (installs.Length > 0)
                {
                    this.Config.SelectedInstall = installs[0];
                }
                else
                {
                    LocalizedMessage.Show("GTANotFound", "Info", DialogIcon.Information, DialogButtons.Ok);
                    HostWindow host = new HostWindow();
                    host.Content = new ChooseInstallDialog(host);
                    host.ShowDialog();

                    if (this.Config.SelectedInstall == null)
                    {
                        Environment.Exit(1);
                        return;
                    }
                }

                this.Config.Save();
            }

            Log.Info("Using GTA V installation at " + this.Config.SelectedInstall.Path);
            Log.Info("Installation type: " + this.Config.SelectedInstall.Type);

            if (Path.GetFullPath(this.WorkingDirectory).Equals(Path.GetFullPath(this.Config.SelectedInstall.Path)))
            {
                LocalizedMessage.Show("InstalledInGTA", "Error", DialogIcon.Error, DialogButtons.Ok);
                Environment.Exit(1);
            }

            GameScanner.Init();

            Log.Info("Loading profiles...");

            string profilesDir = Path.Combine(this.UserDirectory, "Profiles");

            if (!Directory.Exists(profilesDir))
            {
                Directory.CreateDirectory(profilesDir);
            }

            if (this.Config.VanillaProfile == null)
            {
                Log.Info("Vanilla profile not found. Creating it");
                this.Config.Profiles.Add(new Profile("Vanilla", true));
            }

            foreach (string dir in Directory.EnumerateDirectories(profilesDir))
            {
                string name = Path.GetFileName(dir);
                if (!this.Config.ProfileExists(name))
                {
                    this.Config.Profiles.Add(new Profile(name));
                }
            }

            if (this.Config.Profile == null)
            {
                Log.Info("Current profile is invalid");

                if (GameScanner.IsGTAModded())
                {
                    Log.Info("GTA is currently modded: creating new modded profile");
                    Profile profile = new Profile(this.GetNewProfileName());
                    this.Config.Profiles.Add(profile);
                    this.Config.Profile = profile;
                }
                else
                {
                    Log.Info("GTA is currently not modded: considering the game vanilla");
                    this.Config.CurrentProfile = this.Config.VanillaProfile.Name;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Gets called when the user press the "Play" or "Play online" button
        /// </summary>
        /// <param name="online">Did the user chose to play online</param>
        /// <param name="selected">the selected profile ID</param>
        private void SwitchProfileAndPlay(bool online, int selected)
        {
            if (this.Profiles.CurrentProfile != selected)
            {
                Log.Info("Switching from profile '" + this.Profiles[this.Profiles.CurrentProfile] + "' to '" + this.Profiles[selected] + "'.");

                try
                {
                    List <string> modFiles     = null;
                    List <string> modDirs      = null;
                    List <string> dlcMods      = null;
                    string[]      profileDirs  = null;
                    string[]      profileFiles = null;
                    int           moveCount    = 0;

                    if (this.Profiles.CurrentProfile != 0)
                    {
                        GameScanner.ListRootMods(out modFiles, out modDirs);
                        dlcMods    = GameScanner.ListDlcMods();
                        moveCount += modFiles.Count + modDirs.Count + dlcMods.Count;
                    }

                    if (selected != 0)
                    {
                        string profilePath = Path.Combine(this.Settings.GetProfileFolder(), this.Profiles[selected]);
                        profileDirs  = Directory.GetDirectories(profilePath, "*", SearchOption.AllDirectories);
                        profileFiles = Directory.GetFiles(profilePath, "*", SearchOption.AllDirectories);
                        moveCount   += profileDirs.Length + profileFiles.Length;
                    }

                    this.SetProgressBarMaximum(moveCount);

                    if (this.Profiles.CurrentProfile != 0)
                    {
                        string profilePath = Path.Combine(this.Settings.GetProfileFolder(), this.Profiles[this.Profiles.CurrentProfile]);
                        if (!Directory.Exists(profilePath))
                        {
                            Directory.CreateDirectory(profilePath);
                        }


                        foreach (string dir in modDirs)
                        {
                            string name = dir.Replace(this.GtaPath, profilePath);
                            if (!Directory.Exists(name))
                            {
                                Directory.CreateDirectory(name);
                            }
                            this.IncrProgressBarValue();
                        }

                        foreach (string file in modFiles)
                        {
                            if (this.Settings.DeleteLogs && file.EndsWith(".log"))
                            {
                                File.Delete(file);
                            }
                            else
                            {
                                string name = file.Replace(this.GtaPath, profilePath);
                                if (!File.Exists(name))
                                {
                                    File.Move(file, name);
                                }
                                else
                                {
                                    File.Delete(file);
                                }
                            }
                            this.IncrProgressBarValue();
                        }

                        foreach (string dir in modDirs)
                        {
                            if (Directory.Exists(dir))
                            {
                                IOUtils.Delete(dir);
                            }
                        }

                        foreach (string mod in dlcMods)
                        {
                            IOUtils.MoveDirectory(mod, mod.Replace(this.GtaPath, profilePath), false);
                            this.IncrProgressBarValue();
                        }
                    }

                    if (selected != 0)
                    {
                        string profilePath = Path.Combine(this.Settings.GetProfileFolder(), this.Profiles[selected]);
                        if (!Directory.Exists(profilePath))
                        {
                            Directory.CreateDirectory(profilePath);
                        }


                        foreach (string dir in profileDirs)
                        {
                            string name = dir.Replace(profilePath, this.GtaPath);
                            if (!Directory.Exists(name))
                            {
                                Directory.CreateDirectory(name);
                            }
                            this.IncrProgressBarValue();
                        }

                        foreach (string file in profileFiles)
                        {
                            string name = file.Replace(profilePath, this.GtaPath);
                            if (!File.Exists(name))
                            {
                                File.Move(file, name);
                            }
                            else
                            {
                                File.Delete(file);
                            }
                            this.IncrProgressBarValue();
                        }

                        foreach (string dir in profileDirs)
                        {
                            if (Directory.Exists(dir))
                            {
                                IOUtils.Delete(dir);
                            }
                        }
                    }

                    this.Profiles.CurrentProfile = selected;
                    this.SaveProfiles();

                    this.Window.Dispatcher.Invoke(new BoolCallback(LaunchGame), online);
                }
                catch (IOException e)
                {
                    Log.Error(e.ToString());
                    this.Window.Dispatcher.Invoke(new BoolIntCallback(RetryAfterPermissionUpgrade), online, selected);
                }
                catch (UnauthorizedAccessException e)
                {
                    Log.Error(e.ToString());
                    this.Window.Dispatcher.Invoke(new BoolIntCallback(RetryAfterPermissionUpgrade), online, selected);
                }
            }
            else
            {
                this.Window.Dispatcher.Invoke(new BoolCallback(LaunchGame), online);
            }
        }
예제 #7
0
        private void InitLauncher()
        {
            Log.Info("Initializing launcher...");

            if (this.Settings.CustomGTAFolder != null)
            {
                this.GtaPath = this.Settings.CustomGTAFolder;
            }
            else
            {
                this.ReadGamePath();
            }

            if (this.GtaPath != null)
            {
                if (this.GtaPath.EndsWith("\\"))
                {
                    this.GtaPath = this.GtaPath.Substring(0, this.GtaPath.Length - 1);
                }

                Log.Info("Found GTA V installation at " + this.GtaPath + ' ' + (this.IsSteamVersion() ? "(Steam version)" : this.IsCustomVersion() ? "(Custom retail version)" : "(Retail version)"));

                if (Directory.Exists(this.GtaPath))
                {
                    GameScanner.Init();

                    if (File.Exists(Path.Combine(UserDirPath, "profiles.dat")))
                    {
                        try
                        {
                            using (Stream stream = File.Open(Path.Combine(UserDirPath, "profiles.dat"), FileMode.Open))
                            {
                                this.Profiles = (ProfileList)formatter.Deserialize(stream);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Unable to read saved profiles.");
                            Log.Error(ex.ToString());
                            Messages.UnableToReadProfiles();
                            this.createDefaultProfiles();
                        }
                    }
                    else
                    {
                        Log.Info("No profiles.dat file found.");
                        this.createDefaultProfiles();
                    }

                    this.Window.Dispatcher.Invoke(new Callback(UpdateUI));
                }
                else
                {
                    Log.Error("GTA V wasn't found at the specified location.");
                    Messages.GTANotFound();
                }
            }
            else
            {
                Log.Error("No GTA installation found.");
                Messages.NoGTA();
            }
        }