private void buttonScan_Click(object sender, RoutedEventArgs e) { if (Directory.Exists(textBoxDir.Text)) { if (textBoxDir.Text != "") { string fileDir = textBoxDir.Text; string[] newFiles = Directory.GetFiles(fileDir, "*.new", SearchOption.AllDirectories); if (newFiles.Length > 0) { foreach (string s in newFiles) { string origFile = s.Replace(".new", ""); if (File.Exists(origFile)) { byte[] patch = XDelta3.CreatePatch(File.ReadAllBytes(s), File.ReadAllBytes(origFile)); File.WriteAllBytes(origFile + ".xdelta", patch); filesToArchive.Add(origFile + ".xdelta"); listBoxItems.Items.Add(origFile + ".xdelta"); } else { //new file, didnt exist in original game byte[] patch = XDelta3.CreatePatch(File.ReadAllBytes(s), new byte[0]); File.WriteAllBytes(origFile + ".xdeltanew", patch); filesToArchive.Add(origFile + ".xdeltanew"); listBoxItems.Items.Add(origFile + ".xdeltanew"); } } buttonScan.IsEnabled = false; buttonArchive.IsEnabled = true; } else { Application.Current.Windows.OfType <MainWindow>().Single() .ShowMessage("Error, no files ending in .new found!"); } } else { Application.Current.Windows.OfType <MainWindow>().Single() .ShowMessage("Please select a game..."); } } else { Application.Current.Windows.OfType <MainWindow>().Single() .ShowMessage("Game directory doesn't exist"); } }
private async void buttonDl_Click(object sender, RoutedEventArgs e) { /* * Ok this is the dumb part, writing steps to remind myself how this is meant to work.. * 1. download zip from gh * 2. extract zip in game folder root * 3. find all xdelta files * 4. patch all files * 5. ??? * 6. profit * * i don't think normal downloadcontrol will work for this one, it's more tailored for updates */ string gameRoot = Path.GetDirectoryName(_thisGame.GamePath); if (Directory.Exists(gameRoot)) { var patchZip = new DownloadWindow(_zipUrl, _modName, true); patchZip.Closed += (x, x2) => { if (patchZip.data == null) { return; } using (var memoryStream = new MemoryStream(patchZip.data)) using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Read)) { foreach (var entry in zip.Entries) { //remove TeknoParrotUIThumbnails-master/ var name = entry.FullName.Substring(entry.FullName.IndexOf('/') + 1); if (string.IsNullOrEmpty(name)) { continue; } Debug.WriteLine($"Extracting {name}"); try { using (var entryStream = entry.Open()) using (var dll = File.Create(gameRoot + "\\" + name)) { entryStream.CopyTo(dll); entryStream.Close(); } string xDeltaFile = gameRoot + "\\" + name; if (name.Contains(".xdeltanew")) { byte[] patchedFile = XDelta3.ApplyPatch(File.ReadAllBytes(xDeltaFile), new byte[0]); File.WriteAllBytes(xDeltaFile.Replace(".xdeltanew", ""), patchedFile); } else { byte[] patchedFile = XDelta3.ApplyPatch(File.ReadAllBytes(xDeltaFile), File.ReadAllBytes(xDeltaFile.Replace(".xdelta", ""))); File.WriteAllBytes(xDeltaFile.Replace(".xdelta", ""), patchedFile); } } catch (Exception ex) { Debug.WriteLine(ex.Message); // ignore..? } } } isDone = true; }; patchZip.Show(); await isItDone(); Application.Current.Windows.OfType <MainWindow>().Single() .ShowMessage("Mod downloaded and installed successfully!"); buttonDl.IsEnabled = false; _modMenu.installedGUIDs.Add(Path.GetFileNameWithoutExtension(_zipUrl)); WriteToXmlFile("InstalledMods.xml", _modMenu.installedGUIDs, false); } else { Application.Current.Windows.OfType <MainWindow>().Single() .ShowMessage("Game directory doesn't exist..."); } }