public void NormalizedFileNameTest(string current, string parent, bool sanitize, string expected) { var path = new ParentablePath(current, parent); string actual = path.GetNormalizedFileName(sanitize); Assert.Equal(expected, actual); }
/// <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="filename">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, string filename, int indexId = 0, bool keep = false, bool keepext = false, bool quotes = true, bool statsOnly = false, bool throwOnError = false) { ParentablePath path = new ParentablePath(filename.Trim('"')); ParseInto(datFile, path, indexId, keep, keepext, quotes, statsOnly, throwOnError); }
/// <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(); }
public void GetOutputPathTest(string current, string parent, string outDir, bool inplace, string expected) { // Hacks because I can't use environment vars as parameters if (outDir == "%cd%") { outDir = Environment.CurrentDirectory.TrimEnd('\\'); } if (expected?.Contains("%cd%") == true) { expected = expected.Replace("%cd%", Environment.CurrentDirectory.TrimEnd('\\')); } var path = new ParentablePath(current, parent); string actual = path.GetOutputPath(outDir, inplace); Assert.Equal(expected, actual); }