public ModSelectorDialog(Window owner, List <Mod> shownMods) { Owner = owner; AvailableMods.ReplaceAll(shownMods); LoadCommands(); InitializeComponent(); }
private void LoadExternalMods() { int i = 0; string[] terms = { ".patch" }; List <string> searchresults = ResourceUtil.directorySearchRecursive(Settings.Default.PatchPath, terms); if (searchresults != null) { foreach (string modpath in searchresults) { if (!modpath.ContainsCI("debug") && !modpath.ContainsCI("currentbuild")) { AvailableMods.Add(new Mod(modpath)); i++; } } } if (i > 0) { Trace.WriteLine(String.Format("Added {0} external mods", i)); } else { Trace.WriteLine("No external mods found"); } }
//public static bool AuthenticateMod(Stream outStream) //{ // foreach (IPlugin i in Plugins) // { // if (i != null && i.Name != null && i.Name == "SharpTune Vin Authentication") // return i.Run(outStream); // } // DialogResult res; // res = MessageBox.Show("Auth Plugin not found! Download?", "Plugin Missing!", MessageBoxButtons.YesNo); // if (res == DialogResult.Yes) // { // if (InstallAuth()) // { // SharpTuner.LoadPlugins(); // return AuthenticateMod(outStream); // } // } // return false; //} //private static Uri AuthDownloadUri = new Uri("http://sharptuning.com/wp-content/uploads/edd/2013/05/SharpTuneAuth.dll"); //private static bool InstallAuth() //{ // try // { // using (WebClient webClient = new WebClient()) // { // webClient.DownloadFile(AuthDownloadUri, Settings.Default.PluginPath + @"\SharpTuneAuth.dll"); // webClient.Dispose(); // } // return true; // } // catch (Exception E) // { // Trace.WriteLine(E.Message); // MessageBox.Show("Error downloading auth plugin!"); // return false; // } //} /// <summary> /// Gets mods from embedded resources /// </summary> private void LoadResourceMods() { int i = 0; var assembly = Assembly.GetExecutingAssembly(); string[] resources = assembly.GetManifestResourceNames(); foreach (string res in resources) { if (!res.ContainsCI(".patch")) { continue; } Stream stream = assembly.GetManifestResourceStream(res); AvailableMods.Add(new Mod(stream, res)); i++; } if (i > 0) { Trace.WriteLine(String.Format("Added {0} embedded mods", i)); } else { Trace.WriteLine("No embedded mods found"); } //int i = AvailableMods.Count; //ResourceSet ress = Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true); //ResourceManager rm = SharpTune.Properties.Resources.ResourceManager; //foreach (DictionaryEntry r in ress) //{ // MemoryStream stream = new MemoryStream((byte[])rm.GetObject(r.Key.ToString())); // //if (tempMod.TryCheckApplyMod(FilePath, FilePath + ".temp", 2, false)) // AvailableMods.Add(new Mod(stream, r.Key.ToString())); //} }
/// <summary> /// Installs/Uninstalls the selected mod /// </summary> public async void ToggleMod() { if (AvailableMods.Where(x => x.Slug == SelectedMod.Slug).Count() != 0) { await Install(SelectedMod); } else if (InstalledMods.Where(x => x.Slug == SelectedMod.Slug).Count() != 0) { await Uninstall(SelectedMod); } }
public void AddLocalMod(string path) { Mod m = new Mod(string.Empty, Path.GetFileNameWithoutExtension(path), DateTime.Now, string.Empty, string.Empty, string.Empty, string.Empty, Guid.NewGuid().ToString("N"), string.Empty, true); string modZipPath = zipPath + m.Slug + ".zip"; string modExtractPath = Mod.InstallPath + m.Slug + "\\"; File.Copy(path, modZipPath); UnpackMod(modZipPath, modExtractPath); AvailableMods.Add(m); UpdateSettings(); }
/// <summary> /// TODO FIX OR REMOVE THIS. Can't really embed mods as resources without source code anyway!! /// </summary> private static void LoadResourceMods() { int i = AvailableMods.Count; ResourceSet ress = Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true); ResourceManager rm = SharpTune.Properties.Resources.ResourceManager; foreach (DictionaryEntry r in ress) { MemoryStream stream = new MemoryStream((byte[])rm.GetObject(r.Key.ToString())); //if (tempMod.TryCheckApplyMod(FilePath, FilePath + ".temp", 2, false)) AvailableMods.Add(new Mod(stream, r.Key.ToString())); } }
/// <summary> /// Deletes any mod that has the same slug. /// </summary> public void Delete(string slug) { var available = AvailableMods.Where(x => x.Slug == slug); var installed = InstalledMods.Where(x => x.Slug == slug); if (available.Count() != 0) { Delete(available.First()); } if (installed.Count() != 0) { Delete(installed.First()); } }
/// <summary> /// Checks for updates on all mods. /// </summary> public async Task <bool> CheckForUpdates() { bool res = true; foreach (Mod m in AvailableMods.Concat(InstalledMods)) { res = await CheckForUpdates(m); if (!res) { break; } } return(res); }
/// <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> /// Deletes a mod. /// </summary> public async void Delete(Mod m) { string modPath = Mod.InstallPath + m.Slug; string imagePath = Mod.ImagePath + m.Thumbnail; if (InstalledMods.Where(x => x.Slug == m.Slug).Count() != 0) { await Uninstall(SelectedMod); } AvailableMods.Remove(m); UpdateSettings(); if (Directory.Exists(modPath)) { Directory.Delete(modPath, true); } if (File.Exists(m.Thumbnail)) { File.Delete(m.Thumbnail); } }
private static void LoadExternalMods() { int i = AvailableMods.Count; string[] terms = { ".patch" }; List <string> searchresults = ResourceUtil.directorySearchRecursive(Settings.Default.PatchPath, terms); if (searchresults == null) { Trace.WriteLine("No External Mods found"); } else { foreach (string modpath in searchresults) { if (!modpath.ContainsCI("debug") && !modpath.ContainsCI("currentbuild")) { AvailableMods.Add(new Mod(modpath)); } } } }
/// <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); }
/// <summary> /// Saves the settings file. /// </summary> private void UpdateSettings() { settings.AvailableMods = AvailableMods.ToList(); settings.InstalledMods = InstalledMods.ToList(); File.WriteAllText(Settings.SettingsPath, JsonSerializer.SerializeToString(settings)); }
/// <summary> /// From a provided REST API endpoint download a mod. /// </summary> public async Task DownloadMod(string url) { Downloading = true; string modZipPath; string modImagePath; string modExtractPath; string modString = string.Empty; using (WebClient wc = new WebClient()) { dynamic Data = new OnDownloadCompleteArgs(); OnDownloadStart?.Invoke(this, Data); wc.DownloadProgressChanged += WCDownloadPercentChanged; try { modString = await wc.DownloadStringTaskAsync(url); } catch (WebException ex) { Data.ErrorMessage = ex.Message; OnDownloadComplete?.Invoke(this, Data); return; } JsonObject json = JsonObject.Parse(modString); // Let's make sure the slug doesn't have weird stuff. json["slug"] = string.Join(" ", json["slug"].Split(Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToArray())); if (json["compatible"] != "Yes") { Data.ErrorMessage = Helpers._("Error.NotCompatible"); OnDownloadComplete?.Invoke(this, Data); return; } m = new Mod( json["id"], json.ArrayObjects("title") [0]["rendered"], DateTime.ParseExact(json["modified"].Replace("T", " "), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), json.ArrayObjects("content") [0]["rendered"], json["author_name"], url, json["File"], json["slug"], json["slug"] + ".jpg" ); modZipPath = zipPath + m.Slug + ".zip"; modExtractPath = Mod.InstallPath + m.Slug + "\\"; modImagePath = Mod.ImagePath + m.Thumbnail; // Cleanup previous versions and files. Delete(m.Slug); if (File.Exists(modZipPath)) { File.Delete(modZipPath); } if (Directory.Exists(modExtractPath)) { Directory.Delete(modExtractPath, true); } if (File.Exists(modImagePath)) { File.Delete(modImagePath); } // And start downloading stuff. try { await wc.DownloadFileTaskAsync(new System.Uri(json["image"]), modImagePath); } catch (WebException we) { Data.ErrorMessage = we.Message; OnDownloadComplete?.Invoke(this, Data); return; } try { await wc.DownloadFileTaskAsync(new System.Uri(m.File), modZipPath); } catch (WebException we) { Data.ErrorMessage = we.Message; OnDownloadComplete?.Invoke(this, Data); return; } UnpackMod(modZipPath, modExtractPath); AvailableMods.Add(m); Data.Success = true; OnDownloadComplete?.Invoke(this, Data); UpdateSettings(); } Downloading = false; }