public override IEnumerable <string> Process(string fileName) { DatFormat reader = new DatFormat(); FastaFormat writer = new FastaFormat(); string result = FileUtils.ChangeExtension(fileName, ".fasta"); long fileLength = new FileInfo(fileName).Length; using (StreamReader sr = new StreamReader(fileName)) using (StreamWriter sw = new StreamWriter(result)) { Progress.SetRange(0, fileLength); Sequence seq; while ((seq = reader.ReadSequence(sr)) != null) { if (Progress.IsCancellationPending()) { throw new UserTerminatedException(); } Progress.SetPosition(sr.GetCharpos()); writer.WriteSequence(sw, seq); } } return(new string[] { result }); }
public static bool ReadProperties(ThingType thing, DatFormat format, BinaryReader reader) { if (format >= DatFormat.Format_1010) { if (!ReadProperties_1010_1093(thing, reader, format)) { return(false); } } return(true); }
public static bool WriteProperties(ThingType thing, DatFormat format, FlagsBinaryWriter writer) { if (format >= DatFormat.Format_1010) { if (!WriteProperties_1010_1093(thing, writer, format)) { return(false); } } return(true); }
public static bool ReadProperties(ThingType thing, DatFormat format, BinaryReader reader) { if (format == DatFormat.Format_1010 || format == DatFormat.Format_1050 || format == DatFormat.Format_1057) { if (!ReadProperties_1010_1057(thing, reader)) { return false; } } return true; }
public void CreateAndParseTest(string filename, DatFormat datFormat, int totalCount) { // For all filenames, add the local path for test data if (filename != null) { filename = Path.Combine(Environment.CurrentDirectory, "TestData", filename); } var datFile = Parser.CreateAndParse(filename, throwOnError: true); Assert.Equal(datFormat, datFile.Header.DatFormat); Assert.Equal(totalCount, datFile.Items.TotalCount); }
public ThingData(ThingType type, SpriteGroup sprites, DatFormat format) { if (type == null) { throw new ArgumentNullException("type"); } if (sprites == null) { throw new ArgumentNullException("sprites"); } this.type = type; this.sprites = sprites; this.Format = format; }
public ObjectData(ThingType type, SpriteGroup sprites, DatFormat format) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (sprites == null) { throw new ArgumentNullException(nameof(sprites)); } this.type = type; this.sprites = sprites; this.Format = format; }
/// <summary> /// Parse a DAT and return all found games and roms within /// </summary> /// <param name="datFile">Current DatFile object to add to</param> /// <param name="input">Name of the file to be parsed</param> /// <param name="indexId">Index ID for the DAT</param> /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param> /// <param name="keepext">True if original extension should be kept, false otherwise (default)</param> /// <param name="quotes">True if quotes are assumed in supported types (default), false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> public static void ParseInto( DatFile datFile, ParentablePath input, int indexId = 0, bool keep = false, bool keepext = false, bool quotes = true, bool statsOnly = false, bool throwOnError = true) { // Get the current path from the filename string currentPath = input.CurrentPath; // Check the file extension first as a safeguard if (!Utilities.HasValidDatExtension(currentPath)) { return; } // If the output filename isn't set already, get the internal filename datFile.Header.FileName = string.IsNullOrWhiteSpace(datFile.Header.FileName) ? (keepext ? Path.GetFileName(currentPath) : Path.GetFileNameWithoutExtension(currentPath)) : datFile.Header.FileName; // If the output type isn't set already, get the internal output type DatFormat currentPathFormat = GetDatFormat(currentPath); datFile.Header.DatFormat = datFile.Header.DatFormat == 0 ? currentPathFormat : datFile.Header.DatFormat; datFile.Items.SetBucketedBy(ItemKey.CRC); // Setting this because it can reduce issues later InternalStopwatch watch = new InternalStopwatch($"Parsing '{currentPath}' into internal DAT"); // Now parse the correct type of DAT try { var parsingDatFile = DatFile.Create(currentPathFormat, datFile, quotes); parsingDatFile?.ParseFile(currentPath, indexId, keep, statsOnly: statsOnly, throwOnError: throwOnError); } catch (Exception ex) when(!throwOnError) { logger.Error(ex, $"Error with file '{currentPath}'"); } watch.Stop(); }
/// <summary> /// Wrap splitting a DAT by any known type /// </summary> /// <param name="inputs">List of inputs to be used</param> /// <param name="outDir">Output directory for the split files</param> /// <param name="inplace">True if files should be written to the source folders, false otherwise</param> /// <param name="datFormat">DatFormat to be used for outputting the DAT</param> /// <param name="splittingMode">Type of split to perform, if any</param> /// <param name="exta">First extension to split on (Extension Split only)</param> /// <param name="extb">Second extension to split on (Extension Split only)</param> /// <param name="shortname">True if short filenames should be used, false otherwise (Level Split only)</param> /// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise (Level Split only)</param> /// <param name="radix">Long value representing the split point (Size Split only)</param> private static void InitSplit( List <string> inputs, string outDir, bool inplace, DatFormat datFormat, SplittingMode splittingMode, List <string> exta, List <string> extb, bool shortname, bool basedat, long radix) { DatFile datfile = new DatFile(); datfile.DatFormat = datFormat; datfile.DetermineSplitType(inputs, outDir, inplace, splittingMode, exta, extb, shortname, basedat, radix); }
public void CreateOutFileNamesTest(DatFormat datFormat, string extension) { // Create the empty DatHeader var datHeader = new DatHeader { DatFormat = datFormat, FileName = "test.dat", }; // Invoke the method string outDir = "C:\\Test"; var actual = datHeader.CreateOutFileNames(outDir, overwrite: true); // Check the result string expected = $"{outDir}\\test.{extension}"; Assert.Single(actual); Assert.Equal(expected, actual[datFormat]); }
private static bool WriteProperties_1010_1093(ThingType thing, FlagsBinaryWriter writer, DatFormat format) { if (thing.Category == ThingCategory.Item) { if (thing.StackOrder == StackOrder.Ground) { writer.Write(DatFlags1010.Ground); writer.Write(thing.GroundSpeed); } else if (thing.StackOrder == StackOrder.Border) { writer.Write(DatFlags1010.GroundBorder); } else if (thing.StackOrder == StackOrder.Bottom) { writer.Write(DatFlags1010.OnBottom); } else if (thing.StackOrder == StackOrder.Top) { writer.Write(DatFlags1010.OnTop); } if (thing.IsContainer) { writer.Write(DatFlags1010.Container); } if (thing.Stackable) { writer.Write(DatFlags1010.Stackable); } if (thing.ForceUse) { writer.Write(DatFlags1010.ForceUse); } if (thing.MultiUse) { writer.Write(DatFlags1010.MultiUse); } if (thing.Writable) { writer.Write(DatFlags1010.Writable); writer.Write(thing.MaxTextLength); } if (thing.WritableOnce) { writer.Write(DatFlags1010.WritableOnce); writer.Write(thing.MaxTextLength); } if (thing.IsFluidContainer) { writer.Write(DatFlags1010.FluidContainer); } if (thing.IsFluid) { writer.Write(DatFlags1010.Fluid); } if (thing.Unpassable) { writer.Write(DatFlags1010.IsUnpassable); } if (thing.Unmovable) { writer.Write(DatFlags1010.IsUnmovable); } if (thing.BlockMissiles) { writer.Write(DatFlags1010.BlockMissiles); } if (thing.BlockPathfinder) { writer.Write(DatFlags1010.BlockPathfinder); } if (thing.NoMoveAnimation) { writer.Write(DatFlags1010.NoMoveAnimation); } if (thing.Pickupable) { writer.Write(DatFlags1010.Pickupable); } if (thing.Hangable) { writer.Write(DatFlags1010.Hangable); } if (thing.HookSouth) { writer.Write(DatFlags1010.HookSouth); } if (thing.HookEast) { writer.Write(DatFlags1010.HookEast); } if (thing.Rotatable) { writer.Write(DatFlags1010.Rotatable); } if (thing.DontHide) { writer.Write(DatFlags1010.DontHide); } if (thing.Translucent) { writer.Write(DatFlags1010.Translucent); } if (thing.HasElevation) { writer.Write(DatFlags1010.HasElevation); writer.Write(thing.Elevation); } if (thing.LyingObject) { writer.Write(DatFlags1010.LyingObject); } if (thing.Minimap) { writer.Write(DatFlags1010.Minimap); writer.Write(thing.MinimapColor); } if (thing.IsLensHelp) { writer.Write(DatFlags1010.LensHelp); writer.Write(thing.LensHelp); } if (thing.FullGround) { writer.Write(DatFlags1010.FullGround); } if (thing.IgnoreLook) { writer.Write(DatFlags1010.IgnoreLook); } if (thing.IsCloth) { writer.Write(DatFlags1010.Cloth); writer.Write((ushort)thing.ClothSlot); } if (thing.IsMarketItem) { writer.Write(DatFlags1010.Market); writer.Write((ushort)thing.MarketCategory); writer.Write(thing.MarketTradeAs); writer.Write(thing.MarketShowAs); writer.Write((ushort)thing.MarketName.Length); writer.Write(Encoding.Default.GetBytes(thing.MarketName)); writer.Write(thing.MarketRestrictVocation); writer.Write(thing.MarketRestrictLevel); } if (thing.HasAction) { writer.Write(DatFlags1010.DefaultAction); writer.Write((ushort)thing.DefaultAction); } if (format >= DatFormat.Format_1092) { if (thing.Wrappable) { writer.Write(DatFlags1010.Wrappable); } if (thing.Unwrappable) { writer.Write(DatFlags1010.Unwrappable); } } if (thing.Usable) { writer.Write(DatFlags1010.Usable); } } if (thing.AnimateAlways) { writer.Write(DatFlags1010.AnimateAlways); } if (thing.HasLight) { writer.Write(DatFlags1010.HasLight); writer.Write(thing.LightLevel); writer.Write(thing.LightColor); } if (thing.HasOffset) { writer.Write(DatFlags1010.HasOffset); writer.Write(thing.OffsetX); writer.Write(thing.OffsetY); } if (thing.IsTopEffect && format >= DatFormat.Format_1093) { writer.Write(DatFlags1010.TopEffect); } // close flags writer.Write(DatFlags1010.LastFlag); return(true); }
private static bool ReadProperties_1010_1093(ThingType thing, BinaryReader reader, DatFormat format) { DatFlags1010 flag; do { flag = (DatFlags1010)reader.ReadByte(); if (flag == DatFlags1010.LastFlag) { break; } switch (flag) { case DatFlags1010.Ground: // 0x00 thing.StackOrder = StackOrder.Ground; thing.GroundSpeed = reader.ReadUInt16(); break; case DatFlags1010.GroundBorder: // 0x01 thing.StackOrder = StackOrder.Border; break; case DatFlags1010.OnBottom: // 0x02 thing.StackOrder = StackOrder.Bottom; break; case DatFlags1010.OnTop: // 0x03 thing.StackOrder = StackOrder.Top; break; case DatFlags1010.Container: // 0x04 thing.IsContainer = true; break; case DatFlags1010.Stackable: thing.Stackable = true; break; case DatFlags1010.ForceUse: thing.ForceUse = true; break; case DatFlags1010.MultiUse: thing.MultiUse = true; break; case DatFlags1010.Writable: thing.Writable = true; thing.MaxTextLength = reader.ReadUInt16(); break; case DatFlags1010.WritableOnce: thing.WritableOnce = true; thing.MaxTextLength = reader.ReadUInt16(); break; case DatFlags1010.FluidContainer: thing.IsFluidContainer = true; break; case DatFlags1010.Fluid: thing.IsFluid = true; break; case DatFlags1010.IsUnpassable: thing.Unpassable = true; break; case DatFlags1010.IsUnmovable: thing.Unmovable = true; break; case DatFlags1010.BlockMissiles: thing.BlockMissiles = true; break; case DatFlags1010.BlockPathfinder: thing.BlockPathfinder = true; break; case DatFlags1010.NoMoveAnimation: // 0x10 thing.NoMoveAnimation = true; break; case DatFlags1010.Pickupable: thing.Pickupable = true; break; case DatFlags1010.Hangable: thing.Hangable = true; break; case DatFlags1010.HookSouth: thing.HookSouth = true; break; case DatFlags1010.HookEast: thing.HookEast = true; break; case DatFlags1010.Rotatable: thing.Rotatable = true; break; case DatFlags1010.HasLight: thing.HasLight = true; thing.LightLevel = reader.ReadUInt16(); thing.LightColor = reader.ReadUInt16(); break; case DatFlags1010.DontHide: thing.DontHide = true; break; case DatFlags1010.Translucent: thing.Translucent = true; break; case DatFlags1010.HasOffset: thing.HasOffset = true; thing.OffsetX = reader.ReadUInt16(); thing.OffsetY = reader.ReadUInt16(); break; case DatFlags1010.HasElevation: thing.HasElevation = true; thing.Elevation = reader.ReadUInt16(); break; case DatFlags1010.LyingObject: thing.LyingObject = true; break; case DatFlags1010.Minimap: thing.Minimap = true; thing.MinimapColor = reader.ReadUInt16(); break; case DatFlags1010.AnimateAlways: thing.AnimateAlways = true; break; case DatFlags1010.LensHelp: thing.IsLensHelp = true; thing.LensHelp = reader.ReadUInt16(); break; case DatFlags1010.FullGround: thing.FullGround = true; break; case DatFlags1010.IgnoreLook: thing.IgnoreLook = true; break; case DatFlags1010.Cloth: thing.IsCloth = true; thing.ClothSlot = (ClothSlot)reader.ReadUInt16(); break; case DatFlags1010.Market: thing.IsMarketItem = true; thing.MarketCategory = (MarketCategory)reader.ReadUInt16(); thing.MarketTradeAs = reader.ReadUInt16(); thing.MarketShowAs = reader.ReadUInt16(); ushort nameLength = reader.ReadUInt16(); byte[] buffer = reader.ReadBytes(nameLength); thing.MarketName = Encoding.Default.GetString(buffer, 0, buffer.Length); thing.MarketRestrictVocation = reader.ReadUInt16(); thing.MarketRestrictLevel = reader.ReadUInt16(); break; case DatFlags1010.DefaultAction: thing.HasAction = true; thing.DefaultAction = (DefaultAction)reader.ReadUInt16(); break; case DatFlags1010.Wrappable: thing.Wrappable = true; break; case DatFlags1010.Unwrappable: thing.Unwrappable = true; break; case DatFlags1010.TopEffect: thing.IsTopEffect = true; break; case DatFlags1010.Usable: thing.Usable = true; break; default: throw new Exception(string.Format("Error while parsing, unknown flag 0x{0:X} at object id {1}, category {2}.", flag, thing.ID, thing.Category)); } }while (flag != DatFlags1010.LastFlag); return(true); }
/// <summary> /// Entry class for the SabreTools application /// </summary> /// <param name="args">String array representing command line parameters</param> public static void Main(string[] args) { // Perform initial setup and verification Globals.Logger = new Logger(true, "sabretools.log"); // Create a new Help object for this program _help = SabreTools.RetrieveHelp(); // Get the location of the script tag, if it exists int scriptLocation = (new List <string>(args)).IndexOf("--script"); // If output is being redirected or we are in script mode, don't allow clear screens if (!Console.IsOutputRedirected && scriptLocation == -1) { Console.Clear(); Build.PrepareConsole("SabreTools"); } // Now we remove the script tag because it messes things up if (scriptLocation > -1) { List <string> newargs = new List <string>(args); newargs.RemoveAt(scriptLocation); args = newargs.ToArray(); } // Credits take precidence over all if ((new List <string>(args)).Contains("--credits")) { _help.OutputCredits(); Globals.Logger.Close(); return; } // If there's no arguments, show help if (args.Length == 0) { _help.OutputGenericHelp(); Globals.Logger.Close(); return; } // User flags bool addBlankFiles = false, addFileDates = false, archivesAsFiles = false, basedat = false, chdsAsFiles = false, cleanGameNames = false, copyFiles = false, delete = false, depot = false, descAsName = false, hashOnly = false, individual = false, inplace = false, inverse = false, noAutomaticDate = false, nostore = false, onlySame = false, quickScan = false, removeUnicode = false, showBaddumpColumn = false, showNodumpColumn = false, shortname = false, skipFirstOutput = false, updateDat = false; Hash omitFromScan = Hash.DeepHashes;// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually OutputFormat outputFormat = OutputFormat.Folder; ReplaceMode replaceMode = ReplaceMode.None; SkipFileType skipFileType = SkipFileType.None; SplittingMode splittingMode = SplittingMode.None; SplitType splitType = SplitType.None; StatReportFormat statDatFormat = StatReportFormat.None; UpdateMode updateMode = UpdateMode.None; // User inputs int gz = 1, rar = 1, sevenzip = 1, zip = 1; long radix = 0; string outDir = null, tempDir = ""; DatHeader datHeader = new DatHeader(); Filter filter = new Filter(); List <string> basePaths = new List <string>(); List <string> datfiles = new List <string>(); List <string> exta = new List <string>(); List <string> extb = new List <string>(); List <string> inputs = new List <string>(); List <Field> updateFields = new List <Field>(); // Get the first argument as a feature flag string feature = args[0]; // Verify that the flag is valid if (!_help.TopLevelFlag(feature)) { Globals.Logger.User("'{0}' is not valid feature flag", feature); _help.OutputIndividualFeature(feature); Globals.Logger.Close(); return; } // Now get the proper name for the feature feature = _help.GetFeatureName(feature); // If we had the help feature first if (feature == "Help") { // If we had something else after help if (args.Length > 1) { _help.OutputIndividualFeature(args[1]); Globals.Logger.Close(); return; } // Otherwise, show generic help else { _help.OutputGenericHelp(); Globals.Logger.Close(); return; } } else if (feature == "Help (Detailed)") { // If we had something else after help if (args.Length > 1) { _help.OutputIndividualFeature(args[1], includeLongDescription: true); Globals.Logger.Close(); return; } // Otherwise, show generic help else { _help.OutputAllHelp(); Globals.Logger.Close(); return; } } // Now verify that all other flags are valid for (int i = 1; i < args.Length; i++) { // Verify that the current flag is proper for the feature if (!_help[feature].ValidateInput(args[i])) { Globals.Logger.Error("Invalid input detected: {0}", args[i]); _help.OutputIndividualFeature(feature); Globals.Logger.Close(); return; } // Special precautions for files and directories if (File.Exists(args[i]) || Directory.Exists(args[i])) { inputs.Add(args[i]); } } // Now loop through all inputs Dictionary <string, Feature> features = _help.GetEnabledFeatures(); foreach (KeyValuePair <string, Feature> feat in features) { // Check all of the flag names and translate to arguments switch (feat.Key) { #region User Flags case "add-blank-files": addBlankFiles = true; break; case "add-date": addFileDates = true; break; case "archives-as-files": archivesAsFiles = true; break; case "baddump-column": showBaddumpColumn = true; break; case "base": basedat = true; break; case "base-replace": updateMode |= UpdateMode.BaseReplace; break; case "chds-as-Files": chdsAsFiles = true; break; case "copy-files": copyFiles = true; break; case "clean": cleanGameNames = true; break; case "dat-device-non-merged": splitType = SplitType.DeviceNonMerged; break; case "dat-full-non-merged": splitType = SplitType.FullNonMerged; break; case "dat-merged": splitType = SplitType.Merged; break; case "dat-non-merged": splitType = SplitType.NonMerged; break; case "dat-split": splitType = SplitType.Split; break; case "dedup": datHeader.DedupeRoms = DedupeType.Full; break; case "delete": delete = true; break; case "depot": depot = true; break; case "depreciated": // Remove the Logiqx standard output if this is included if ((datHeader.DatFormat & DatFormat.Logiqx) != 0) { datHeader.DatFormat &= ~DatFormat.Logiqx; } datHeader.DatFormat |= DatFormat.LogiqxDepreciated; break; case "description-as-name": descAsName = true; break; case "diff-against": updateMode |= UpdateMode.DiffAgainst; break; case "diff-all": updateMode |= UpdateMode.AllDiffs; break; case "diff-cascade": updateMode |= UpdateMode.DiffCascade; break; case "diff-duplicates": updateMode |= UpdateMode.DiffDupesOnly; break; case "diff-individuals": updateMode |= UpdateMode.DiffIndividualsOnly; break; case "diff-no-duplicates": updateMode |= UpdateMode.DiffNoDupesOnly; break; case "diff-reverse-cascade": updateMode |= UpdateMode.DiffReverseCascade; break; case "exclude-of": Globals.Logger.User("This flag '{0}' is depreciated, please use {1} instead", feat.Key, String.Join(", ", _excludeFieldListInput.Flags)); datHeader.ExcludeFields[(int)Field.CloneOf] = true; datHeader.ExcludeFields[(int)Field.MachineType] = true; datHeader.ExcludeFields[(int)Field.RomOf] = true; datHeader.ExcludeFields[(int)Field.Runnable] = true; datHeader.ExcludeFields[(int)Field.SampleOf] = true; break; case "extension": splittingMode |= SplittingMode.Extension; break; case "game-dedup": datHeader.DedupeRoms = DedupeType.Game; break; case "game-prefix": datHeader.GameName = true; break; case "hash": splittingMode |= SplittingMode.Hash; break; case "hash-only": hashOnly = true; break; case "individual": individual = true; break; case "inplace": inplace = true; break; case "inverse": inverse = true; break; case "keep-empty-games": datHeader.KeepEmptyGames = true; break; case "level": splittingMode |= SplittingMode.Level; break; case "match-of-tags": filter.IncludeOfInGame.Neutral = true; break; case "merge": updateMode |= UpdateMode.Merge; break; case "no-automatic-date": noAutomaticDate = true; break; case "nodump-column": showNodumpColumn = true; break; case "not-runnable": filter.Runnable.Neutral = false; break; case "no-store-header": nostore = true; break; case "one-rom-per-game": datHeader.OneRom = true; break; case "only-same": onlySame = true; break; case "quick": quickScan = true; break; case "quotes": datHeader.Quotes = true; break; case "remove-extensions": datHeader.RemoveExtension = true; break; case "remove-md5": Globals.Logger.User("This flag '{0}' is depreciated, please use {1} instead", feat.Key, String.Join(", ", _excludeFieldListInput.Flags)); datHeader.ExcludeFields[(int)Field.MD5] = true; break; case "remove-sha1": Globals.Logger.User("This flag '{0}' is depreciated, please use {1} instead", feat.Key, String.Join(", ", _excludeFieldListInput.Flags)); datHeader.ExcludeFields[(int)Field.SHA1] = true; break; case "remove-sha256": Globals.Logger.User("This flag '{0}' is depreciated, please use {1} instead", feat.Key, String.Join(", ", _excludeFieldListInput.Flags)); datHeader.ExcludeFields[(int)Field.SHA256] = true; break; case "remove-sha384": Globals.Logger.User("This flag '{0}' is depreciated, please use {1} instead", feat.Key, String.Join(", ", _excludeFieldListInput.Flags)); datHeader.ExcludeFields[(int)Field.SHA384] = true; break; case "remove-sha512": Globals.Logger.User("This flag '{0}' is depreciated, please use {1} instead", feat.Key, String.Join(", ", _excludeFieldListInput.Flags)); datHeader.ExcludeFields[(int)Field.SHA512] = true; break; case "remove-unicode": removeUnicode = true; break; case "reverse-base-name": updateMode |= UpdateMode.ReverseBaseReplace; break; case "romba": datHeader.Romba = true; break; case "roms": datHeader.UseRomName = true; break; case "runnable": filter.Runnable.Neutral = true; break; case "scan-all": sevenzip = 0; gz = 0; rar = 0; zip = 0; break; case "scene-date-strip": datHeader.SceneDateStrip = true; break; case "short": shortname = true; break; case "size": splittingMode |= SplittingMode.Size; break; case "skip-archives": skipFileType = SkipFileType.Archive; break; case "skip-files": skipFileType = SkipFileType.File; break; case "skip-first-output": skipFirstOutput = true; break; case "skip-md5": omitFromScan |= Hash.MD5; break; case "skip-sha1": omitFromScan |= Hash.SHA1; break; case "skip-sha256": omitFromScan &= ~Hash.SHA256; // This needs to be inverted later break; case "skip-sha384": omitFromScan &= ~Hash.SHA384; // This needs to be inverted later break; case "skip-sha512": omitFromScan &= ~Hash.SHA512; // This needs to be inverted later break; case "single-set": filter.Single.Neutral = true; break; case "superdat": datHeader.Type = "SuperDAT"; break; case "tar": outputFormat = OutputFormat.TapeArchive; break; case "torrent-7zip": outputFormat = OutputFormat.Torrent7Zip; break; case "torrent-gzip": outputFormat = OutputFormat.TorrentGzip; break; case "torrent-lrzip": outputFormat = OutputFormat.TorrentLRZip; break; case "torrent-lz4": outputFormat = OutputFormat.TorrentLZ4; break; case "torrent-rar": outputFormat = OutputFormat.TorrentRar; break; case "torrent-xz": outputFormat = OutputFormat.TorrentXZ; break; case "torrent-zip": outputFormat = OutputFormat.TorrentZip; break; case "torrent-zpaq": outputFormat = OutputFormat.TorrentZPAQ; break; case "torrent-zstd": outputFormat = OutputFormat.TorrentZstd; break; case "trim": filter.Trim.Neutral = true; break; case "type": splittingMode |= SplittingMode.Type; break; case "update-dat": updateDat = true; break; case "update-description": replaceMode |= ReplaceMode.Description; break; case "update-game-type": replaceMode |= ReplaceMode.MachineType; break; case "update-hashes": replaceMode |= ReplaceMode.Hash; break; case "update-manufacturer": replaceMode |= ReplaceMode.Manufacturer; break; case "update-names": replaceMode |= ReplaceMode.ItemName; break; case "update-parents": replaceMode |= ReplaceMode.Parents; break; case "update-year": replaceMode |= ReplaceMode.Year; break; #endregion #region User Int32 Inputs case "7z": sevenzip = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; break; case "gz": gz = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; break; case "rar": rar = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; break; case "threads": int val = (int)feat.Value.GetValue(); if (val != Int32.MinValue) { Globals.MaxThreads = val; } break; case "zip": zip = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; break; #endregion #region User Int64 Inputs case "radix": radix = (long)feat.Value.GetValue() == Int64.MinValue ? (long)feat.Value.GetValue() : 0; break; #endregion #region User List<string> Inputs case "base-dat": basePaths.AddRange((List <string>)feat.Value.GetValue()); break; case "crc": filter.CRC.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "dat": datfiles.AddRange((List <string>)feat.Value.GetValue()); break; case "exclude-field": // TODO: Use this foreach (string field in (List <string>)feat.Value.GetValue()) { datHeader.ExcludeFields[(int)Utilities.GetField(field)] = true; } break; case "exta": exta.AddRange((List <string>)feat.Value.GetValue()); break; case "extb": extb.AddRange((List <string>)feat.Value.GetValue()); break; case "game-description": filter.MachineDescription.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "game-name": filter.MachineName.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "game-type": foreach (string mach in (List <string>)feat.Value.GetValue()) { filter.MachineTypes.Positive |= Utilities.GetMachineType(mach); } break; case "item-name": filter.ItemName.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "item-type": filter.ItemTypes.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "md5": filter.MD5.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-crc": filter.CRC.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-game-description": filter.MachineDescription.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-game-name": filter.MachineName.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-game-type": foreach (string nmach in (List <string>)feat.Value.GetValue()) { filter.MachineTypes.Negative |= Utilities.GetMachineType(nmach); } break; case "not-item-name": filter.ItemName.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-item-type": filter.ItemTypes.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-md5": filter.MD5.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-sha1": filter.SHA1.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-sha256": filter.SHA256.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-sha384": filter.SHA384.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-sha512": filter.SHA512.NegativeSet.AddRange((List <string>)feat.Value.GetValue()); break; case "not-status": foreach (string nstat in (List <string>)feat.Value.GetValue()) { filter.ItemStatuses.Negative |= Utilities.GetItemStatus(nstat); } break; case "output-type": foreach (string ot in (List <string>)feat.Value.GetValue()) { DatFormat dftemp = Utilities.GetDatFormat(ot); if (dftemp != DatFormat.Logiqx || (dftemp == DatFormat.Logiqx && (datHeader.DatFormat & DatFormat.LogiqxDepreciated) == 0)) { datHeader.DatFormat |= dftemp; } } break; case "report-type": foreach (string rt in (List <string>)feat.Value.GetValue()) { statDatFormat |= Utilities.GetStatFormat(rt); } break; case "sha1": filter.SHA1.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "sha256": filter.SHA256.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "sha384": filter.SHA384.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "sha512": filter.SHA512.PositiveSet.AddRange((List <string>)feat.Value.GetValue()); break; case "status": foreach (string stat in (List <string>)feat.Value.GetValue()) { filter.ItemStatuses.Positive |= Utilities.GetItemStatus(stat); } break; case "update-field": // TODO: Use this foreach (string field in (List <string>)feat.Value.GetValue()) { updateFields.Add(Utilities.GetField(field)); } break; #endregion #region User String Inputs case "add-extension": datHeader.AddExtension = (string)feat.Value.GetValue(); break; case "author": datHeader.Author = (string)feat.Value.GetValue(); break; case "category": datHeader.Category = (string)feat.Value.GetValue(); break; case "comment": datHeader.Comment = (string)feat.Value.GetValue(); break; case "date": datHeader.Date = (string)feat.Value.GetValue(); break; case "description": datHeader.Description = (string)feat.Value.GetValue(); break; case "email": datHeader.Email = (string)feat.Value.GetValue(); break; case "equal": filter.Size.Neutral = Utilities.GetSizeFromString((string)feat.Value.GetValue()); break; case "filename": datHeader.FileName = (string)feat.Value.GetValue(); break; case "forcemerging": datHeader.ForceMerging = Utilities.GetForceMerging((string)feat.Value.GetValue()); break; case "forcenodump": datHeader.ForceNodump = Utilities.GetForceNodump((string)feat.Value.GetValue()); break; case "forcepacking": datHeader.ForcePacking = Utilities.GetForcePacking((string)feat.Value.GetValue()); break; case "greater": filter.Size.Positive = Utilities.GetSizeFromString((string)feat.Value.GetValue()); break; case "header": datHeader.Header = (string)feat.Value.GetValue(); break; case "homepage": datHeader.Homepage = (string)feat.Value.GetValue(); break; case "less": filter.Size.Negative = Utilities.GetSizeFromString((string)feat.Value.GetValue()); break; case "name": datHeader.Name = (string)feat.Value.GetValue(); break; case "output-dir": outDir = (string)feat.Value.GetValue(); break; case "postfix": datHeader.Postfix = (string)feat.Value.GetValue(); break; case "prefix": datHeader.Prefix = (string)feat.Value.GetValue(); break; case "replace-extension": datHeader.ReplaceExtension = (string)feat.Value.GetValue(); break; case "root": datHeader.RootDir = (string)feat.Value.GetValue(); break; case "root-dir": filter.Root.Neutral = (string)feat.Value.GetValue(); break; case "temp": tempDir = (string)feat.Value.GetValue(); break; case "url": datHeader.Url = (string)feat.Value.GetValue(); break; case "version": datHeader.Version = (string)feat.Value.GetValue(); break; #endregion } } // Now take care of each mode in succesion switch (feature) { case "Help": // No-op as this should be caught break; // Create a DAT from a directory or set of directories case "DATFromDir": VerifyInputs(inputs, feature); InitDatFromDir(inputs, datHeader, omitFromScan, noAutomaticDate, archivesAsFiles, chdsAsFiles, skipFileType, addBlankFiles, addFileDates, tempDir, outDir, copyFiles, filter); break; // If we're in header extract and remove mode case "Extract": VerifyInputs(inputs, feature); InitExtractRemoveHeader(inputs, outDir, nostore); break; // If we're in header restore mode case "Restore": VerifyInputs(inputs, feature); InitReplaceHeader(inputs, outDir); break; case "Script": // No-op as this should be caught break; // If we're using the sorter case "Sort": InitSort(datfiles, inputs, outDir, depot, quickScan, addFileDates, delete, inverse, outputFormat, datHeader.Romba, sevenzip, gz, rar, zip, updateDat, datHeader.Header, splitType, chdsAsFiles, individual); break; // Split a DAT by the split type case "Split": VerifyInputs(inputs, feature); InitSplit(inputs, outDir, inplace, datHeader.DatFormat, splittingMode, exta, extb, shortname, basedat, radix); break; // Get statistics on input files case "Stats": VerifyInputs(inputs, feature); InitStats(inputs, datHeader.FileName, outDir, individual, showBaddumpColumn, showNodumpColumn, statDatFormat); break; // Convert, update, merge, diff, and filter a DAT or folder of DATs case "Update": VerifyInputs(inputs, feature); InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skipFirstOutput, noAutomaticDate, filter, splitType, outDir, cleanGameNames, removeUnicode, descAsName, replaceMode, onlySame); break; // If we're using the verifier case "Verify": VerifyInputs(inputs, feature); InitVerify(datfiles, inputs, depot, hashOnly, quickScan, datHeader.Header, splitType, chdsAsFiles, individual, filter); break; // If nothing is set, show the help default: _help.OutputGenericHelp(); break; } Globals.Logger.Close(); return; }
/// <summary> /// Generate a proper outfile name based on a DAT and output directory /// </summary> /// <param name="outDir">Output directory</param> /// <param name="overwrite">True if we ignore existing files (default), false otherwise</param> /// <returns>Dictionary of output formats mapped to file names</returns> public Dictionary <DatFormat, string> CreateOutFileNames(string outDir, bool overwrite = true) { // Create the output dictionary Dictionary <DatFormat, string> outfileNames = new Dictionary <DatFormat, string>(); // Double check the outDir for the end delim if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString())) { outDir += Path.DirectorySeparatorChar; } // Get all used extensions List <string> usedExtensions = new List <string>(); // Get the extensions from the output type #region .csv // CSV if (DatFormat.HasFlag(DatFormat.CSV)) { outfileNames.Add(DatFormat.CSV, CreateOutFileNamesHelper(outDir, ".csv", overwrite)); usedExtensions.Add(".csv"); } ; #endregion #region .dat // ClrMamePro if (DatFormat.HasFlag(DatFormat.ClrMamePro)) { outfileNames.Add(DatFormat.ClrMamePro, CreateOutFileNamesHelper(outDir, ".dat", overwrite)); usedExtensions.Add(".dat"); } ; // RomCenter if (DatFormat.HasFlag(DatFormat.RomCenter)) { if (usedExtensions.Contains(".dat")) { outfileNames.Add(DatFormat.RomCenter, CreateOutFileNamesHelper(outDir, ".rc.dat", overwrite)); usedExtensions.Add(".rc.dat"); } else { outfileNames.Add(DatFormat.RomCenter, CreateOutFileNamesHelper(outDir, ".dat", overwrite)); usedExtensions.Add(".dat"); } } // DOSCenter if (DatFormat.HasFlag(DatFormat.DOSCenter)) { if (usedExtensions.Contains(".dat")) { outfileNames.Add(DatFormat.DOSCenter, CreateOutFileNamesHelper(outDir, ".dc.dat", overwrite)); usedExtensions.Add(".dc.dat"); } else { outfileNames.Add(DatFormat.DOSCenter, CreateOutFileNamesHelper(outDir, ".dat", overwrite)); usedExtensions.Add(".dat"); } } #endregion #region .json // JSON if (DatFormat.HasFlag(DatFormat.SabreJSON)) { outfileNames.Add(DatFormat.SabreJSON, CreateOutFileNamesHelper(outDir, ".json", overwrite)); usedExtensions.Add(".json"); } #endregion #region .md5 // Redump MD5 if (DatFormat.HasFlag(DatFormat.RedumpMD5)) { outfileNames.Add(DatFormat.RedumpMD5, CreateOutFileNamesHelper(outDir, ".md5", overwrite)); usedExtensions.Add(".md5"); } ; #endregion #region .sfv // Redump SFV if (DatFormat.HasFlag(DatFormat.RedumpSFV)) { outfileNames.Add(DatFormat.RedumpSFV, CreateOutFileNamesHelper(outDir, ".sfv", overwrite)); usedExtensions.Add(".sfv"); } ; #endregion #region .sha1 // Redump SHA-1 if (DatFormat.HasFlag(DatFormat.RedumpSHA1)) { outfileNames.Add(DatFormat.RedumpSHA1, CreateOutFileNamesHelper(outDir, ".sha1", overwrite)); usedExtensions.Add(".sha1"); } ; #endregion #region .sha256 // Redump SHA-256 if (DatFormat.HasFlag(DatFormat.RedumpSHA256)) { outfileNames.Add(DatFormat.RedumpSHA256, CreateOutFileNamesHelper(outDir, ".sha256", overwrite)); usedExtensions.Add(".sha256"); } ; #endregion #region .sha384 // Redump SHA-384 if (DatFormat.HasFlag(DatFormat.RedumpSHA384)) { outfileNames.Add(DatFormat.RedumpSHA384, CreateOutFileNamesHelper(outDir, ".sha384", overwrite)); usedExtensions.Add(".sha384"); } ; #endregion #region .sha512 // Redump SHA-512 if (DatFormat.HasFlag(DatFormat.RedumpSHA512)) { outfileNames.Add(DatFormat.RedumpSHA512, CreateOutFileNamesHelper(outDir, ".sha512", overwrite)); usedExtensions.Add(".sha512"); } ; #endregion #region .spamsum // Redump SpamSum if (DatFormat.HasFlag(DatFormat.RedumpSpamSum)) { outfileNames.Add(DatFormat.RedumpSpamSum, CreateOutFileNamesHelper(outDir, ".spamsum", overwrite)); usedExtensions.Add(".spamsum"); } ; #endregion #region .ssv // SSV if (DatFormat.HasFlag(DatFormat.SSV)) { outfileNames.Add(DatFormat.SSV, CreateOutFileNamesHelper(outDir, ".ssv", overwrite)); usedExtensions.Add(".ssv"); } ; #endregion #region .tsv // TSV if (DatFormat.HasFlag(DatFormat.TSV)) { outfileNames.Add(DatFormat.TSV, CreateOutFileNamesHelper(outDir, ".tsv", overwrite)); usedExtensions.Add(".tsv"); } ; #endregion #region .txt // AttractMode if (DatFormat.HasFlag(DatFormat.AttractMode)) { outfileNames.Add(DatFormat.AttractMode, CreateOutFileNamesHelper(outDir, ".txt", overwrite)); usedExtensions.Add(".txt"); } // MAME Listroms if (DatFormat.HasFlag(DatFormat.Listrom)) { if (usedExtensions.Contains(".txt")) { outfileNames.Add(DatFormat.Listrom, CreateOutFileNamesHelper(outDir, ".lr.txt", overwrite)); usedExtensions.Add(".lr.txt"); } else { outfileNames.Add(DatFormat.Listrom, CreateOutFileNamesHelper(outDir, ".txt", overwrite)); usedExtensions.Add(".txt"); } } // Missfile if (DatFormat.HasFlag(DatFormat.MissFile)) { if (usedExtensions.Contains(".txt")) { outfileNames.Add(DatFormat.MissFile, CreateOutFileNamesHelper(outDir, ".miss.txt", overwrite)); usedExtensions.Add(".miss.txt"); } else { outfileNames.Add(DatFormat.MissFile, CreateOutFileNamesHelper(outDir, ".txt", overwrite)); usedExtensions.Add(".txt"); } } // Everdrive SMDB if (DatFormat.HasFlag(DatFormat.EverdriveSMDB)) { if (usedExtensions.Contains(".txt")) { outfileNames.Add(DatFormat.EverdriveSMDB, CreateOutFileNamesHelper(outDir, ".smdb.txt", overwrite)); usedExtensions.Add(".smdb.txt"); } else { outfileNames.Add(DatFormat.EverdriveSMDB, CreateOutFileNamesHelper(outDir, ".txt", overwrite)); usedExtensions.Add(".txt"); } } #endregion #region .xml // Logiqx XML if (DatFormat.HasFlag(DatFormat.Logiqx)) { outfileNames.Add(DatFormat.Logiqx, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } if (DatFormat.HasFlag(DatFormat.LogiqxDeprecated)) { outfileNames.Add(DatFormat.LogiqxDeprecated, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } // SabreDAT if (DatFormat.HasFlag(DatFormat.SabreXML)) { if (usedExtensions.Contains(".xml")) { outfileNames.Add(DatFormat.SabreXML, CreateOutFileNamesHelper(outDir, ".sd.xml", overwrite)); usedExtensions.Add(".sd.xml"); } else { outfileNames.Add(DatFormat.SabreXML, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } } // Software List if (DatFormat.HasFlag(DatFormat.SoftwareList)) { if (usedExtensions.Contains(".xml")) { outfileNames.Add(DatFormat.SoftwareList, CreateOutFileNamesHelper(outDir, ".sl.xml", overwrite)); usedExtensions.Add(".sl.xml"); } else { outfileNames.Add(DatFormat.SoftwareList, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } } // MAME Listxml if (DatFormat.HasFlag(DatFormat.Listxml)) { if (usedExtensions.Contains(".xml")) { outfileNames.Add(DatFormat.Listxml, CreateOutFileNamesHelper(outDir, ".mame.xml", overwrite)); usedExtensions.Add(".mame.xml"); } else { outfileNames.Add(DatFormat.Listxml, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } } // OfflineList if (DatFormat.HasFlag(DatFormat.OfflineList)) { if (usedExtensions.Contains(".xml")) { outfileNames.Add(DatFormat.OfflineList, CreateOutFileNamesHelper(outDir, ".ol.xml", overwrite)); usedExtensions.Add(".ol.xml"); } else { outfileNames.Add(DatFormat.OfflineList, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } } // openMSX if (DatFormat.HasFlag(DatFormat.OpenMSX)) { if (usedExtensions.Contains(".xml")) { outfileNames.Add(DatFormat.OpenMSX, CreateOutFileNamesHelper(outDir, ".msx.xml", overwrite)); usedExtensions.Add(".msx.xml"); } else { outfileNames.Add(DatFormat.OpenMSX, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } } // Archive.org if (DatFormat.HasFlag(DatFormat.ArchiveDotOrg)) { if (usedExtensions.Contains(".xml")) { outfileNames.Add(DatFormat.ArchiveDotOrg, CreateOutFileNamesHelper(outDir, ".ado.xml", overwrite)); usedExtensions.Add(".ado.xml"); } else { outfileNames.Add(DatFormat.ArchiveDotOrg, CreateOutFileNamesHelper(outDir, ".xml", overwrite)); usedExtensions.Add(".xml"); } } #endregion return(outfileNames); }
public static bool WriteProperties(ThingType thing, DatFormat format, BinaryWriter writer) { if (format == DatFormat.Format_1010 || format == DatFormat.Format_1050 || format == DatFormat.Format_1057) { if (!WriteProperties_1010_1057(thing, writer)) { return false; } } return true; }