public void TestDates() { IdGamesTextFileParser parser = new IdGamesTextFileParser(s_formats); string[] dates = new string[] { "Release date : 5/April/16", "Release date:4/05/2016", " Release date: 4.05.2016", " Release date: 4 05 2016", "Date finished: 5 April 2016", "release Date: April 5th 2016", "Release date: April 5th, 2016", "Release date: April 5th 16", "Release date: junk 5 April 2016 junk", }; DateTime assert = DateTime.Parse("4/5/2016", CultureInfo.InvariantCulture); foreach (string date in dates) { parser.Parse(date); Assert.AreEqual(parser.ReleaseDate, assert); } }
public void TestBadDates() { IdGamesTextFileParser parser = new IdGamesTextFileParser(s_formats); parser.Parse("Release date: this is garbage"); Assert.AreEqual(null, parser.ReleaseDate); parser.Parse("Release date: "); Assert.AreEqual(null, parser.ReleaseDate); parser.Parse("Release date:"); Assert.AreEqual(null, parser.ReleaseDate); parser.Parse("Release date: 1234"); Assert.AreEqual(null, parser.ReleaseDate); }
private void FillTextFileInfo(IGameFile gameFile, ZipArchive za) { bool bParsedTxt = false; foreach (ZipArchiveEntry zae in za.Entries) { if (Path.GetExtension(zae.FullName).Equals(".txt", StringComparison.OrdinalIgnoreCase)) { byte[] buffer = new byte[zae.Length]; zae.Open().Read(buffer, 0, Convert.ToInt32(zae.Length)); IdGamesTextFileParser parser = new IdGamesTextFileParser(DateParseFormats); parser.Parse(UnicodeEncoding.UTF7.GetString(buffer)); gameFile.Title = parser.Title; gameFile.Author = parser.Author; gameFile.ReleaseDate = parser.ReleaseDate; gameFile.Description = parser.Description; if (string.IsNullOrEmpty(gameFile.Title)) { gameFile.Title = gameFile.FileName; } bParsedTxt = !string.IsNullOrEmpty(gameFile.Title) || !string.IsNullOrEmpty(gameFile.Author) || !string.IsNullOrEmpty(gameFile.Description); } if (bParsedTxt) { break; } } }
public void TestEmpty() { IdGamesTextFileParser parser = new IdGamesTextFileParser(s_formats); parser.Parse(string.Empty); Assert.AreEqual(string.Empty, parser.Title); Assert.AreEqual(string.Empty, parser.Author); Assert.AreEqual(null, parser.ReleaseDate); Assert.AreEqual(string.Empty, parser.Description); }
public void TestStrings() { string test = @"=========================================================================== Primary purpose : Deathmatch =========================================================================== TitLe : Onslaught DM 3 (v.1.1) Filename : onsl3.wad Release DATE : 01/17/07 AUTHORS : Hobomaster22, Ak-01 dEsCrIpTioN : 21 head to head deathmatch maps with faced paced action. This is a 1on1 specific mapset. For FFA more than 4 players is not recommended."; IdGamesTextFileParser parser = new IdGamesTextFileParser(s_formats); parser.Parse(test); Assert.AreEqual("Onslaught DM 3 (v.1.1)", parser.Title); Assert.AreEqual(DateTime.Parse("01/17/07", CultureInfo.InvariantCulture), parser.ReleaseDate); Assert.AreEqual("Hobomaster22, Ak-01", parser.Author); //Could be Author: or Authors: Assert.AreEqual("21 head to head deathmatch maps with faced paced action. This is a 1on1 specific mapset. For FFA more than 4 players is not recommended.", parser.Description); test = test.Replace("AUTHORS", "AUTHOR"); parser.Parse(test); Assert.AreEqual("Onslaught DM 3 (v.1.1)", parser.Title); Assert.AreEqual(DateTime.Parse("01/17/07", CultureInfo.InvariantCulture), parser.ReleaseDate); Assert.AreEqual("Hobomaster22, Ak-01", parser.Author); //Could be Author: or Authors: Assert.AreEqual("21 head to head deathmatch maps with faced paced action. This is a 1on1 specific mapset. For FFA more than 4 players is not recommended.", parser.Description); test = @"=========================================================================== Primary purpose : Deathmatch =========================================================================== TitLe : Filename : Release DATE : AUTHORS : dEsCrIpTioN : "; parser.Parse(test); Assert.AreEqual(string.Empty, parser.Title); Assert.AreEqual(null, parser.ReleaseDate); Assert.AreEqual(string.Empty, parser.Author); Assert.AreEqual(string.Empty, parser.Description); }
private void FillTextFileInfo(IGameFile gameFile, IArchiveReader reader) { bool bParsedTxt = false; foreach (var entry in reader.Entries) { if (Path.GetExtension(entry.FullName).Equals(".txt", StringComparison.OrdinalIgnoreCase)) { byte[] buffer = new byte[entry.Length]; try { entry.Read(buffer, 0, Convert.ToInt32(entry.Length)); } catch (Exception) { // Do not fail because we couldn't read a text file } IdGamesTextFileParser parser = new IdGamesTextFileParser(DateParseFormats); parser.Parse(Encoding.UTF7.GetString(buffer)); bParsedTxt = !string.IsNullOrEmpty(parser.Title) || !string.IsNullOrEmpty(parser.Author) || !string.IsNullOrEmpty(parser.Description); if (bParsedTxt) { gameFile.Title = parser.Title; gameFile.Author = parser.Author; gameFile.ReleaseDate = parser.ReleaseDate; gameFile.Description = parser.Description; } } if (bParsedTxt) { break; } } if (string.IsNullOrEmpty(gameFile.Title)) { gameFile.Title = gameFile.FileNameNoPath; } }
private IGameFile FromZipFile(FileInfo fi) { IGameFile gameFile = new GameFile(); gameFile.FileName = fi.Name; ZipArchive za = null; try { za = ZipFile.OpenRead(fi.FullName); } catch //probably corrupt, delete? { return(null); } bool bParsedTxt = false; try { foreach (ZipArchiveEntry zae in za.Entries) { FileInfo zipFile = new FileInfo(zae.FullName); if (zipFile.Extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)) { byte[] buffer = new byte[zae.Length]; zae.Open().Read(buffer, 0, Convert.ToInt32(zae.Length)); IdGamesTextFileParser parser = new IdGamesTextFileParser(DateParseFormats); parser.Parse(UnicodeEncoding.UTF7.GetString(buffer)); gameFile.Title = parser.Title; gameFile.Author = parser.Author; gameFile.ReleaseDate = parser.ReleaseDate; gameFile.Description = parser.Description; if (string.IsNullOrEmpty(gameFile.Title)) { gameFile.Title = fi.Name; } bParsedTxt = !string.IsNullOrEmpty(gameFile.Title) || !string.IsNullOrEmpty(gameFile.Author) || !string.IsNullOrEmpty(gameFile.Description); } if (bParsedTxt) { break; } } } catch (InvalidDataException) { gameFile = null; } finally { za.Dispose(); } return(gameFile); }