/// <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); } }
/// <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> /// 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); } }