示例#1
0
 static void InsertGame(InitialRomInfo rom)
 {
     using (var cmd = DB.Con.CreateCommand())
     {
         cmd.CommandText = "INSERT INTO game (system, name, created_date) VALUES (@System, @Name, datetime('now','localtime'))";
         cmd.Parameters.Add(new SqliteParameter("@System", rom.GuessedSystem));
         cmd.Parameters.Add(new SqliteParameter("@Name", rom.Name));
         cmd.ExecuteNonQuery();
     }
 }
示例#2
0
 static bool GameInDatabase(InitialRomInfo rom)
 {
     using (var cmd = DB.Con.CreateCommand())
     {
         cmd.CommandText = "SELECT game_id FROM game WHERE system = @System and name = @Name";
         cmd.Parameters.Add(new SqliteParameter("@System", rom.GuessedSystem));
         cmd.Parameters.Add(new SqliteParameter("@Name", rom.Name));
         var result = cmd.ExecuteScalar();
         return(result != null);
     }
 }
示例#3
0
		static bool GameInDatabase(InitialRomInfo rom)
		{
			using (var cmd = DB.Con.CreateCommand())
			{
				cmd.CommandText = "SELECT game_id FROM game WHERE system = @System and name = @Name";
				cmd.Parameters.Add(new SqliteParameter("@System", rom.GuessedSystem));
				cmd.Parameters.Add(new SqliteParameter("@Name", rom.Name));
				var result = cmd.ExecuteScalar();
				return result != null;
			}
		}
示例#4
0
 static void InsertRom(InitialRomInfo rom)
 {
     using (var cmd = DB.Con.CreateCommand())
     {
         cmd.CommandText =
             "INSERT INTO rom (crc32, md5, sha1, size, system, name, region, version_tags, created_date) " +
             "VALUES (@crc32, @md5, @sha1, @size, @System, @Name, @Region, @VersionTags, datetime('now','localtime'))";
         cmd.Parameters.Add(new SqliteParameter("@crc32", rom.CRC32));
         cmd.Parameters.Add(new SqliteParameter("@md5", rom.MD5));
         cmd.Parameters.Add(new SqliteParameter("@sha1", rom.SHA1));
         cmd.Parameters.Add(new SqliteParameter("@size", rom.Size));
         cmd.Parameters.Add(new SqliteParameter("@System", rom.GuessedSystem));
         cmd.Parameters.Add(new SqliteParameter("@Name", rom.Name));
         cmd.Parameters.Add(new SqliteParameter("@Region", rom.GuessedRegion));
         cmd.Parameters.Add(new SqliteParameter("@VersionTags", rom.VersionTags));
         cmd.ExecuteNonQuery();
     }
 }
