private void menuCreateEmpty_Click(object sender, RoutedEventArgs e) { this.Wad?.Dispose(); this.Wad = new WADFile(); StringDictionary = new Dictionary <ulong, string>(); if ((bool)this.Config["GenerateWadDictionary"]) { try { WADHashGenerator.GenerateWADStrings(Logger, this.Wad, StringDictionary); } catch (Exception excp) { Logging.LogException(Logger, "Failed to Generate WAD String Dictionary", excp); } } this.previewExpander.IsEnabled = true; this.menuSave.IsEnabled = true; this.menuImportHashtable.IsEnabled = true; this.menuExportHashtable.IsEnabled = true; this.menuExportAll.IsEnabled = true; this.menuAddFile.IsEnabled = true; this.menuAddFileRedirection.IsEnabled = true; this.menuAddFolder.IsEnabled = true; this.CurrentlySelectedEntry = null; this.datagridWadEntries.ItemsSource = this.Wad.Entries; Logger.Info("Created empty WAD File"); }
public string convert(List <IFormFile> file) { if (null == file || file.Count != 1) { throw new ArgumentException("目前只支持解析单个wad文件"); } WADFile wad = new WADFile(file[0].OpenReadStream()); List <WadResult> wadResults = new List <WadResult>(); wadResults = WADHashGenerator.GenerateWADStrings(wad, wadResults); wad.Dispose(); GC.Collect(); return(ApiUtil.success(wadResults)); }
private void ExtractFile(string path) { try { var info = new FileInfo(path); var Wad = new WADFile(path); var stringDictionary = new Dictionary <ulong, string>(); WADHashGenerator.GenerateWADStrings(Wad, stringDictionary); var worker = ExtractWADEntries(info.Directory.FullName + "/" + System.IO.Path.GetFileNameWithoutExtension(path), Wad.Entries, stringDictionary); worker.RunWorkerCompleted += Worker_RunWorkerCompleted; } catch (Exception excp) { return; } }
private void OpenWADFile(string filePath) { try { this.Wad?.Dispose(); this.Wad = new WADFile(filePath); } catch (Exception excp) { Logging.LogException(Logger, "Failed to load WAD File: " + filePath, excp); return; } StringDictionary = new Dictionary <ulong, string>(); if ((bool)this.Config["GenerateWadDictionary"]) { try { WADHashGenerator.GenerateWADStrings(Logger, this.Wad, StringDictionary); } catch (Exception excp) { Logging.LogException(Logger, "Failed to Generate WAD String Dictionary", excp); } } this.previewExpander.IsEnabled = true; this.previewHandler.clearUp(); if (previewExpander.IsExpanded) { previewExpander.IsExpanded = false; } this.menuSave.IsEnabled = true; this.menuImportHashtable.IsEnabled = true; this.menuExportHashtable.IsEnabled = true; this.menuExportAll.IsEnabled = true; this.menuAddFile.IsEnabled = true; this.menuAddFileRedirection.IsEnabled = true; this.menuAddFolder.IsEnabled = true; this.CurrentlySelectedEntry = null; this.datagridWadEntries.ItemsSource = this.Wad.Entries; Logger.Info("Opened WAD File: " + filePath); }
public bool openWadFile(string path) { try { this.wadPath = path; this.activeWad = new WADFile(path); } catch (Exception ex) { // Logging.LogException(Logger, "Failed to load WAD File: " + filePath, excp); Console.WriteLine(ex.Message); return(false); } WADHashGenerator.GenerateWADStrings(this.activeWad, StringDictionary); var notKnown = 0; foreach (var entry in this.activeWad.Entries) { var found = false; foreach (var hash in StringDictionary) { if (entry.XXHash == hash.Key) { mapEntries.Add(hash.Value, entry); found = true; break; } } if (!found) { notKnown++; var extension = Utilities.GetLeagueFileExtensionType(entry.GetContent(true)); var name = "Unknown" + notKnown; name += "." + extension.ToString().ToLower(); mapEntries.Add(name, entry); } } return(true); }
private void menuCreateFromDirectory_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog() { ShowNewFolderButton = false }; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.Wad?.Dispose(); this.Wad = new WADFile(); StringDictionary = new Dictionary <ulong, string>(); DirectoryInfo directory = new DirectoryInfo(dialog.SelectedPath); using (XXHash64 xxHash = XXHash64.Create()) { foreach (FileInfo fileInfo in directory.EnumerateFiles("*", SearchOption.AllDirectories)) { string path = fileInfo.FullName.Substring(directory.FullName.Length + 1); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); bool hasUnknownPath = fileNameWithoutExtension.All(c => "ABCDEF0123456789".Contains(c)) && fileNameWithoutExtension.Length <= 16; if (hasUnknownPath) { ulong hashedPath = HexStringToUInt64(fileNameWithoutExtension); this.Wad.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true); } else { ulong hashedPath = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0); if (!StringDictionary.ContainsKey(hashedPath)) { StringDictionary.Add(hashedPath, path); } this.Wad.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true); } } } if ((bool)this.Config["GenerateWadDictionary"]) { try { WADHashGenerator.GenerateWADStrings(Logger, this.Wad, StringDictionary); } catch (Exception excp) { Logging.LogException(Logger, "Failed to Generate WAD String Dictionary", excp); } } this.previewExpander.IsEnabled = true; this.menuSave.IsEnabled = true; this.menuImportHashtable.IsEnabled = true; this.menuExportHashtable.IsEnabled = true; this.menuExportAll.IsEnabled = true; this.menuAddFile.IsEnabled = true; this.menuAddFileRedirection.IsEnabled = true; this.menuAddFolder.IsEnabled = true; this.CurrentlySelectedEntry = null; this.datagridWadEntries.ItemsSource = this.Wad.Entries; Logger.Info("Created WAD file from directory: " + dialog.SelectedPath); CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh(); } }
private void menuCreateFromDirectory_Click(object sender, RoutedEventArgs e) { using (CommonOpenFileDialog dialog = new CommonOpenFileDialog()) { dialog.IsFolderPicker = true; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { DirectoryInfo selectedDirectory = new DirectoryInfo(dialog.FileName); FileInfo[] files = selectedDirectory.GetFiles("*", SearchOption.AllDirectories); this.progressBarWadExtraction.Maximum = files.Length; this.IsEnabled = false; BackgroundWorker wadCreator = new BackgroundWorker { WorkerReportsProgress = true }; wadCreator.ProgressChanged += (sender2, args) => { this.progressBarWadExtraction.Value = args.ProgressPercentage; }; wadCreator.DoWork += (sender2, e2) => { this.WAD?.Dispose(); this.WAD = new WADFile((byte)(long)Config.Get("WadSaveMajorVersion"), (byte)(long)Config.Get("WadSaveMinorVersion")); StringDictionary = new Dictionary <ulong, string>(); int progress = 0; foreach (FileInfo fileInfo in files) { if (fileInfo.Name == "OBSIDIAN_PACKED_MAPPING.txt") { continue; } string path = fileInfo.FullName.Substring(selectedDirectory.FullName.Length + 1).Replace('\\', '/'); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); bool hasUnknownPath = fileNameWithoutExtension.Length == 16 && fileNameWithoutExtension.All(c => "ABCDEF0123456789".Contains(c)); if (hasUnknownPath) { ulong hashedPath = Convert.ToUInt64(fileNameWithoutExtension, 16); AddFile(hashedPath, File.ReadAllBytes(fileInfo.FullName), true, false); } else { AddFile(path, File.ReadAllBytes(fileInfo.FullName), true, false); } progress += 1; wadCreator.ReportProgress(progress); } if ((bool)Config.Get("GenerateWadDictionary")) { try { WADHashGenerator.GenerateWADStrings(Logger, this.WAD, StringDictionary); } catch (Exception excp) { Logging.LogException(Logger, "Failed to Generate WAD String Dictionary", excp); } } }; wadCreator.RunWorkerCompleted += (sender2, args) => { this.menuSave.IsEnabled = true; this.menuImportHashtable.IsEnabled = true; this.menuExportHashtable.IsEnabled = true; this.menuExportAll.IsEnabled = true; this.menuAddFile.IsEnabled = true; this.menuAddFileRedirection.IsEnabled = true; this.menuAddFolder.IsEnabled = true; this.CurrentlySelectedEntry = null; this.datagridWadEntries.ItemsSource = this.WAD.Entries; this.progressBarWadExtraction.Maximum = 100; this.progressBarWadExtraction.Value = 100; this.IsEnabled = true; Logger.Info("Created WAD file from directory: " + selectedDirectory.FullName); CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh(); }; wadCreator.RunWorkerAsync(); } } }