private string extractIros(string iroFile, string path) { bPreview.Enabled = false; _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(iroFile); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); string filter = path; string fn = ""; foreach (string file in iro.AllFileNames()) { if (!String.IsNullOrEmpty(filter) && (file.IndexOf(filter) < 0)) { continue; } byte[] data = iro.GetBytes(file); fn = System.IO.Path.Combine(System.IO.Path.GetTempPath(), file); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn)); System.IO.File.WriteAllBytes(fn, data); } sw.Stop(); bPreview.Enabled = true; return(fn); }
private void ProcessDownload(object state) { try { string source = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", File); _dest = System.IO.Path.Combine(Sys.Settings.LibraryLocation, File); byte[] sig = new byte[4]; using (var iro = new _7thWrapperLib.IrosArc(source, true)) { if (!iro.CheckValid()) { throw new Exception("IRO archive appears to be invalid: corrupted download?"); } if (!Controller.WaitForPatches()) { throw new Exception("Failed to acquire patches"); } int numPatch = Controller.PatchFiles.Count; int pDone = 0; foreach (string pfile in Controller.PatchFiles) { string patchfile = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", pfile); using (var patch = new _7thWrapperLib.IrosArc(patchfile)) { iro.ApplyPatch(patch, (d, _) => SetPCComplete((int)((100 / numPatch) * pDone + 100 * d / numPatch))); } pDone++; } } System.IO.File.Move(source, _dest); } catch (Exception e) { Error(e); return; } SetPCComplete(100); Complete(); }
void bw_Patch(object sender, DoWorkEventArgs e) { PatchOp patch = (PatchOp)e.Argument; using (var orig = new _7thWrapperLib.IrosArc(patch.OrigFile, true)) { using (var newiro = new _7thWrapperLib.IrosArc(patch.NewFile)) { using (var fs = new System.IO.FileStream(patch.SaveFile, System.IO.FileMode.Create)) _7thWrapperLib.IrosPatcher.Create(orig, newiro, fs, patch.Compress, IroProgress); } } }
public _7thWrapperLib.RuntimeMod GetRuntime(_7thWrapperLib.LoaderContext context) { var mod = Sys.Library.GetItem(ModID); if (mod == null) { return(null); } string location = System.IO.Path.Combine(Sys.Settings.LibraryLocation, mod.LatestInstalled.InstalledLocation); _7thWrapperLib.ModInfo modinfo = null; if (mod.LatestInstalled.InstalledLocation.EndsWith(".iro")) { using (var arc = new _7thWrapperLib.IrosArc(location)) { if (arc.HasFile("mod.xml")) { var doc = new System.Xml.XmlDocument(); doc.Load(arc.GetData("mod.xml")); modinfo = new _7thWrapperLib.ModInfo(doc, context); } } } else { string mfile = System.IO.Path.Combine(location, "mod.xml"); if (System.IO.File.Exists(mfile)) { modinfo = new _7thWrapperLib.ModInfo(mfile, context); } } modinfo = modinfo ?? new _7thWrapperLib.ModInfo(); foreach (var opt in modinfo.Options) { if (!Settings.Any(s => s.ID.Equals(opt.ID, StringComparison.InvariantCultureIgnoreCase))) { Settings.Add(new ProfileSetting() { ID = opt.ID, Value = opt.Default }); } } return(new _7thWrapperLib.RuntimeMod( location, modinfo.Conditionals.Where(f => IsActive(f.ActiveWhen)), modinfo.ModFolders.Where(f => IsActive(f.ActiveWhen)).Select(f => f.Folder), modinfo.LoadLibraries, modinfo.LoadAssemblies, modinfo.LoadPlugins )); }
void bw_DoWork(object sender, DoWorkEventArgs e) { IroOp io = e.Argument as IroOp; BackgroundWorker bw = sender as BackgroundWorker; using (var arc = new _7thWrapperLib.IrosArc(io.Iro)) { var files = arc.AllFileNames().ToList(); int count = 0; foreach (string file in files) { string path = System.IO.Path.Combine(io.Folder, file); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path)); System.IO.File.WriteAllBytes(path, arc.GetBytes(file)); count++; IroProgress(1.0 * count / files.Count, file); } } }
internal Task UnpackIro() { string pathToOutput = PathToOutputFolder; string pathToIro = PathToIroFile; IsUnpacking = true; Task unpackTask = Task.Factory.StartNew(() => { using (_7thWrapperLib.IrosArc arc = new _7thWrapperLib.IrosArc(pathToIro)) { List <string> files = arc.AllFileNames().ToList(); int count = 0; foreach (string file in files) { string path = Path.Combine(pathToOutput, file); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, arc.GetBytes(file)); count++; IroProgress(1.0 * count / files.Count, file); } } }); unpackTask.ContinueWith((result) => { IsUnpacking = false; ProgressValue = 0; if (result.IsFaulted) { Logger.Warn(result.Exception.GetBaseException()); StatusText = $"An error occured while unpacking: {result.Exception.GetBaseException().Message}"; return; } StatusText = "Unpacking complete!"; }); return(unpackTask); }
public System.IO.Stream GetData(string name) { string path = System.IO.Path.Combine(Sys.Settings.LibraryLocation, InstalledLocation); if (InstalledLocation.EndsWith(".iro", StringComparison.InvariantCultureIgnoreCase) && System.IO.File.Exists(path)) { using (var arc = new _7thWrapperLib.IrosArc(path)) return(arc.GetData(name)); } else { path = System.IO.Path.Combine(path, name); if (System.IO.File.Exists(path)) { return(new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read)); } } return(null); }
private void ProcessDownload(object state) { string patchfile = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", File); try { string source = System.IO.Path.Combine(Sys.Settings.LibraryLocation, Install.LatestInstalled.InstalledLocation); using (var iro = new _7thWrapperLib.IrosArc(source, true)) { using (var patch = new _7thWrapperLib.IrosArc(patchfile)) { iro.ApplyPatch(patch, (d, _) => SetPCComplete((int)(100 * d))); } } } catch (Exception e) { Error(e); return; } Sys.Library.QueuePendingDelete(new[] { patchfile }); SetPCComplete(100); Complete(); }
private void ProcessDownload(object state) { string patchfile = Path.Combine(Sys.Settings.LibraryLocation, "temp", Filename); try { if (Install == null) { Install = Sys.Library.GetItem(Mod.ID); if (Install == null) { // don't go any further since mod is not installed Error(new Exception($"{Mod.Name} not installed")); return; } } string source = Path.Combine(Sys.Settings.LibraryLocation, Install.LatestInstalled.InstalledLocation); using (var iro = new _7thWrapperLib.IrosArc(source, true)) { using (var patch = new _7thWrapperLib.IrosArc(patchfile)) { iro.ApplyPatch(patch, (d, msg) => { Sys.Message(new WMessage(msg, WMessageLogLevel.LogOnly)); SetPercentComplete((int)(100 * d)); }); } } File.Delete(patchfile); } catch (Exception e) { Error(e); return; } SetPercentComplete(100); Complete(); }
internal void PatchIro() { string pathToOriginalIro = PathToOriginalIroFile; string pathToNewIro = PathToNewIroFile; string iropFile = PathToIropFile; _7thWrapperLib.CompressType compressType = (_7thWrapperLib.CompressType)CompressionSelectedIndex; IsPatching = true; Task patchTask = Task.Factory.StartNew(() => { using (_7thWrapperLib.IrosArc orig = new _7thWrapperLib.IrosArc(pathToOriginalIro, true)) { using (_7thWrapperLib.IrosArc newiro = new _7thWrapperLib.IrosArc(pathToNewIro)) { using (var fs = new FileStream(iropFile, FileMode.Create)) _7thWrapperLib.IrosPatcher.Create(orig, newiro, fs, compressType, IroProgress); } } }); patchTask.ContinueWith((result) => { IsPatching = false; ProgressValue = 0; if (result.IsFaulted) { Logger.Warn(result.Exception.GetBaseException()); StatusText = $"{ResourceHelper.Get(StringKey.AnErrorOccuredWhilePatching)}: {result.Exception.GetBaseException().Message}"; return; } StatusText = ResourceHelper.Get(StringKey.PatchingComplete); }); }
static void Main(string[] args) { if (args.Length == 0) { System.Console.WriteLine(HELP); return; } _7thWrapperLib.RuntimeLog.Enabled = args.Any(s => s.Equals("/LOG", StringComparison.InvariantCultureIgnoreCase)); Action <double, string> onProgress = (d, s) => { Console.WriteLine(String.Format("{0}%: {1}", (int)(d * 100), s)); }; if (args[0].Equals("LIST", StringComparison.InvariantCultureIgnoreCase)) { _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(args[1]); foreach (string s in iro.GetInformation()) { Console.WriteLine(s); } } else if (args[0].Equals("CREATE", StringComparison.InvariantCultureIgnoreCase)) { List <_7thWrapperLib.IrosArc.ArchiveCreateEntry> entries = new List <_7thWrapperLib.IrosArc.ArchiveCreateEntry>(); string dir = args[2]; foreach (string file in System.IO.Directory.GetFiles(dir, "*", System.IO.SearchOption.AllDirectories)) { entries.Add(_7thWrapperLib.IrosArc.ArchiveCreateEntry.FromDisk(dir, file.Substring(dir.Length).Trim('/', '\\'))); } _7thWrapperLib.CompressType compress = (_7thWrapperLib.CompressType)Enum.Parse(typeof(_7thWrapperLib.CompressType), args[3]); using (var fs = new System.IO.FileStream(args[1], System.IO.FileMode.Create)) _7thWrapperLib.IrosArc.Create(fs, entries, _7thWrapperLib.ArchiveFlags.None, compress, onProgress ); } else if (args[0].Equals("EXTRACT", StringComparison.InvariantCultureIgnoreCase)) { _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(args[1]); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); string filter = args.Length > 3 ? args[3] : String.Empty; foreach (string file in iro.AllFileNames()) { if (!String.IsNullOrEmpty(filter) && (file.IndexOf(filter) < 0)) { continue; } Console.WriteLine("Writing " + file); byte[] data = iro.GetBytes(file); string fn = System.IO.Path.Combine(args[2], file); fn = fn.Replace("%", "___").Replace(":", "---"); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn)); System.IO.File.WriteAllBytes(fn, data); } sw.Stop(); Console.WriteLine("Done in " + (sw.ElapsedMilliseconds / 1000f) + " seconds"); } else if (args[0].Equals("MAKEPATCH", StringComparison.InvariantCultureIgnoreCase)) { _7thWrapperLib.IrosArc orig = new _7thWrapperLib.IrosArc(args[1]); _7thWrapperLib.IrosArc newarc = new _7thWrapperLib.IrosArc(args[2]); _7thWrapperLib.CompressType compress = (_7thWrapperLib.CompressType)Enum.Parse(typeof(_7thWrapperLib.CompressType), args[4]); using (var fs = new System.IO.FileStream(args[3], System.IO.FileMode.Create)) { _7thWrapperLib.IrosPatcher.Create(orig, newarc, fs, compress, onProgress); } } else if (args[0].Equals("APPLYPATCH", StringComparison.InvariantCultureIgnoreCase)) { _7thWrapperLib.IrosArc orig = new _7thWrapperLib.IrosArc(args[1], true); _7thWrapperLib.IrosArc patch = new _7thWrapperLib.IrosArc(args[2]); orig.ApplyPatch(patch, onProgress); } }
private void ProcessDownload(object state) { try { string source = System.IO.Path.Combine(Sys.Settings.LibraryLocation, "temp", File); _dest = System.IO.Path.Combine(Sys.Settings.LibraryLocation, File); byte[] sig = new byte[4]; using (var fs = new System.IO.FileStream(source, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { fs.Read(sig, 0, 4); int isig = BitConverter.ToInt32(sig, 0); if (isig == _7thWrapperLib.IrosArc.SIG) { //plain IRO file, just move into place fs.Close(); using (var iro = new _7thWrapperLib.IrosArc(source)) if (!iro.CheckValid()) { throw new Exception("IRO archive appears to be invalid: corrupted download?"); } SetPCComplete(50); System.IO.File.Copy(source, _dest, overwrite: true); System.IO.File.Delete(source); } else { var archive = ArchiveFactory.Open(fs); var iroEnt = archive.Entries.FirstOrDefault(e => System.IO.Path.GetExtension(e.Key).Equals(".iro", StringComparison.InvariantCultureIgnoreCase)); if (iroEnt != null) { SetPCComplete(50); iroEnt.WriteToFile(_dest); } else { //extract entire archive... if (_dest.EndsWith(".iro", StringComparison.InvariantCultureIgnoreCase)) { _dest = _dest.Substring(0, _dest.Length - 4); } var entries = archive.Entries.ToArray(); string extractTo = _dest; if (!String.IsNullOrEmpty(ExtractInto)) { extractTo = System.IO.Path.Combine(extractTo, ExtractInto); } System.IO.Directory.CreateDirectory(extractTo); using (var reader = archive.ExtractAllEntries()) { int count = 0; while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { string filepath = reader.Entry.Key.Replace('/', '\\'); if (String.IsNullOrEmpty(ExtractSubFolder) || filepath.StartsWith(ExtractSubFolder, StringComparison.InvariantCultureIgnoreCase)) { string path = System.IO.Path.Combine(extractTo, filepath.Substring(ExtractSubFolder.Length).TrimStart('\\', '/')); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path)); using (var fOut = new System.IO.FileStream(path, System.IO.FileMode.Create)) reader.WriteEntryTo(fOut); } count++; float prog = (float)count / (float)entries.Length; SetPCComplete((int)(50 * prog) + 50); // start at 50% go up to 100% } } } } fs.Close(); System.IO.File.Delete(source); } } } catch (Exception e) { Error(e); return; } SetPCComplete(100); Complete(); }
public static void ImportMod(string source, string name, bool iroMode, bool noCopy) { Mod m = new Mod() { Author = String.Empty, Description = "Imported mod", ID = Guid.NewGuid(), Link = String.Empty, Tags = new List <string>(), Name = name, LatestVersion = new ModVersion() { CompatibleGameVersions = GameVersions.All, Links = new List <string>(), PreviewImage = String.Empty, ReleaseDate = DateTime.Now, ReleaseNotes = String.Empty, Version = 1.00m, } }; string location; if (noCopy) { location = System.IO.Path.GetFileName(source); } else { location = String.Format("{0}_{1}", m.ID, name); } System.Xml.XmlDocument doc = null; Func <string, byte[]> getData = null; if (!iroMode) { if (!noCopy) { foreach (string file in System.IO.Directory.GetFiles(source, "*", System.IO.SearchOption.AllDirectories)) { string part = file.Substring(source.Length).Trim('\\', '/'); string dest = System.IO.Path.Combine(Sys.Settings.LibraryLocation, location, part); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(dest)); System.IO.File.Copy(file, dest, true); } } string mx = System.IO.Path.Combine(Sys.Settings.LibraryLocation, location, "mod.xml"); if (System.IO.File.Exists(mx)) { doc = new System.Xml.XmlDocument(); doc.Load(mx); } getData = s => { string file = System.IO.Path.Combine(Sys.Settings.LibraryLocation, location, s); if (System.IO.File.Exists(file)) { return(System.IO.File.ReadAllBytes(file)); } return(null); }; //System.IO.Directory.Move(txtFolder.Text, System.IO.Path.Combine(Sys.Settings.LibraryLocation, location)); } else { if (!noCopy) { location = location + ".iro"; System.IO.File.Copy(source, System.IO.Path.Combine(Sys.Settings.LibraryLocation, location), true); } var arc = new _7thWrapperLib.IrosArc(source); if (arc.HasFile("mod.xml")) { doc = new System.Xml.XmlDocument(); doc.Load(arc.GetData("mod.xml")); } getData = s => arc.HasFile(s) ? arc.GetBytes(s) : null; } if (doc != null) { m.Author = doc.SelectSingleNode("/ModInfo/Author").NodeTextS(); m.Link = doc.SelectSingleNode("/ModInfo/Link").NodeTextS(); m.Description = doc.SelectSingleNode("/ModInfo/Description").NodeTextS(); decimal ver; if (decimal.TryParse(doc.SelectSingleNode("/ModInfo/Version").NodeTextS().Replace(',', '.'), out ver)) { m.LatestVersion.Version = ver; } var pv = doc.SelectSingleNode("/ModInfo/PreviewFile"); if (pv != null) { byte[] data = getData(pv.InnerText); if (data != null) { string url = "iros://Preview/Auto/" + m.ID.ToString(); m.LatestVersion.PreviewImage = url; Sys.ImageCache.InsertManual(url, data); } } } Sys.Library.AddInstall(new InstalledItem() { CachedDetails = m, CachePreview = String.Empty, ModID = m.ID, UpdateType = UpdateType.Ignore, Versions = new List <InstalledVersion>() { new InstalledVersion() { VersionDetails = m.LatestVersion, InstalledLocation = location } }, }); }
/// <summary> /// Parses mod.xml from a folder or .iro and returns the <see cref="Mod"/> /// </summary> /// <param name="sourceFileOrFolder">absolute path to folder or .iro file </param> /// <param name="defaultModIfMissing"> default mod properties to use if the mod.xml file is not found </param> /// <returns></returns> public Mod ParseModXmlFromSource(string sourceFileOrFolder, Mod defaultModIfMissing = null) { if (defaultModIfMissing == null) { defaultModIfMissing = new Mod() { Author = String.Empty, Description = "Imported mod", Category = "Unknown", ID = ParseModGuidFromFileOrFolderName(sourceFileOrFolder), Link = String.Empty, Tags = new List <string>(), Name = "", LatestVersion = new ModVersion() { CompatibleGameVersions = GameVersions.All, Links = new List <string>(), PreviewImage = String.Empty, ReleaseDate = DateTime.Now, ReleaseNotes = String.Empty, Version = 1.00m, } }; } Mod parsedMod = Mod.CopyMod(defaultModIfMissing); if (string.IsNullOrWhiteSpace(sourceFileOrFolder)) { return(parsedMod); } if (!File.Exists(sourceFileOrFolder) && !Directory.Exists(sourceFileOrFolder)) { return(parsedMod); } bool isIroFile = sourceFileOrFolder.EndsWith(".iro"); System.Xml.XmlDocument doc = null; Func <string, byte[]> getImageData = null; _7thWrapperLib.IrosArc arc = null; string[] musicFiles = FF7FileLister.GetMusicFiles(); string[] movieFiles = FF7FileLister.GetMovieFiles().Keys.ToArray(); if (isIroFile) { RaiseProgressChanged("Getting mod.xml data from .iro", 10); arc = new _7thWrapperLib.IrosArc(sourceFileOrFolder, patchable: false, (i, fileCount) => { double newProgress = 10.0 + ((double)i / fileCount) * 30.0; RaiseProgressChanged($"Scanning .iro archive files {i} / {fileCount}", newProgress); }); if (arc.HasFile("mod.xml")) { doc = new System.Xml.XmlDocument(); doc.Load(arc.GetData("mod.xml")); } RaiseProgressChanged($"Scanning .iro archive files for movie and music files", 45); foreach (string file in arc.AllFileNames()) { if (musicFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase))) { parsedMod.ContainsMusic = true; } if (movieFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase))) { parsedMod.ContainsMovies = true; } if (parsedMod.ContainsMovies && parsedMod.ContainsMusic) { break; // break out of loop to stop scanning since confirmed both music and movie files exist in mod } } getImageData = s => { return(arc.HasFile(s) ? arc.GetBytes(s) : null); }; } else { string pathToModXml = Path.Combine(sourceFileOrFolder, "mod.xml"); RaiseProgressChanged("Getting mod.xml data from file", 10); if (File.Exists(pathToModXml)) { doc = new System.Xml.XmlDocument(); doc.Load(pathToModXml); } RaiseProgressChanged($"Scanning mod folder for movie and music files", 25); foreach (string file in FileUtils.GetAllFilesInDirectory(sourceFileOrFolder)) { if (musicFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase))) { parsedMod.ContainsMusic = true; } if (movieFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase))) { parsedMod.ContainsMovies = true; } if (parsedMod.ContainsMovies && parsedMod.ContainsMusic) { break; // break out of loop to stop scanning since confirmed both music and movie files exist in mod } } getImageData = s => { string file = Path.Combine(sourceFileOrFolder, s); if (File.Exists(file)) { return(File.ReadAllBytes(file)); } return(null); }; } if (doc != null) { RaiseProgressChanged("Parsing information from mod.xml", 50); //If mod.xml contains an ID GUID, then use that instead of generating random one string modidstr = doc.SelectSingleNode("/ModInfo/ID").NodeTextS(); if (!string.IsNullOrWhiteSpace(modidstr)) { try { parsedMod.ID = new Guid(modidstr); } catch (Exception e) { Sys.Message(new WMessage("Invalid GUID found for Mod ID ... Using guid from file/folder name (or new guid).", WMessageLogLevel.LogOnly, e)); parsedMod.ID = ParseModGuidFromFileOrFolderName(sourceFileOrFolder); } } parsedMod.Name = doc.SelectSingleNode("/ModInfo/Name").NodeTextS(); if (string.IsNullOrWhiteSpace(parsedMod.Name)) { parsedMod.Name = defaultModIfMissing.Name; } parsedMod.Author = doc.SelectSingleNode("/ModInfo/Author").NodeTextS(); if (string.IsNullOrWhiteSpace(parsedMod.Author)) { parsedMod.Author = defaultModIfMissing.Author; } parsedMod.Link = doc.SelectSingleNode("/ModInfo/Link").NodeTextS(); if (string.IsNullOrWhiteSpace(parsedMod.Link)) { parsedMod.Link = defaultModIfMissing.Link; } parsedMod.Description = doc.SelectSingleNode("/ModInfo/Description").NodeTextS(); if (string.IsNullOrWhiteSpace(parsedMod.Description)) { parsedMod.Description = defaultModIfMissing.Description; } parsedMod.Category = doc.SelectSingleNode("/ModInfo/Category").NodeTextS(); if (string.IsNullOrWhiteSpace(parsedMod.Category)) { parsedMod.Category = defaultModIfMissing.Category; } parsedMod.LatestVersion.ReleaseNotes = doc.SelectSingleNode("/ModInfo/ReleaseNotes").NodeTextS(); if (string.IsNullOrWhiteSpace(parsedMod.LatestVersion.ReleaseNotes)) { parsedMod.LatestVersion.ReleaseNotes = defaultModIfMissing.LatestVersion.ReleaseNotes; } if (DateTime.TryParse(doc.SelectSingleNode("/ModInfo/ReleaseDate").NodeTextS(), out DateTime parsedDate)) { parsedMod.LatestVersion.ReleaseDate = parsedDate; } else { parsedMod.LatestVersion.ReleaseDate = defaultModIfMissing.LatestVersion.ReleaseDate; } string versionText = doc.SelectSingleNode("/ModInfo/Version").NodeTextS().Replace(',', '.'); // in-case Xml has "1,7" format then replace with "1.7" if (decimal.TryParse(versionText, System.Globalization.NumberStyles.AllowDecimalPoint, new System.Globalization.CultureInfo(""), out decimal ver)) { parsedMod.LatestVersion.Version = ver; } else { parsedMod.LatestVersion.Version = defaultModIfMissing.LatestVersion.Version; } var pv = doc.SelectSingleNode("/ModInfo/PreviewFile"); if (pv != null) { // add the preview file to image cache and set the url prefixed with iros://Preview/Auto since it came from auto-import byte[] data = getImageData(pv.InnerText); if (data != null) { string url = $"iros://Preview/Auto/{parsedMod.ID}_{pv.InnerText.Replace('\\', '_')}"; parsedMod.LatestVersion.PreviewImage = url; Sys.ImageCache.InsertManual(url, data); } } } if (arc != null) { arc.Dispose(); } return(parsedMod); }
private void ProcessDownload(object state) { // check if already finished processing download and call Complete() if (HasProcessed) { SetPercentComplete?.Invoke(100); Complete(); return; } try { string source = Path.Combine(Sys.Settings.LibraryLocation, "temp", FileName); _dest = Path.Combine(Sys.Settings.LibraryLocation, FileName); byte[] sig = new byte[4]; int isig = 0; using (var fs = new FileStream(source, FileMode.Open, FileAccess.Read)) { fs.Read(sig, 0, 4); isig = BitConverter.ToInt32(sig, 0); fs.Close(); } if (isig == _7thWrapperLib.IrosArc.SIG) { //plain IRO file, just move into place using (var iro = new _7thWrapperLib.IrosArc(source)) if (!iro.CheckValid()) { throw new Exception("IRO archive appears to be invalid: corrupted download?"); } SetPercentComplete?.Invoke(50); File.Copy(source, _dest, overwrite: true); File.Delete(source); } else { using (var fs = new FileStream(source, FileMode.Open, FileAccess.Read)) { var archive = ArchiveFactory.Open(fs); var iroEnt = archive.Entries.FirstOrDefault(e => Path.GetExtension(e.Key).Equals(".iro", StringComparison.InvariantCultureIgnoreCase)); if (iroEnt != null) { SetPercentComplete?.Invoke(50); iroEnt.WriteToFile(_dest, new SharpCompress.Common.ExtractionOptions() { Overwrite = true }); } else { //extract entire archive... if (_dest.EndsWith(".iro", StringComparison.InvariantCultureIgnoreCase)) { _dest = _dest.Substring(0, _dest.Length - 4); } string extractTo = _dest; if (!String.IsNullOrEmpty(ExtractInto)) { extractTo = Path.Combine(extractTo, ExtractInto); } Directory.CreateDirectory(extractTo); using (var reader = archive.ExtractAllEntries()) { var entries = archive.Entries.ToArray(); int count = 0; while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(extractTo, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } count++; float prog = (float)count / (float)entries.Length; SetPercentComplete?.Invoke((int)(50 * prog) + 50); // start at 50% go up to 100% } } } fs.Close(); } File.Delete(source); } } catch (Exception e) { Error(e); return; } HasProcessed = true; // if reached this point then successfully processed the download with no error SetPercentComplete?.Invoke(100); Complete(); }