示例#5
0
		static InitialRomInfo GenerateRomHashDirect(string file, byte[] filebytes)
		{
			var info = new InitialRomInfo();
			var fileInfo = new FileInfo(file);
			string ext = fileInfo.Extension.ToLowerInvariant().Replace(".", "");
			info.FileName = fileInfo.Name;

			// Parse the filename to guess things about the rom
			var name = Path.GetFileNameWithoutExtension(fileInfo.Name);
			if (name.StartsWith("[BIOS] ")) 
				name = name.Replace("[BIOS] ","") + " [BIOS]";

			string modifiers = "";
			int modIndex = name.IndexOfAny(modifierStartChars);
			if (modIndex > 0)
			{
				modifiers = name.Substring(modIndex);
				name = name.Substring(0, modIndex);
			}
			info.Name = name.Trim();

			// parse out modifiers
			var mods = new List<string>();
			modifiers = modifiers.Replace(")", ";").Replace("]",";");
			modifiers = modifiers.Replace("(", "").Replace("[", "");
			var m_ = modifiers.Split(';');
			foreach (var mi in m_)
			{
				var m = mi.Trim();
				if (m.Length == 0) continue;
				mods.Add(m);
			}

			info.VersionTags = "";
			foreach (var mi in mods)
			{
				if (info.VersionTags.Length != 0)
					info.VersionTags += ";";
				
				switch (mi.ToLower())
				{
					case "j":
					case "jp":
					case "jpn":
					case "japan":
						info.GuessedRegion = "Japan";
						break;
					case "usa":
					case "us":
					case "u":
						info.GuessedRegion = "USA";
						break;
					case "europe":
					case "eur":
					case "e":
						info.GuessedRegion = "Europe";
						break;
					case "world":
					case "w":
						info.GuessedRegion = "World";
						break;
					case "korea":
					case "kr":
					case "k":
						info.GuessedRegion = "Korea";
						break;
					case "brazil":
					case "br":
						info.GuessedRegion = "Brazil";
						break;
					case "taiwan":
					case "tw":
						info.GuessedRegion = "Taiwan";
						break;
					case "usa, europe":
						info.GuessedRegion = "USA;Europe";
						break;
					case "japan, europe":
						info.GuessedRegion = "Europe;Japan";
						break;
					case "japan, usa":
						info.GuessedRegion = "USA;Japan";
						break;

					default:
						info.VersionTags += mi;
						break;
				}
			}

			// transform binary to canonical binary representation (de-header/de-stripe/de-swap)
			byte[] romBytes = filebytes;
			switch (ext)
			{
				case "sms":
				case "gg":
				case "sg":
				case "pce":
				case "sgx":
					romBytes = MaybeStripHeader512(filebytes);
					break;

				case "smd":
					if (filebytes.Length % 1024 == 512)
						System.Windows.Forms.MessageBox.Show("derp");
					romBytes = DeInterleaveSMD(filebytes);
					break;

				case "z64":
				case "n64":
				case "v64":
					throw new NotImplementedException("n64 demutate not done");
			}
			
			// guess system
			switch (ext)
			{
				case "sms": info.GuessedSystem = "SMS"; break;
				case "gg":  info.GuessedSystem = "GG"; break;
				case "sg":  info.GuessedSystem = "SG"; break;
				case "pce": info.GuessedSystem = "PCE"; break;
				case "sgx": info.GuessedSystem = "SGX"; break;
				case "smd":
				case "gen": info.GuessedSystem = "GEN"; break;
				case "nes": info.GuessedSystem = "NES"; break;
				default: info.GuessedSystem = "Unknown"; break;
			}

			// Perform hashing
			info.CRC32 = Hash_CRC32(romBytes);
			info.MD5 = Hash_MD5(romBytes);
			info.SHA1 = Hash_SHA1(romBytes);
			info.Size = romBytes.Length;

			return info;
		}
