示例#1
0
        public static bool FindInFiles(RvFile tFile)
        {
            if (_commandFindInFiles == null)
            {
                _commandFindInFiles = new SQLiteCommand(@"
                    SELECT COUNT(1) FROM FILES WHERE
                        size=@size AND crc=@CRC and sha1=@SHA1 and md5=@MD5", DBSqlite.db.Connection);
                _commandFindInFiles.Parameters.Add(new SQLiteParameter("size"));
                _commandFindInFiles.Parameters.Add(new SQLiteParameter("crc"));
                _commandFindInFiles.Parameters.Add(new SQLiteParameter("sha1"));
                _commandFindInFiles.Parameters.Add(new SQLiteParameter("md5"));
            }

            _commandFindInFiles.Parameters["size"].Value = tFile.Size;
            _commandFindInFiles.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
            _commandFindInFiles.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
            _commandFindInFiles.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);

            object res = _commandFindInFiles.ExecuteScalar();

            if ((res == null) || (res == DBNull.Value))
            {
                return(false);
            }
            int count = Convert.ToInt32(res);

            return(count > 0);
        }
示例#2
0
        private static void FileUpdateZeroRom(RvFile file)
        {
            if (_commandRvFileUpdateZeroRom == null)
            {
                _commandRvFileUpdateZeroRom = new SQLiteCommand(
                    @"
                    UPDATE ROM SET 
	                    FileId = @FileId,
                        LocalFileHeader = null,
                        LocalFileHeaderOffset = null,
                        LocalFileHeaderLength=null
                    WHERE
	                    ( Size=0 ) AND
	                    ( crc  is NULL OR crc  = @crc  ) AND
	                    ( sha1 is NULL OR sha1 = @sha1 ) AND
	                    ( md5  is NULL OR md5  = @md5  ) AND 
                        FileId IS NULL;
                ", DBSqlite.db.Connection);
                _commandRvFileUpdateZeroRom.Parameters.Add(new SQLiteParameter("FileId"));
                _commandRvFileUpdateZeroRom.Parameters.Add(new SQLiteParameter("crc"));
                _commandRvFileUpdateZeroRom.Parameters.Add(new SQLiteParameter("sha1"));
                _commandRvFileUpdateZeroRom.Parameters.Add(new SQLiteParameter("md5"));
            }

            _commandRvFileUpdateZeroRom.Parameters["FileId"].Value = file.FileId;
            _commandRvFileUpdateZeroRom.Parameters["crc"].Value    = VarFix.ToDBString(file.CRC);
            _commandRvFileUpdateZeroRom.Parameters["sha1"].Value   = VarFix.ToDBString(file.SHA1);
            _commandRvFileUpdateZeroRom.Parameters["md5"].Value    = VarFix.ToDBString(file.MD5);
            _commandRvFileUpdateZeroRom.ExecuteNonQuery();
        }
示例#3
0
        public void DBWrite()
        {
            DataAccessLayer.ExecuteNonQuery("BEGIN");

            SqlWrite.Parameters["size"].Value           = Size;
            SqlWrite.Parameters["compressedsize"].Value = CompressedSize;
            SqlWrite.Parameters["crc"].Value            = VarFix.ToDBString(CRC);
            SqlWrite.Parameters["sha1"].Value           = VarFix.ToDBString(SHA1);
            SqlWrite.Parameters["md5"].Value            = VarFix.ToDBString(MD5);

            object res    = SqlWrite.ExecuteScalar();
            UInt32 fileId = Convert.ToUInt32(res);

            if (Size != 0)
            {
                SqlUpdateRom.Parameters["FileId"].Value = fileId;
                SqlUpdateRom.Parameters["size"].Value   = Size;
                SqlUpdateRom.Parameters["crc"].Value    = VarFix.ToDBString(CRC);
                SqlUpdateRom.Parameters["sha1"].Value   = VarFix.ToDBString(SHA1);
                SqlUpdateRom.Parameters["md5"].Value    = VarFix.ToDBString(MD5);
                SqlUpdateRom.ExecuteNonQuery();
            }
            else
            {
                SqlUpdateZeroRom.Parameters["FileId"].Value = fileId;
                SqlUpdateZeroRom.Parameters["crc"].Value    = VarFix.ToDBString(CRC);
                SqlUpdateZeroRom.Parameters["sha1"].Value   = VarFix.ToDBString(SHA1);
                SqlUpdateZeroRom.Parameters["md5"].Value    = VarFix.ToDBString(MD5);
                SqlUpdateZeroRom.ExecuteNonQuery();
            }
            DataAccessLayer.ExecuteNonQuery("COMMIT");
        }
示例#4
0
        public static bool Execute(RvFile tFile)
        {
            if (tFile.Size == 0)
            {
                CommandZero.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                CommandZero.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
                CommandZero.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);

                object resZero = CommandZero.ExecuteScalar();

                if (resZero == null || resZero == DBNull.Value)
                {
                    return(false);
                }
                int countZero = Convert.ToInt32(resZero);

                return(countZero > 0);
            }

            Command.Parameters["size"].Value = tFile.Size;
            Command.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
            Command.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
            Command.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);

            object res = Command.ExecuteScalar();

            if (res == null || res == DBNull.Value)
            {
                return(false);
            }
            int count = Convert.ToInt32(res);

            return(count > 0);
        }
