private void SetProject(ProjectData.Project project) { if (project != null) { try { this.FileHashLookup = project.LoadListsFileNames(); this.TypeHashLookup = project.LoadListsTypeNames(); this.openDialog.InitialDirectory = project.InstallPath; this.saveKnownFileListDialog.InitialDirectory = project.ListsPath; } catch (Exception e) { MessageBox.Show( "There was an error while loading project data." + Environment.NewLine + Environment.NewLine + e.ToString() + Environment.NewLine + Environment.NewLine + "(You can press Ctrl+C to copy the contents of this dialog)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); project = null; } } if (project != this.Manager.ActiveProject) { this.Manager.ActiveProject = project; } this.projectComboBox.SelectedItem = project; }
public string Compose(ProjectData.HashList <uint> names) { return(string.Format( "{0},{1}", this._Value.X.ToString(CultureInfo.InvariantCulture), this._Value.Y.ToString(CultureInfo.InvariantCulture))); }
private void SetProject(ProjectData.Project project) { if (project != null) { try { this.openDialog.InitialDirectory = project.InstallPath; this.saveKnownFileListDialog.InitialDirectory = project.ListsPath; } catch (Exception e) { MessageBox.Show( "There was an error while loading project data." + Environment.NewLine + Environment.NewLine + e + Environment.NewLine + Environment.NewLine + "(You can press Ctrl+C to copy the contents of this dialog)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); project = null; } this._Hashes = project.LoadListsFileNames(); } // ReSharper disable RedundantCheckBeforeAssignment if (project != this._Manager.ActiveProject) // ReSharper restore RedundantCheckBeforeAssignment { this._Manager.ActiveProject = project; } this.projectComboBox.SelectedItem = project; }
public void ShowSaveProgress( IWin32Window owner, Stream archive, ArchiveTableFile table, List <uint> saving, ProjectData.HashList <uint> fileNames, string basePath, SaveAllSettings settings) { SaveAllInformation info; info.BasePath = basePath; info.Archive = archive; info.Table = table; info.Saving = saving; info.FileNames = fileNames; info.Settings = settings; this.progressBar.Value = 0; this.progressBar.Maximum = 100; this._SaveThread = new Thread(this.SaveAll); this._SaveThread.Start(info); this.ShowDialog(owner); }
private void OnReloadLists(object sender, EventArgs e) { this._Hashes = this._Manager.ActiveProject != null ? this._Manager.ActiveProject.LoadListsFileNames() : null; this.BuildFileTree(); }
private void OnReloadLists(object sender, EventArgs e) { if (this.Manager.ActiveProject != null) { this.FileHashLookup = this.Manager.ActiveProject.LoadListsFileNames(); this.TypeHashLookup = this.Manager.ActiveProject.LoadListsTypeNames(); } this.BuildFileTree(); }
private void OnReloadLists(object sender, EventArgs e) { if (this.Manager.ActiveProject != null) { this.Hashes = this.Manager.ActiveProject.LoadLists( "*.filelist", s => s.HashFileNameCRC32(), s => s.ToLowerInvariant()); } this.BuildFileTree(); }
private static string Compose(KeyValuePair <uint, uint> kv, ProjectData.HashList <uint> names) { string key = kv.Key.ToString("X8", CultureInfo.InvariantCulture); string value = kv.Value.ToString("X8", CultureInfo.InvariantCulture); if (names.Contains(kv.Key) && names[kv.Key].IndexOf('=') == -1 && names[kv.Key].IndexOf(',') == -1) { key = names[kv.Key]; } if (names.Contains(kv.Value) && names[kv.Value].IndexOf('=') == -1 && names[kv.Value].IndexOf(',') == -1) { value = names[kv.Value]; } if (key == value) { return(key); } return(String.Format( "{0}={1}", key, value)); }
public string Compose(ProjectData.HashList <uint> names) { string key = this._Value.Key.ToString("X8", CultureInfo.InvariantCulture); string value = this._Value.Value.ToString("X8", CultureInfo.InvariantCulture); if (names.Contains(this._Value.Key) && names[this._Value.Key].IndexOf('=') == -1) { key = "$" + names[this._Value.Key]; } if (names.Contains(this._Value.Value) && names[this._Value.Value].IndexOf('=') == -1) { value = "$" + names[this._Value.Value]; } if (key == value) { return(key); } return(String.Format( "{0}={1}", key, value)); }
public string Compose(ProjectData.HashList <uint> names) { return(String.Format( "{0},{1},{2},{3}, {4},{5},{6},{7}, {8},{9},{10},{11}, {12},{13},{14},{15}", this._Value.M11.ToString(CultureInfo.InvariantCulture), this._Value.M12.ToString(CultureInfo.InvariantCulture), this._Value.M13.ToString(CultureInfo.InvariantCulture), this._Value.M14.ToString(CultureInfo.InvariantCulture), this._Value.M21.ToString(CultureInfo.InvariantCulture), this._Value.M22.ToString(CultureInfo.InvariantCulture), this._Value.M23.ToString(CultureInfo.InvariantCulture), this._Value.M24.ToString(CultureInfo.InvariantCulture), this._Value.M31.ToString(CultureInfo.InvariantCulture), this._Value.M32.ToString(CultureInfo.InvariantCulture), this._Value.M33.ToString(CultureInfo.InvariantCulture), this._Value.M34.ToString(CultureInfo.InvariantCulture), this._Value.M41.ToString(CultureInfo.InvariantCulture), this._Value.M42.ToString(CultureInfo.InvariantCulture), this._Value.M43.ToString(CultureInfo.InvariantCulture), this._Value.M44.ToString(CultureInfo.InvariantCulture))); }
public void ShowSaveProgress( IWin32Window owner, Stream stream, ERF archive, IEnumerable <ERF.Entry> saving, ProjectData.HashList <ulong> fileNames, ProjectData.HashList <uint> typeNames, string basePath, SaveAllSettings settings) { this.Info.BasePath = basePath; this.Info.Stream = stream; this.Info.Archive = archive; this.Info.Saving = saving; this.Info.FileNames = fileNames; this.Info.TypeNames = typeNames; this.Info.Settings = settings; this.progressBar.Value = 0; this.progressBar.Maximum = 100; this.SaveThread = new Thread(new ParameterizedThreadStart(SaveAll)); this.ShowDialog(owner); }
public string Compose(ProjectData.HashList <uint> names) { return(this._Value); }
public FileNameHashComparer(ProjectData.HashList <uint> names) { this._FileNames = names; }
public EntryComparer(ProjectData.HashList <ulong> names) { this.FileNames = names; }
public static void Main(string[] args) { var mode = Mode.Unknown; Endian?endian = null; bool showHelp = false; string currentProject = null; var options = new OptionSet { { "e|export", "convert from binary to XML", v => { if (v != null) { mode = Mode.Export; } } }, { "i|import", "convert from XML to binary", v => { if (v != null) { mode = Mode.Import; } } }, { "l|little-endian", "write in little endian mode", v => { if (v != null) { endian = Endian.Little; } } }, { "b|big-endian", "write in big endian mode", v => { if (v != null) { endian = Endian.Big; } } }, { "p|project=", "override current project", v => currentProject = v }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } // detect! if (mode == Mode.Unknown && extras.Count >= 1) { var extension = Path.GetExtension(extras[0]); if (extension != null && extension.ToLowerInvariant() == ".xml") { mode = Mode.Import; } else { mode = Mode.Export; } } if (extras.Count < 1 || extras.Count > 2 || showHelp == true || mode == Mode.Unknown) { Console.WriteLine("Usage: {0} [OPTIONS]+ [-e] input_bin [output_xml]", GetExecutableName()); Console.WriteLine(" {0} [OPTIONS]+ [-i] input_xml [output_bin]", GetExecutableName()); Console.WriteLine("Convert a property file between binary and XML format."); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } var manager = ProjectData.Manager.Load(currentProject); if (manager.ActiveProject == null) { Console.WriteLine("Warning: no active project loaded."); } _Names = manager.LoadListsPropertyNames(); if (mode == Mode.Export) { if (endian.HasValue == false) { endian = manager.GetSetting("endian", Endian.Little); } string inputPath = extras[0]; string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, ".xml"); var extension = Path.GetExtension(inputPath); IPropertyFile propertyFile; FileFormat fileFormat; using (var input = File.OpenRead(inputPath)) { input.Seek(0, SeekOrigin.Begin); if (BlackboardPropertyFile.CheckMagic(input) == true) { fileFormat = FileFormat.Blackboard; input.Seek(0, SeekOrigin.Begin); propertyFile = new BlackboardPropertyFile() { Endian = endian.Value, }; propertyFile.Deserialize(input); } else { fileFormat = FileFormat.Raw; input.Seek(0, SeekOrigin.Begin); propertyFile = new RawPropertyFile() { Endian = endian.Value, }; propertyFile.Deserialize(input); } } using (var output = File.Create(outputPath)) { var settings = new XmlWriterSettings { Indent = true, IndentChars = "\t", CheckCharacters = false, }; var writer = XmlWriter.Create(output, settings); writer.WriteStartDocument(); writer.WriteStartElement("container"); if (extension != null) { writer.WriteAttributeString("extension", extension); } writer.WriteAttributeString("format", fileFormat.ToString()); writer.WriteAttributeString("endian", endian.Value.ToString()); foreach (var node in propertyFile.Nodes) { writer.WriteStartElement("object"); WriteObject(writer, node); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); } } else if (mode == Mode.Import) { string inputPath = extras[0]; IPropertyFile propertyFile; string extension; using (var input = File.OpenRead(inputPath)) { var doc = new XPathDocument(input); var nav = doc.CreateNavigator(); var root = nav.SelectSingleNode("/container"); if (root == null) { throw new FormatException(); } extension = root.GetAttribute("extension", ""); if (string.IsNullOrEmpty(extension) == true) { extension = ".bin"; } FileFormat fileFormat; var formatAttribute = root.GetAttribute("format", ""); if (string.IsNullOrEmpty(formatAttribute) == false) { if (Enum.TryParse(formatAttribute, out fileFormat) == false) { throw new FormatException(); } } else { fileFormat = FileFormat.Raw; } var endianAttribute = root.GetAttribute("endian", ""); if (endian.HasValue == false && string.IsNullOrEmpty(endianAttribute) == false) { Endian fileEndian; if (Enum.TryParse(endianAttribute, out fileEndian) == false) { throw new FormatException(); } endian = fileEndian; } else { endian = manager.GetSetting("endian", Endian.Little); } switch (fileFormat) { case FileFormat.Raw: { propertyFile = new RawPropertyFile() { Endian = endian.Value, }; break; } case FileFormat.Blackboard: { propertyFile = new BlackboardPropertyFile() { Endian = endian.Value, }; break; } default: { throw new NotSupportedException(); } } var nodes = root.Select("object"); while (nodes.MoveNext() == true) { propertyFile.Nodes.Add(ParseObject(nodes.Current)); } } string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, extension); using (var output = File.Create(outputPath)) { propertyFile.Serialize(output); } } else { throw new NotSupportedException(); } }
public string Compose(ProjectData.HashList <uint> name) { return(string.Join(",", this._Values.Select(v => v.ToString(CultureInfo.InvariantCulture)))); }
public NameComparer(ProjectData.HashList <uint> names) { this._Names = names; }
public FileNameHashComparer(ProjectData.HashList <uint> hashes) { this.Hashes = hashes; }
private static bool GetEntryName(Stream input, BigFile fat, Big.Entry entry, ProjectData.HashList <uint> hashes, bool extractUnknowns, bool onlyUnknowns, out string entryName) { entryName = hashes[entry.NameHash]; if (entryName == null) { if (extractUnknowns == false) { return(false); } string type; string extension; { var guess = new byte[64]; int read = 0; if (entry.CompressionScheme == Big.CompressionScheme.None) { if (entry.CompressedSize > 0) { input.Seek(entry.Offset, SeekOrigin.Begin); read = input.Read(guess, 0, (int)Math.Min(entry.CompressedSize, guess.Length)); } } else { using (var temp = new MemoryStream()) { EntryDecompression.Decompress(entry, input, temp); temp.Position = 0; read = temp.Read(guess, 0, (int)Math.Min(temp.Length, guess.Length)); } } var tuple = FileDetection.Detect(guess, Math.Min(guess.Length, read)); type = tuple != null ? tuple.Item1 : "unknown"; extension = tuple != null ? tuple.Item2 : null; } entryName = entry.NameHash.ToString("X8"); if (string.IsNullOrEmpty(extension) == false) { entryName = Path.ChangeExtension(entryName, "." + extension); } if (string.IsNullOrEmpty(type) == false) { entryName = Path.Combine(type, entryName); } entryName = Path.Combine("__UNKNOWN", entryName); } else { if (onlyUnknowns == true) { return(false); } entryName = FilterEntryName(entryName); } return(true); }
public static void Run(string currentProject, List <string> extras) { var manager = ProjectData.Manager.Load(currentProject); if (manager.ActiveProject == null) { Console.WriteLine("Warning: no active project loaded."); } _PropertyNames = manager.LoadListsPropertySetPropertyNames(); _SymbolNames = manager.LoadListsPropertySetSymbolNames(); string inputPath = extras[0]; string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null) + "_unpack"; Directory.CreateDirectory(outputPath); var inventory = new PropertySetInventory(); using (var input = File.OpenRead(inputPath)) { inventory.Deserialize(input, Endian.Little); } foreach (var item in inventory.Items) { if (item.Name.HashSymbol() == item.Id && _SymbolNames.Contains(item.Id) == false) { _SymbolNames.Add(item.Id, item.Name); } } var settings = new XmlWriterSettings { Indent = true, IndentChars = "\t", CheckCharacters = false, }; var indexPath = Path.Combine(outputPath, "@resource.xml"); using (var indexWriter = XmlWriter.Create(indexPath, settings)) { indexWriter.WriteStartDocument(); indexWriter.WriteStartElement("Resources"); foreach (var item in inventory.Items) { string xmlName; if (_SymbolNames.Contains(item.Id) == false) { if ((uint)item.Name.HashSymbol() != item.Id) { // todo: make this look up correct names from lists Console.WriteLine( "Hash of {0:X8} doesn't match hash of '{1}' -- name probably got truncated!", item.Id, item.Name); xmlName = string.Format(@"__TRUNCATED\{0}_{1:X8}.xml", item.Name, item.Id); } else { xmlName = item.Name + ".xml"; } } else { xmlName = _SymbolNames[item.Id] + ".xml"; } if (item.Id != item.Root.Name.Id) { throw new InvalidOperationException(); } indexWriter.WriteStartElement("Resource"); indexWriter.WriteAttributeString("name", item.Name); indexWriter.WriteAttributeString("flags", item.Flags.ToString()); indexWriter.WriteValue(xmlName); indexWriter.WriteEndElement(); var itemPath = Path.Combine(outputPath, xmlName); using (var itemWriter = XmlWriter.Create(itemPath, settings)) { itemWriter.WriteStartDocument(); itemWriter.WriteStartElement("Resource"); WritePropertySet(itemWriter, item.Root); itemWriter.WriteEndElement(); itemWriter.WriteEndDocument(); itemWriter.Flush(); } } indexWriter.WriteEndElement(); indexWriter.WriteEndDocument(); indexWriter.Flush(); } }
public string Compose(ProjectData.HashList <uint> names) { return(string.Join(", ", this._Values.Select(v => Compose(v, names)))); }
public string Compose(ProjectData.HashList <uint> names) { return(this._Value.ToString(CultureInfo.InvariantCulture)); }