示例#6
0
        static InitialRomInfo GenerateRomHashDirect(string file, byte[] filebytes)
        {
            var    info     = new InitialRomInfo();
            var    fileInfo = new FileInfo(file);
            string ext      = fileInfo.Extension.ToLowerInvariant().Replace(".", "");

            info.FileName = fileInfo.Name;

            // Parse the filename to guess things about the rom
            var name = Path.GetFileNameWithoutExtension(fileInfo.Name);

            if (name.StartsWith("[BIOS] "))
            {
                name = name.Replace("[BIOS] ", "") + " [BIOS]";
            }

            string modifiers = "";
            int    modIndex  = name.IndexOfAny(modifierStartChars);

            if (modIndex > 0)
            {
                modifiers = name.Substring(modIndex);
                name      = name.Substring(0, modIndex);
            }
            info.Name = name.Trim();

            // parse out modifiers
            var mods = new List <string>();

            modifiers = modifiers.Replace(")", ";").Replace("]", ";");
            modifiers = modifiers.Replace("(", "").Replace("[", "");
            var m_ = modifiers.Split(';');

            foreach (var mi in m_)
            {
                var m = mi.Trim();
                if (m.Length == 0)
                {
                    continue;
                }
                mods.Add(m);
            }

            info.VersionTags = "";
            foreach (var mi in mods)
            {
                if (info.VersionTags.Length != 0)
                {
                    info.VersionTags += ";";
                }

                switch (mi.ToLower())
                {
                case "j":
                case "jp":
                case "jpn":
                case "japan":
                    info.GuessedRegion = "Japan";
                    break;

                case "usa":
                case "us":
                case "u":
                    info.GuessedRegion = "USA";
                    break;

                case "europe":
                case "eur":
                case "e":
                    info.GuessedRegion = "Europe";
                    break;

                case "world":
                case "w":
                    info.GuessedRegion = "World";
                    break;

                case "korea":
                case "kr":
                case "k":
                    info.GuessedRegion = "Korea";
                    break;

                case "brazil":
                case "br":
                    info.GuessedRegion = "Brazil";
                    break;

                case "taiwan":
                case "tw":
                    info.GuessedRegion = "Taiwan";
                    break;

                case "usa, europe":
                    info.GuessedRegion = "USA;Europe";
                    break;

                case "japan, europe":
                    info.GuessedRegion = "Europe;Japan";
                    break;

                case "japan, usa":
                    info.GuessedRegion = "USA;Japan";
                    break;

                default:
                    info.VersionTags += mi;
                    break;
                }
            }

            // transform binary to canonical binary representation (de-header/de-stripe/de-swap)
            byte[] romBytes = filebytes;
            switch (ext)
            {
            case "sms":
            case "gg":
            case "sg":
            case "pce":
            case "sgx":
                romBytes = MaybeStripHeader512(filebytes);
                break;

            case "smd":
                if (filebytes.Length % 1024 == 512)
                {
                    System.Windows.Forms.MessageBox.Show("derp");
                }
                romBytes = DeInterleaveSMD(filebytes);
                break;

            case "z64":
            case "n64":
            case "v64":
                throw new NotImplementedException("n64 demutate not done");
            }

            // guess system
            switch (ext)
            {
            case "sms": info.GuessedSystem = "SMS"; break;

            case "gg":  info.GuessedSystem = "GG"; break;

            case "sg":  info.GuessedSystem = "SG"; break;

            case "pce": info.GuessedSystem = "PCE"; break;

            case "sgx": info.GuessedSystem = "SGX"; break;

            case "smd":
            case "gen": info.GuessedSystem = "GEN"; break;

            case "nes": info.GuessedSystem = "NES"; break;

            default: info.GuessedSystem = "Unknown"; break;
            }

            // Perform hashing
            info.CRC32 = Hash_CRC32(romBytes);
            info.MD5   = Hash_MD5(romBytes);
            info.SHA1  = Hash_SHA1(romBytes);
            info.Size  = romBytes.Length;

            return(info);
        }
示例#7
0
		static void InsertRom(InitialRomInfo rom)
		{
			using (var cmd = DB.Con.CreateCommand())
			{
				cmd.CommandText = 
					"INSERT INTO rom (crc32, md5, sha1, size, system, name, region, version_tags, created_date) "+
					"VALUES (@crc32, @md5, @sha1, @size, @System, @Name, @Region, @VersionTags, datetime('now','localtime'))";
				cmd.Parameters.Add(new SqliteParameter("@crc32", rom.CRC32));
				cmd.Parameters.Add(new SqliteParameter("@md5", rom.MD5));
				cmd.Parameters.Add(new SqliteParameter("@sha1", rom.SHA1));
				cmd.Parameters.Add(new SqliteParameter("@size", rom.Size));
				cmd.Parameters.Add(new SqliteParameter("@System", rom.GuessedSystem));
				cmd.Parameters.Add(new SqliteParameter("@Name", rom.Name));
				cmd.Parameters.Add(new SqliteParameter("@Region", rom.GuessedRegion));
				cmd.Parameters.Add(new SqliteParameter("@VersionTags", rom.VersionTags));
				cmd.ExecuteNonQuery();
			}
		}
示例#8
0
		static void InsertGame(InitialRomInfo rom)
		{
			using (var cmd = DB.Con.CreateCommand())
			{
				cmd.CommandText = "INSERT INTO game (system, name, created_date) VALUES (@System, @Name, datetime('now','localtime'))";
				cmd.Parameters.Add(new SqliteParameter("@System", rom.GuessedSystem));
				cmd.Parameters.Add(new SqliteParameter("@Name", rom.Name));
				cmd.ExecuteNonQuery();
			}
		}