示例#5
0
        public static uint?Execute(RvRom tFile)
        {
            if (tFile.SHA1 != null)
            {
                CommandSHA1.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
                CommandSHA1.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);
                CommandSHA1.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                CommandSHA1.Parameters["size"].Value = tFile.Size;

                object res = CommandSHA1.ExecuteScalar();

                if (res == null || res == DBNull.Value)
                {
                    return(null);
                }
                return((uint?)Convert.ToInt32(res));
            }
            if (tFile.MD5 != null)
            {
                CommandMD5.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);
                CommandMD5.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                CommandMD5.Parameters["size"].Value = tFile.Size;

                object res = CommandMD5.ExecuteScalar();

                if (res == null || res == DBNull.Value)
                {
                    return(null);
                }
                return((uint?)Convert.ToInt32(res));
            }
            if (tFile.CRC != null)
            {
                CommandCRC.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                CommandCRC.Parameters["size"].Value = tFile.Size;

                object res = CommandCRC.ExecuteScalar();

                if (res == null || res == DBNull.Value)
                {
                    return(null);
                }
                return((uint?)Convert.ToInt32(res));
            }
            if (tFile.Size != null && tFile.Size == 0)
            {
                CommandSize.Parameters["size"].Value = tFile.Size;

                object res = CommandSize.ExecuteScalar();

                if (res == null || res == DBNull.Value)
                {
                    return(null);
                }
                return((uint?)Convert.ToInt32(res));
            }

            return(null);
        }
