public static FdsGame Import(string fdsFileName, byte[] rawRomData = null) { if (rawRomData == null) { rawRomData = File.ReadAllBytes(fdsFileName); } if (Encoding.ASCII.GetString(rawRomData, 0, 3) == "FDS") // header? cut it! { var fdsDataNoHeader = new byte[rawRomData.Length - 0x10]; Array.Copy(rawRomData, 0x10, fdsDataNoHeader, 0, fdsDataNoHeader.Length); rawRomData = fdsDataNoHeader; } var crc32 = CRC32(rawRomData); var code = GenerateCode(crc32, DefaultPrefix); var gamePath = Path.Combine(GamesDirectory, code); var fdsPath = Path.Combine(gamePath, code + ".fds"); Directory.CreateDirectory(gamePath); File.WriteAllBytes(fdsPath, rawRomData); var game = new FdsGame(gamePath, true); game.Name = Path.GetFileNameWithoutExtension(fdsFileName); game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim(); game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim(); game.Name = game.Name.Replace("_", " ").Replace(" ", " ").Trim(); game.FindCover(fdsFileName, Resources.blank_fds, crc32); game.Args = DefaultArgs; game.Save(); return(game); }
public static FdsGame Import(string fdsFileName, byte[] rawRomData = null) { if (rawRomData == null) { rawRomData = File.ReadAllBytes(fdsFileName); } var crc32 = CRC32(rawRomData); var code = GenerateCode(crc32, prefixCode); var gamePath = Path.Combine(GamesDirectory, code); var fdsPath = Path.Combine(gamePath, code + ".fds"); Directory.CreateDirectory(gamePath); File.WriteAllBytes(fdsPath, rawRomData); var game = new FdsGame(gamePath, true); game.Name = Path.GetFileNameWithoutExtension(fdsFileName); game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim(); game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim(); game.Name = game.Name.Replace("_", " ").Replace(" ", " ") /*.Replace(", The", "")*/.Trim(); // Trying to find cover file Image cover = null; if (!string.IsNullOrEmpty(fdsFileName)) { var imagePath = Path.Combine(Path.GetDirectoryName(fdsFileName), Path.GetFileNameWithoutExtension(fdsFileName) + ".png"); if (File.Exists(imagePath)) { cover = LoadBitmap(imagePath); } imagePath = Path.Combine(Path.GetDirectoryName(fdsFileName), Path.GetFileNameWithoutExtension(fdsFileName) + ".jpg"); if (File.Exists(imagePath)) { cover = LoadBitmap(imagePath); } var artDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "art"); Directory.CreateDirectory(artDirectory); imagePath = Path.Combine(artDirectory, Path.GetFileNameWithoutExtension(fdsFileName) + ".png"); if (File.Exists(imagePath)) { cover = LoadBitmap(imagePath); } imagePath = Path.Combine(artDirectory, Path.GetFileNameWithoutExtension(fdsFileName) + ".jpg"); if (File.Exists(imagePath)) { cover = LoadBitmap(imagePath); } var covers = Directory.GetFiles(artDirectory, string.Format("{0:X8}*.*", crc32), SearchOption.AllDirectories); if (covers.Length > 0) { cover = LoadBitmap(covers[0]); } } if (cover == null) { cover = Resources.blank_fds; } game.Image = cover; game.Save(); return(game); }