mirror of
https://github.com/claunia/osrepodbmgr.git
synced 2025-12-16 19:14:25 +00:00
Added fields to DB to store virus scanning and crack status of files.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
@@ -36,7 +36,7 @@ namespace osrepodbmgr.Core
|
||||
{
|
||||
public static List<string> files;
|
||||
public static List<string> folders;
|
||||
public static Dictionary<string, DBFile> hashes;
|
||||
public static Dictionary<string, DBOSFile> hashes;
|
||||
public static Dictionary<string, DBFolder> foldersDict;
|
||||
public static string path;
|
||||
public static DBEntry dbInfo;
|
||||
|
||||
@@ -55,6 +55,18 @@ namespace osrepodbmgr.Core
|
||||
}
|
||||
|
||||
public struct DBFile
|
||||
{
|
||||
public ulong Id;
|
||||
public string Sha256;
|
||||
public bool Crack;
|
||||
public bool? VirusScanned;
|
||||
public DateTime? ClamTime;
|
||||
public DateTime? VirusTotalTime;
|
||||
public string Virus;
|
||||
public long Length;
|
||||
}
|
||||
|
||||
public struct DBOSFile
|
||||
{
|
||||
public ulong Id;
|
||||
public string Path;
|
||||
@@ -247,24 +259,67 @@ namespace osrepodbmgr.Core
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddFile(string hash)
|
||||
IDbCommand GetFileCommand(DBFile entry)
|
||||
{
|
||||
//Console.WriteLine("Adding {0}", hash);
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
IDbDataParameter param1 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param2 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param3 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param4 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param5 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param6 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param7 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@hash";
|
||||
param1.ParameterName = "@sha256";
|
||||
param2.ParameterName = "@crack";
|
||||
param3.ParameterName = "@virscan";
|
||||
param4.ParameterName = "@clamtime";
|
||||
param5.ParameterName = "@vtotaltime";
|
||||
param6.ParameterName = "@virus";
|
||||
param7.ParameterName = "@length";
|
||||
|
||||
param1.DbType = DbType.String;
|
||||
param2.DbType = DbType.Boolean;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.String;
|
||||
param5.DbType = DbType.String;
|
||||
param7.DbType = DbType.UInt64;
|
||||
|
||||
param1.Value = hash;
|
||||
param1.Value = entry.Sha256;
|
||||
param2.Value = entry.Crack;
|
||||
param3.Value = entry.VirusScanned;
|
||||
if(entry.ClamTime != null)
|
||||
param4.Value = entry.ClamTime.Value.ToString("yyyy-MM-dd HH:mm");
|
||||
else
|
||||
param4.Value = null;
|
||||
if(entry.VirusTotalTime != null)
|
||||
param5.Value = entry.VirusTotalTime.Value.ToString("yyyy-MM-dd HH:mm");
|
||||
else
|
||||
param5.Value = null;
|
||||
param6.Value = entry.Virus;
|
||||
param7.Value = entry.Length;
|
||||
|
||||
dbcmd.Parameters.Add(param1);
|
||||
dbcmd.Parameters.Add(param2);
|
||||
dbcmd.Parameters.Add(param3);
|
||||
dbcmd.Parameters.Add(param4);
|
||||
dbcmd.Parameters.Add(param5);
|
||||
dbcmd.Parameters.Add(param6);
|
||||
dbcmd.Parameters.Add(param7);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
|
||||
public bool AddFile(DBFile file)
|
||||
{
|
||||
IDbCommand dbcmd = GetFileCommand(file);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string sql = "INSERT INTO files (sha256) VALUES (@hash)";
|
||||
const string sql = "INSERT INTO `files` (`sha256`, `crack`, `virscan`, `clamtime`, `vtotaltime`, `virus`, `length`)" +
|
||||
" VALUES (@sha256, @crack, @virscan, @clamtime, @vtotaltime, @virus, @length)";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
@@ -299,7 +354,62 @@ namespace osrepodbmgr.Core
|
||||
return false;
|
||||
}
|
||||
|
||||
IDbCommand GetFileCommand(DBFile person)
|
||||
public ulong GetFilesCount()
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM files";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try
|
||||
{
|
||||
return Convert.ToUInt64(count);
|
||||
}
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
public bool GetFiles(out List<DBFile> entries, long start, long count)
|
||||
{
|
||||
entries = new List<DBFile>();
|
||||
|
||||
string sql = string.Format("SELECT * FROM files LIMIT {0}, {1} ORDER BY id", count, start);
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbcmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbcmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
DataTable dataTable = dataSet.Tables[0];
|
||||
|
||||
foreach(DataRow dRow in dataTable.Rows)
|
||||
{
|
||||
DBFile fEntry = new DBFile();
|
||||
|
||||
fEntry.Id = ulong.Parse(dRow["id"].ToString());
|
||||
fEntry.Sha256 = dRow["sha256"].ToString();
|
||||
fEntry.Crack = bool.Parse(dRow["crack"].ToString());
|
||||
if(dRow["virscan"] == DBNull.Value)
|
||||
fEntry.VirusScanned = null;
|
||||
else
|
||||
fEntry.VirusScanned = bool.Parse(dRow["virscan"].ToString());
|
||||
if(dRow["clamtime"] == DBNull.Value)
|
||||
fEntry.ClamTime = null;
|
||||
else
|
||||
fEntry.ClamTime = DateTime.Parse(dRow["clamtime"].ToString());
|
||||
if(dRow["vtotaltime"] == DBNull.Value)
|
||||
fEntry.VirusTotalTime = null;
|
||||
else
|
||||
fEntry.VirusTotalTime = DateTime.Parse(dRow["vtotaltime"].ToString());
|
||||
fEntry.Virus = dRow["virus"].ToString();
|
||||
fEntry.Length = long.Parse(dRow["length"].ToString());
|
||||
|
||||
entries.Add(fEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetOSFileCommand(DBOSFile person)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
@@ -346,9 +456,9 @@ namespace osrepodbmgr.Core
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
public bool AddFileToOS(DBFile file, long os)
|
||||
public bool AddFileToOS(DBOSFile file, long os)
|
||||
{
|
||||
IDbCommand dbcmd = GetFileCommand(file);
|
||||
IDbCommand dbcmd = GetOSFileCommand(file);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
@@ -557,9 +667,9 @@ namespace osrepodbmgr.Core
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetAllFiles(out List<DBFile> entries, long id)
|
||||
public bool GetAllFilesInOS(out List<DBOSFile> entries, long id)
|
||||
{
|
||||
entries = new List<DBFile>();
|
||||
entries = new List<DBOSFile>();
|
||||
|
||||
string sql = string.Format("SELECT * from os_{0}", id);
|
||||
|
||||
@@ -573,7 +683,7 @@ namespace osrepodbmgr.Core
|
||||
|
||||
foreach(DataRow dRow in dataTable.Rows)
|
||||
{
|
||||
DBFile fEntry = new DBFile();
|
||||
DBOSFile fEntry = new DBOSFile();
|
||||
fEntry.Id = ulong.Parse(dRow["id"].ToString());
|
||||
fEntry.Path = dRow["path"].ToString();
|
||||
fEntry.Sha256 = dRow["sha256"].ToString();
|
||||
|
||||
@@ -35,9 +35,18 @@ namespace osrepodbmgr.Core
|
||||
"DROP TABLE IF EXISTS `files` ;\n\n" +
|
||||
"CREATE TABLE IF NOT EXISTS `files` (\n" +
|
||||
" `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" `sha256` VARCHAR(64) NOT NULL);\n\n" +
|
||||
" `sha256` VARCHAR(64) NOT NULL,\n" +
|
||||
" `crack` BOOLEAN NOT NULL,\n" +
|
||||
" `virscan` BOOLEAN NULL,\n" +
|
||||
" `clamtime` DATETIME NULL,\n" +
|
||||
" `vtotaltime` DATETIME NULL,\n" +
|
||||
" `virus` VARCHAR(128) NULL,\n" +
|
||||
" `length` BIGINT NOT NULL);\n\n" +
|
||||
"CREATE UNIQUE INDEX `files_id_UNIQUE` ON `files` (`id` ASC);\n\n" +
|
||||
"CREATE UNIQUE INDEX `files_sha256_UNIQUE` ON `files` (`sha256` ASC);";
|
||||
"CREATE UNIQUE INDEX `files_sha256_UNIQUE` ON `files` (`sha256` ASC);\n\n" +
|
||||
"CREATE INDEX `files_virscan_idx` ON `files` (`virscan` ASC);\n\n" +
|
||||
"CREATE INDEX `files_virus_idx` ON `files` (`virus` ASC);\n\n" +
|
||||
"CREATE INDEX `files_length_idx` ON `files` (`length` ASC);";
|
||||
|
||||
public const string OSesTableSql = "-- -----------------------------------------------------\n" +
|
||||
"-- Table `oses`\n" +
|
||||
@@ -54,12 +63,12 @@ namespace osrepodbmgr.Core
|
||||
" `machine` VARCHAR(45) NULL,\n" +
|
||||
" `format` VARCHAR(45) NULL,\n" +
|
||||
" `description` VARCHAR(45) NULL,\n" +
|
||||
" `oem` BOOLEAN NULL,\n" +
|
||||
" `upgrade` BOOLEAN NULL,\n" +
|
||||
" `update` BOOLEAN NULL,\n" +
|
||||
" `source` BOOLEAN NULL,\n" +
|
||||
" `files` BOOLEAN NULL,\n" +
|
||||
" `netinstall` BOOLEAN NULL,\n" +
|
||||
" `oem` BOOLEAN NOT NULL,\n" +
|
||||
" `upgrade` BOOLEAN NOT NULL,\n" +
|
||||
" `update` BOOLEAN NOT NULL,\n" +
|
||||
" `source` BOOLEAN NOT NULL,\n" +
|
||||
" `files` BOOLEAN NOT NULL,\n" +
|
||||
" `netinstall` BOOLEAN NOT NULL,\n" +
|
||||
" `xml` BLOB NULL,\n" +
|
||||
" `json` BLOB NULL);\n\n" +
|
||||
"CREATE UNIQUE INDEX `oses_id_UNIQUE` ON `oses` (`id` ASC);\n\n" +
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
@@ -112,7 +112,7 @@ namespace osrepodbmgr.Core
|
||||
{
|
||||
try
|
||||
{
|
||||
Context.hashes = new Dictionary<string, DBFile>();
|
||||
Context.hashes = new Dictionary<string, DBOSFile>();
|
||||
Context.foldersDict = new Dictionary<string, DBFolder>();
|
||||
List<string> alreadyMetadata = new List<string>();
|
||||
bool foundMetadata = false;
|
||||
@@ -375,7 +375,8 @@ namespace osrepodbmgr.Core
|
||||
fileStream.Read(dataBuffer, 0, (int)remainder);
|
||||
sha256Context.Update(dataBuffer);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(string.Format("{0:P}", 0 / (double)fileStream.Length), relpath, 0, fileStream.Length);
|
||||
dataBuffer = new byte[fileStream.Length];
|
||||
@@ -386,7 +387,7 @@ namespace osrepodbmgr.Core
|
||||
fileStream.Close();
|
||||
string hash = stringify(sha256Context.Final());
|
||||
|
||||
DBFile dbFile = new DBFile();
|
||||
DBOSFile dbFile = new DBOSFile();
|
||||
dbFile.Attributes = fi.Attributes;
|
||||
dbFile.CreationTimeUtc = fi.CreationTimeUtc;
|
||||
dbFile.LastAccessTimeUtc = fi.LastAccessTimeUtc;
|
||||
@@ -531,7 +532,7 @@ namespace osrepodbmgr.Core
|
||||
try
|
||||
{
|
||||
long counter = 0;
|
||||
foreach(KeyValuePair<string, DBFile> kvp in Context.hashes)
|
||||
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Checking files in database", counter, Context.hashes.Count);
|
||||
@@ -559,7 +560,7 @@ namespace osrepodbmgr.Core
|
||||
UpdateProgress(null, string.Format("Check OS id {0}", os.id), osCounter, osesArray.Length);
|
||||
|
||||
counter = 0;
|
||||
foreach(KeyValuePair<string, DBFile> kvp in Context.hashes)
|
||||
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
|
||||
{
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(null, string.Format("Checking for file {0}", kvp.Value.Path), counter, Context.hashes.Count);
|
||||
@@ -612,13 +613,17 @@ namespace osrepodbmgr.Core
|
||||
try
|
||||
{
|
||||
long counter = 0;
|
||||
foreach(KeyValuePair<string, DBFile> kvp in Context.hashes)
|
||||
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Adding files to database", counter, Context.hashes.Count);
|
||||
|
||||
if(!dbCore.DBOps.ExistsFile(kvp.Value.Sha256))
|
||||
dbCore.DBOps.AddFile(kvp.Value.Sha256);
|
||||
dbCore.DBOps.AddFile(new DBFile
|
||||
{
|
||||
Sha256 = kvp.Value.Sha256, ClamTime = null, Crack = false,
|
||||
Length = kvp.Value.Length, Virus = null, VirusScanned = null, VirusTotalTime = null
|
||||
});
|
||||
|
||||
counter++;
|
||||
}
|
||||
@@ -631,7 +636,7 @@ namespace osrepodbmgr.Core
|
||||
dbCore.DBOps.CreateTableForOS(Context.dbInfo.id);
|
||||
|
||||
counter = 0;
|
||||
foreach(KeyValuePair<string, DBFile> kvp in Context.hashes)
|
||||
foreach(KeyValuePair<string, DBOSFile> kvp in Context.hashes)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(null, "Adding files to OS in database", counter, Context.hashes.Count);
|
||||
@@ -701,7 +706,8 @@ namespace osrepodbmgr.Core
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if(!dbCore.CreateDB(Settings.Current.DatabasePath, null, null, null))
|
||||
{
|
||||
if(Failed != null)
|
||||
@@ -879,7 +885,7 @@ namespace osrepodbmgr.Core
|
||||
break;
|
||||
}
|
||||
|
||||
foreach(KeyValuePair<string, DBFile> file in Context.hashes)
|
||||
foreach(KeyValuePair<string, DBOSFile> file in Context.hashes)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("Compressing...", file.Value.Path, counter, Context.hashes.Count);
|
||||
@@ -934,8 +940,8 @@ namespace osrepodbmgr.Core
|
||||
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2(string.Format("{0:P}", inFs.Length / (double)inFs.Length),
|
||||
"Finishing...",inFs.Length, inFs.Length);
|
||||
|
||||
"Finishing...", inFs.Length, inFs.Length);
|
||||
|
||||
inFs.Close();
|
||||
zStream.Close();
|
||||
}
|
||||
@@ -974,7 +980,7 @@ namespace osrepodbmgr.Core
|
||||
jms.Position = 0;
|
||||
}
|
||||
|
||||
if(FinishedWithText!= null)
|
||||
if(FinishedWithText != null)
|
||||
FinishedWithText(string.Format("Correctly added operating system with MDID {0}", mdid));
|
||||
}
|
||||
catch(Exception ex)
|
||||
@@ -1419,14 +1425,14 @@ namespace osrepodbmgr.Core
|
||||
return;
|
||||
}
|
||||
|
||||
List<DBFile> files;
|
||||
List<DBOSFile> files;
|
||||
List<DBFolder> folders;
|
||||
long counter;
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("", "Asking DB for files...", 1, 100);
|
||||
|
||||
dbCore.DBOps.GetAllFiles(out files, Context.dbInfo.id);
|
||||
dbCore.DBOps.GetAllFilesInOS(out files, Context.dbInfo.id);
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("", "Asking DB for folders...", 2, 100);
|
||||
@@ -1452,7 +1458,7 @@ namespace osrepodbmgr.Core
|
||||
}
|
||||
|
||||
counter = 3;
|
||||
foreach(DBFile file in files)
|
||||
foreach(DBOSFile file in files)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("", string.Format("Creating {0}...", file.Path), counter, 3 + files.Count);
|
||||
@@ -1610,14 +1616,14 @@ namespace osrepodbmgr.Core
|
||||
zf.EmitTimesInWindowsFormatWhenSaving = true;
|
||||
zf.UseZip64WhenSaving = Zip64Option.AsNecessary;
|
||||
zf.SortEntriesBeforeSaving = true;
|
||||
List<DBFile> files;
|
||||
List<DBOSFile> files;
|
||||
List<DBFolder> folders;
|
||||
long counter;
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("", "Asking DB for files...", 1, 100);
|
||||
|
||||
dbCore.DBOps.GetAllFiles(out files, Context.dbInfo.id);
|
||||
dbCore.DBOps.GetAllFilesInOS(out files, Context.dbInfo.id);
|
||||
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("", "Asking DB for folders...", 2, 100);
|
||||
@@ -1644,8 +1650,8 @@ namespace osrepodbmgr.Core
|
||||
}
|
||||
|
||||
counter = 3;
|
||||
Context.hashes = new Dictionary<string, DBFile>();
|
||||
foreach(DBFile file in files)
|
||||
Context.hashes = new Dictionary<string, DBOSFile>();
|
||||
foreach(DBOSFile file in files)
|
||||
{
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress("", string.Format("Adding {0}...", file.Path), counter, 3 + files.Count);
|
||||
@@ -1677,10 +1683,10 @@ namespace osrepodbmgr.Core
|
||||
|
||||
static Stream Zf_HandleOpen(string entryName)
|
||||
{
|
||||
DBFile file;
|
||||
DBOSFile file;
|
||||
if(!Context.hashes.TryGetValue(entryName, out file))
|
||||
{
|
||||
if (!Context.hashes.TryGetValue(entryName.Replace('/', '\\'), out file))
|
||||
if(!Context.hashes.TryGetValue(entryName.Replace('/', '\\'), out file))
|
||||
throw new ArgumentException("Cannot find requested zip entry in hashes dictionary");
|
||||
}
|
||||
|
||||
@@ -1771,7 +1777,7 @@ namespace osrepodbmgr.Core
|
||||
|
||||
if(e.EventType == ZipProgressEventType.Error_Saving && Failed != null)
|
||||
Failed("An error occurred creating ZIP file.");
|
||||
|
||||
|
||||
if(e.EventType == ZipProgressEventType.Saving_Completed && Finished != null)
|
||||
Finished();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user