/// <summary> /// Uninstalls a game mod. /// </summary> public async Task Uninstall(Mod m) { string modPath = AppDomain.CurrentDomain.BaseDirectory + "\\mods\\" + m.Slug; string backupPath = AppDomain.CurrentDomain.BaseDirectory + "\\backups\\" + m.Slug; Console.WriteLine("Uninstall Task"); if (Directory.Exists(backupPath)) { foreach (var f in Directory.GetFiles(modPath)) { string fileName = Path.GetFileName(f); string from = modPath + "\\" + fileName; string destin = settings.PSO2Dir + "\\" + fileName; string backup = backupPath + "\\" + fileName; if (!File.Exists(backup)) { continue; } // TODO: if backup file does not exists or not vanilla file, download patch from official site var UninstallTask = new Helpers.FileCopy(backup, destin); if (!await Task.Run(() => UninstallTask.StartCopy())) { // If error, download patch from official site await Task.Run(() => Helpers.DownloadPatch(fileName, destin)); } } Directory.Delete(backupPath, true); } else { MessageBox.Show("The backup is missing or something... mod won't really uninstall, do a file check plz"); } if (m.ToolInfo == null) { m.ToolInfo = ""; } m.ToolInfo.Replace(Mod.ModBrokenMessage, ""); InstalledMods.Remove(m); AvailableMods.Add(m); UpdateSettings(); }
/// <summary> /// Installs a mod into the game. /// </summary> public async Task <bool> Install(Mod m) { string mPath = Mod.InstallPath + m.Slug; string mBackupPath = Mod.BackupPath + m.Slug; if (!Directory.Exists(mBackupPath)) { Directory.CreateDirectory(mBackupPath); } Console.WriteLine("Install Mod"); // Before installing get the list of affected ice files and make sure no installed // mod uses the same files if (!ModCollision(m)) { m.ContentsMD5 = new Dictionary <string, string>(); foreach (var f in Directory.GetFiles(mPath)) { var fileName = Path.GetFileName(f); string from = mPath + "\\" + fileName; string destin = settings.PSO2Dir + "\\" + fileName; string backup = mBackupPath + "\\" + fileName; if (!File.Exists(from)) { MessageBox.Show("Mod file(s) are not found. please reinstall mod.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!File.Exists(destin)) { // backup target no match continue; } //Console.WriteLine ("Backup FROM: " + settings.PSO2Dir + "\\" + fileName + " TO: " + mBackupPath + "\\" + fileName); //Console.WriteLine ("Replace FROM: " + mPath + "\\" + fileName + " TO: " + settings.PSO2Dir + "\\" + fileName); if (!Mod.modSettingsFiles.Contains(fileName)) { var BackupTask = new Helpers.FileCopy(destin, backup); var ApplyModTask = new Helpers.FileCopy(from, destin); // This is done here because some mods will have dynamic/setup content so we create // the md5 hash over the file we copy on the pso2 dir m.ContentsMD5.Add(fileName, Helpers.CheckMD5(destin)); Console.WriteLine("Backup Task"); await Task.Run(() => BackupTask.StartCopy()); Console.WriteLine("Apply Mod Task"); await Task.Run(() => ApplyModTask.StartCopy()); } } InstalledMods.Add(m); AvailableMods.Remove(m); UpdateSettings(); } else { MessageBox.Show("Another installed mod is using the same files this mod will try to overwrite. Installation cancelled", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } return(true); }