示例#6
0
        private static bool FindInROMsAlt(RvFile tFile)
        {
            if (_commandFindInRoMsAlt == null)
            {
                _commandFindInRoMsAlt = new SQLiteCommand(@"
                        SELECT
                        (
                            SELECT count(1) FROM ROM WHERE
                                ( type=@type ) AND
                                ( sha1=@SHA1 ) AND 
                                ( md5=@MD5 OR md5 is NULL) AND
                                ( crc=@CRC OR crc is NULL ) AND
                                ( size=@size OR size is NULL )
                        ) +
                        (
                            SELECT count(1) FROM ROM WHERE
                                ( type=@type ) AND
                                ( md5=@MD5 ) AND
                                ( sha1=@SHA1 OR sha1 is NULL ) AND 
                                ( crc=@CRC OR crc is NULL ) AND
                                ( size=@size OR size is NULL )
                        ) +
                        (
                            SELECT count(1) FROM ROM WHERE
                                ( type=@type ) AND
                                ( crc=@CRC ) AND
                                ( sha1=@SHA1 OR sha1 is NULL ) AND 
                                ( md5=@MD5 OR md5 is NULL) AND
                                ( size=@size OR size is NULL )
                        ) 
                        AS TotalFound", DBSqlite.db.Connection);
                _commandFindInRoMsAlt.Parameters.Add(new SQLiteParameter("type"));
                _commandFindInRoMsAlt.Parameters.Add(new SQLiteParameter("size"));
                _commandFindInRoMsAlt.Parameters.Add(new SQLiteParameter("crc"));
                _commandFindInRoMsAlt.Parameters.Add(new SQLiteParameter("sha1"));
                _commandFindInRoMsAlt.Parameters.Add(new SQLiteParameter("md5"));
            }

            _commandFindInRoMsAlt.Parameters["type"].Value = (int)tFile.AltType;
            _commandFindInRoMsAlt.Parameters["size"].Value = tFile.AltSize;
            _commandFindInRoMsAlt.Parameters["crc"].Value  = VarFix.ToDBString(tFile.AltCRC);
            _commandFindInRoMsAlt.Parameters["sha1"].Value = VarFix.ToDBString(tFile.AltSHA1);
            _commandFindInRoMsAlt.Parameters["md5"].Value  = VarFix.ToDBString(tFile.AltMD5);

            object res = _commandFindInRoMsAlt.ExecuteScalar();

            if ((res == null) || (res == DBNull.Value))
            {
                return(false);
            }
            int count = Convert.ToInt32(res);

            return(count > 0);
        }
示例#7
0
        public void DBWrite()
        {
            FileId = DatUpdate.NoFilesInDB ? null : FindAFile.Execute(this);

            SqlWrite.Parameters["GameId"].Value = GameId;
            SqlWrite.Parameters["name"].Value   = Name;
            SqlWrite.Parameters["size"].Value   = Size;
            SqlWrite.Parameters["crc"].Value    = VarFix.ToDBString(CRC);
            SqlWrite.Parameters["sha1"].Value   = VarFix.ToDBString(SHA1);
            SqlWrite.Parameters["md5"].Value    = VarFix.ToDBString(MD5);
            SqlWrite.Parameters["merge"].Value  = Merge;
            SqlWrite.Parameters["status"].Value = Status;
            SqlWrite.Parameters["FileID"].Value = FileId;
            SqlWrite.ExecuteNonQuery();
        }
示例#8
0
        public void DBWrite()
        {
            if (_commandRvRomWrite == null)
            {
                _commandRvRomWrite = new SQLiteCommand(@"
                INSERT INTO ROM  ( GameId, name, type, size, crc, sha1, md5, merge, status, putinzip, FileId)
                          VALUES (@GameId,@Name,@Type,@Size,@CRC,@SHA1,@MD5,@Merge,@Status,@PutInZip,@FileId);

                SELECT last_insert_rowid();", Program.db.Connection);

                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("GameId"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("Name"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("Type"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("Size"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("CRC"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("SHA1"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("MD5"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("Merge"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("Status"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("PutInZip"));
                _commandRvRomWrite.Parameters.Add(new SQLiteParameter("FileId"));
            }


            FileId = DatUpdate.NoFilesInDb ? null : RvRomFileMatchup.FindAFile(this);
            _commandRvRomWrite.Parameters["GameId"].Value   = GameId;
            _commandRvRomWrite.Parameters["name"].Value     = Name;
            _commandRvRomWrite.Parameters["type"].Value     = (int)AltType;
            _commandRvRomWrite.Parameters["size"].Value     = Size;
            _commandRvRomWrite.Parameters["crc"].Value      = VarFix.ToDBString(CRC);
            _commandRvRomWrite.Parameters["sha1"].Value     = VarFix.ToDBString(SHA1);
            _commandRvRomWrite.Parameters["md5"].Value      = VarFix.ToDBString(MD5);
            _commandRvRomWrite.Parameters["merge"].Value    = Merge;
            _commandRvRomWrite.Parameters["status"].Value   = Status;
            _commandRvRomWrite.Parameters["putinzip"].Value = PutInZip;
            _commandRvRomWrite.Parameters["FileID"].Value   = FileId;
            _commandRvRomWrite.ExecuteNonQuery();
        }
示例#9
0
        private void RvFileWrite()
        {
            if (_commandRvFileWrite == null)
            {
                _commandRvFileWrite = new SQLiteCommand(
                    @"INSERT INTO FILES (size,compressedsize,crc,sha1,md5,alttype,altsize,altcrc,altsha1,altmd5)
                        VALUES (@Size,@compressedsize,@CRC,@SHA1,@MD5,@alttype,@altsize,@altcrc,@altsha1,@altmd5);
                    SELECT last_insert_rowid();", Program.db.Connection);

                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("size"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("compressedsize"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("crc"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("sha1"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("md5"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("alttype"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("altsize"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("altcrc"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("altsha1"));
                _commandRvFileWrite.Parameters.Add(new SQLiteParameter("altmd5"));
            }

            _commandRvFileWrite.Parameters["size"].Value           = Size;
            _commandRvFileWrite.Parameters["compressedsize"].Value = CompressedSize;
            _commandRvFileWrite.Parameters["crc"].Value            = VarFix.ToDBString(CRC);
            _commandRvFileWrite.Parameters["sha1"].Value           = VarFix.ToDBString(SHA1);
            _commandRvFileWrite.Parameters["md5"].Value            = VarFix.ToDBString(MD5);
            _commandRvFileWrite.Parameters["alttype"].Value        = (int)AltType;
            _commandRvFileWrite.Parameters["altsize"].Value        = AltSize;
            _commandRvFileWrite.Parameters["altcrc"].Value         = VarFix.ToDBString(AltCRC);
            _commandRvFileWrite.Parameters["altsha1"].Value        = VarFix.ToDBString(AltSHA1);
            _commandRvFileWrite.Parameters["altmd5"].Value         = VarFix.ToDBString(AltMD5);

            object res = _commandRvFileWrite.ExecuteScalar();

            FileId = Convert.ToUInt32(res);
        }
示例#10
0
        private static bool FindInROMs(RvFile tFile)
        {
            if ((_commandFindInRoMsZero == null) || (_commandFindInRoMs == null))
            {
                _commandFindInRoMsZero = new SQLiteCommand(@"
                    SELECT count(1) AS TotalFound FROM ROM WHERE
                        ( sha1=@SHA1 OR sha1 is NULL ) AND 
                        ( md5=@MD5 OR md5 is NULL) AND
                        ( crc=@CRC OR crc is NULL ) AND
                        ( size=0 and (status !='nodump' or status is null)) ", DBSqlite.db.Connection);
                _commandFindInRoMsZero.Parameters.Add(new SQLiteParameter("crc"));
                _commandFindInRoMsZero.Parameters.Add(new SQLiteParameter("sha1"));
                _commandFindInRoMsZero.Parameters.Add(new SQLiteParameter("md5"));


                _commandFindInRoMs = new SQLiteCommand(@"
                        SELECT
                        (
                            SELECT count(1) FROM ROM WHERE
                                ( sha1=@SHA1 ) AND 
                                ( md5=@MD5 OR md5 is NULL) AND
                                ( crc=@CRC OR crc is NULL ) AND
                                ( size=@size OR size is NULL )
                        ) +
                        (
                            SELECT count(1) FROM ROM WHERE
                                ( md5=@MD5 ) AND
                                ( sha1=@SHA1 OR sha1 is NULL ) AND 
                                ( crc=@CRC OR crc is NULL ) AND
                                ( size=@size OR size is NULL )
                        ) +
                        (
                            SELECT count(1) FROM ROM WHERE
                                ( crc=@CRC ) AND
                                ( sha1=@SHA1 OR sha1 is NULL ) AND 
                                ( md5=@MD5 OR md5 is NULL) AND
                                ( size=@size OR size is NULL )
                        ) 
                        AS TotalFound", DBSqlite.db.Connection);
                _commandFindInRoMs.Parameters.Add(new SQLiteParameter("size"));
                _commandFindInRoMs.Parameters.Add(new SQLiteParameter("crc"));
                _commandFindInRoMs.Parameters.Add(new SQLiteParameter("sha1"));
                _commandFindInRoMs.Parameters.Add(new SQLiteParameter("md5"));
            }

            if (tFile.Size == 0)
            {
                _commandFindInRoMsZero.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                _commandFindInRoMsZero.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
                _commandFindInRoMsZero.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);

                object resZero = _commandFindInRoMsZero.ExecuteScalar();

                if ((resZero == null) || (resZero == DBNull.Value))
                {
                    return(false);
                }
                int countZero = Convert.ToInt32(resZero);

                return(countZero > 0);
            }

            _commandFindInRoMs.Parameters["size"].Value = tFile.Size;
            _commandFindInRoMs.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
            _commandFindInRoMs.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
            _commandFindInRoMs.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);

            object res = _commandFindInRoMs.ExecuteScalar();

            if ((res == null) || (res == DBNull.Value))
            {
                return(false);
            }
            int count = Convert.ToInt32(res);

            return(count > 0);
        }
示例#11
0
        public static uint?FindAFile(RvRom tFile)
        {
            if (_commandSHA1 == null)
            {
                _commandSHA1 = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
	                                    (                  @sha1 = sha1 ) AND
	                                    ( @md5  is NULL OR @md5  = md5  ) AND
	                                    ( @crc  is NULL OR @crc  = crc  ) AND
	                                    ( @size is NULL OR @size = Size )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandSHA1.Parameters.Add(new SQLiteParameter("sha1"));
                _commandSHA1.Parameters.Add(new SQLiteParameter("md5"));
                _commandSHA1.Parameters.Add(new SQLiteParameter("crc"));
                _commandSHA1.Parameters.Add(new SQLiteParameter("size"));


                _commandSHA1Alt = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
                                        (               @alttype = alttype ) AND
	                                    (                  @sha1 = altsha1 ) AND
	                                    ( @md5  is NULL OR @md5  = altmd5  ) AND
	                                    ( @crc  is NULL OR @crc  = altcrc  ) AND
	                                    ( @size is NULL OR @size = altSize )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandSHA1Alt.Parameters.Add(new SQLiteParameter("alttype"));
                _commandSHA1Alt.Parameters.Add(new SQLiteParameter("sha1"));
                _commandSHA1Alt.Parameters.Add(new SQLiteParameter("md5"));
                _commandSHA1Alt.Parameters.Add(new SQLiteParameter("crc"));
                _commandSHA1Alt.Parameters.Add(new SQLiteParameter("size"));


                _commandMD5 = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
	                                    (                  @md5  = md5  ) AND
	                                    ( @crc  is NULL OR @crc  = crc  ) AND
	                                    ( @size is NULL OR @size = Size )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandMD5.Parameters.Add(new SQLiteParameter("md5"));
                _commandMD5.Parameters.Add(new SQLiteParameter("crc"));
                _commandMD5.Parameters.Add(new SQLiteParameter("size"));

                _commandMD5Alt = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
                                        (               @alttype = alttype ) AND
	                                    (                  @md5  = altmd5  ) AND
	                                    ( @crc  is NULL OR @crc  = altcrc  ) AND
	                                    ( @size is NULL OR @size = altSize )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandMD5Alt.Parameters.Add(new SQLiteParameter("alttype"));
                _commandMD5Alt.Parameters.Add(new SQLiteParameter("md5"));
                _commandMD5Alt.Parameters.Add(new SQLiteParameter("crc"));
                _commandMD5Alt.Parameters.Add(new SQLiteParameter("size"));

                _commandCRC = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
	                                    (                  @crc  = crc  ) AND
	                                    ( @size is NULL OR @size = Size )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandCRC.Parameters.Add(new SQLiteParameter("crc"));
                _commandCRC.Parameters.Add(new SQLiteParameter("size"));

                _commandCRCAlt = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
                                        (               @alttype = alttype ) AND
	                                    (                  @crc  = altcrc  ) AND
	                                    ( @size is NULL OR @size = altSize )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandCRCAlt.Parameters.Add(new SQLiteParameter("alttype"));
                _commandCRCAlt.Parameters.Add(new SQLiteParameter("crc"));
                _commandCRCAlt.Parameters.Add(new SQLiteParameter("size"));


                _commandSize = new SQLiteCommand(@"
                       select FileId from FILES
                            WHERE
	                                    ( @size = Size )
                            limit 1
                ", DBSqlite.db.Connection);

                _commandSize.Parameters.Add(new SQLiteParameter("size"));
            }


            if (tFile.SHA1 != null)
            {
                _commandSHA1.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1);
                _commandSHA1.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);
                _commandSHA1.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                _commandSHA1.Parameters["size"].Value = tFile.Size;

                object res = _commandSHA1.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }

                if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(tFile.AltType))
                {
                    return(null);
                }

                _commandSHA1Alt.Parameters["alttype"].Value = (int)tFile.AltType;
                _commandSHA1Alt.Parameters["sha1"].Value    = VarFix.ToDBString(tFile.SHA1);
                _commandSHA1Alt.Parameters["md5"].Value     = VarFix.ToDBString(tFile.MD5);
                _commandSHA1Alt.Parameters["crc"].Value     = VarFix.ToDBString(tFile.CRC);
                _commandSHA1Alt.Parameters["size"].Value    = tFile.Size;

                res = _commandSHA1Alt.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }

                return(null);
            }

            if (tFile.MD5 != null)
            {
                _commandMD5.Parameters["md5"].Value  = VarFix.ToDBString(tFile.MD5);
                _commandMD5.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                _commandMD5.Parameters["size"].Value = tFile.Size;

                object res = _commandMD5.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }

                if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(tFile.AltType))
                {
                    return(null);
                }

                _commandMD5Alt.Parameters["alttype"].Value = (int)tFile.AltType;
                _commandMD5Alt.Parameters["md5"].Value     = VarFix.ToDBString(tFile.MD5);
                _commandMD5Alt.Parameters["crc"].Value     = VarFix.ToDBString(tFile.CRC);
                _commandMD5Alt.Parameters["size"].Value    = tFile.Size;

                res = _commandMD5Alt.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }

                return(null);
            }

            if (tFile.CRC != null)
            {
                _commandCRC.Parameters["crc"].Value  = VarFix.ToDBString(tFile.CRC);
                _commandCRC.Parameters["size"].Value = tFile.Size;

                object res = _commandCRC.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }

                if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(tFile.AltType))
                {
                    return(null);
                }

                _commandCRCAlt.Parameters["alttype"].Value = (int)tFile.AltType;
                _commandCRCAlt.Parameters["crc"].Value     = VarFix.ToDBString(tFile.CRC);
                _commandCRCAlt.Parameters["size"].Value    = tFile.Size;

                res = _commandCRCAlt.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }

                return(null);
            }


            if (tFile.Size != null && tFile.Size == 0)
            {
                _commandSize.Parameters["size"].Value = tFile.Size;

                object res = _commandSize.ExecuteScalar();
                if (res != null && res != DBNull.Value)
                {
                    return((uint?)Convert.ToInt32(res));
                }
            }

            return(null);
        }
示例#12
0
        private static void FileUpdateRomAlt(RvFile file)
        {
            if (_commandRvFileUpdateRomAlt == null)
            {
                _commandRvFileUpdateRomAlt = new SQLiteCommand(
                    @"
                    UPDATE ROM SET 
	                    FileId = @FileId,
                        LocalFileHeader = null,
                        LocalFileHeaderOffset = null,
                        LocalFileHeaderLength=null
                    WHERE
                        (                 type = @type ) AND
	                    (                 sha1 = @sha1 ) AND
	                    ( md5  is NULL OR md5  = @md5  ) AND 
	                    ( crc  is NULL OR crc  = @crc  ) AND
	                    ( size is NULL OR size = @Size ) AND
                        FileId IS NULL;
		
                    UPDATE ROM SET 
	                    FileId = @FileId,
                        LocalFileHeader = null,
                        LocalFileHeaderOffset = null,
                        LocalFileHeaderLength=null
                    WHERE
                        (                 type = @type ) AND
	                    (                 md5  = @md5  ) AND 
	                    ( sha1 is NULL OR sha1 = @sha1 ) AND
	                    ( crc  is NULL OR crc  = @crc  ) AND
	                    ( size is NULL OR size = @Size ) AND
                        FileId IS NULL;
		
                    UPDATE ROM SET 
	                    FileId = @FileId,
                        LocalFileHeader = null,
                        LocalFileHeaderOffset = null,
                        LocalFileHeaderLength=null
                    WHERE
                        (                 type = @type ) AND
	                    (                 crc  = @crc  ) AND
	                    ( sha1 is NULL OR sha1 = @sha1 ) AND
	                    ( md5  is NULL OR md5  = @md5  ) AND 
	                    ( size is NULL OR size = @Size ) AND
                        FileId IS NULL;
                ", Program.db.Connection);
                _commandRvFileUpdateRomAlt.Parameters.Add(new SQLiteParameter("FileId"));
                _commandRvFileUpdateRomAlt.Parameters.Add(new SQLiteParameter("type"));
                _commandRvFileUpdateRomAlt.Parameters.Add(new SQLiteParameter("size"));
                _commandRvFileUpdateRomAlt.Parameters.Add(new SQLiteParameter("crc"));
                _commandRvFileUpdateRomAlt.Parameters.Add(new SQLiteParameter("sha1"));
                _commandRvFileUpdateRomAlt.Parameters.Add(new SQLiteParameter("md5"));
            }

            _commandRvFileUpdateRomAlt.Parameters["FileId"].Value = file.FileId;
            _commandRvFileUpdateRomAlt.Parameters["type"].Value   = file.AltType;
            _commandRvFileUpdateRomAlt.Parameters["size"].Value   = file.AltSize;
            _commandRvFileUpdateRomAlt.Parameters["crc"].Value    = VarFix.ToDBString(file.AltCRC);
            _commandRvFileUpdateRomAlt.Parameters["sha1"].Value   = VarFix.ToDBString(file.AltSHA1);
            _commandRvFileUpdateRomAlt.Parameters["md5"].Value    = VarFix.ToDBString(file.AltMD5);
            _commandRvFileUpdateRomAlt.ExecuteNonQuery();
        }