public static void CheckDbForFiles() { try { long counter = 0; #if DEBUG stopwatch.Restart(); #endif Dictionary <string, DbAppFile> knownFiles = new Dictionary <string, DbAppFile>(); bool unknownFile = false; foreach (KeyValuePair <string, DbAppFile> kvp in Context.Hashes) { // Empty file with size zero if (kvp.Value.Sha256 == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") { AddFileForApp(kvp.Key, kvp.Value.Sha256, true, kvp.Value.Crack); counter++; continue; } UpdateProgress?.Invoke(null, "Checking files in database", counter, Context.Hashes.Count); AddFileForApp?.Invoke(kvp.Key, kvp.Value.Sha256, dbCore.DbOps.ExistsFile(kvp.Value.Sha256), kvp.Value.Crack); if (dbCore.DbOps.ExistsFile(kvp.Value.Sha256)) { counter++; knownFiles.Add(kvp.Key, kvp.Value); } else { unknownFile = true; } } #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds to checks for file knowledge in the DB", stopwatch.Elapsed.TotalSeconds); stopwatch.Restart(); #endif if (knownFiles.Count == 0 || unknownFile) { Finished?.Invoke(); return; } UpdateProgress?.Invoke(null, "Retrieving apps from database", counter, Context.Hashes.Count); dbCore.DbOps.GetAllApps(out List <DbEntry> apps); #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds get all apps from DB", stopwatch.Elapsed.TotalSeconds); #endif if (apps != null && apps.Count > 0) { DbEntry[] appsArray = new DbEntry[apps.Count]; apps.CopyTo(appsArray); long appCounter = 0; #if DEBUG stopwatch.Restart(); #endif foreach (DbEntry app in appsArray) { UpdateProgress?.Invoke(null, $"Check application id {app.Id}", appCounter, appsArray.Length); counter = 0; foreach (KeyValuePair <string, DbAppFile> kvp in knownFiles) { UpdateProgress2?.Invoke(null, $"Checking for file {kvp.Value.Path}", counter, knownFiles.Count); if (!dbCore.DbOps.ExistsFileInApp(kvp.Value.Sha256, app.Id)) { if (apps.Contains(app)) { apps.Remove(app); } // If one file is missing, the rest don't matter break; } counter++; } if (apps.Count == 0) { break; // No apps left } } #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds correlate all files with all known applications", stopwatch.Elapsed.TotalSeconds); #endif } if (AddApp != null) { foreach (DbEntry app in apps) { AddApp?.Invoke(app); } } Finished?.Invoke(); } catch (ThreadAbortException) {} catch (Exception ex) { if (Debugger.IsAttached) { throw; } Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}"); #if DEBUG Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException); #endif } }
IDbCommand GetAppCommand(DbEntry entry) { 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(); IDbDataParameter param8 = dbcmd.CreateParameter(); IDbDataParameter param9 = dbcmd.CreateParameter(); IDbDataParameter param10 = dbcmd.CreateParameter(); IDbDataParameter param11 = dbcmd.CreateParameter(); IDbDataParameter param12 = dbcmd.CreateParameter(); IDbDataParameter param13 = dbcmd.CreateParameter(); IDbDataParameter param14 = dbcmd.CreateParameter(); IDbDataParameter param15 = dbcmd.CreateParameter(); IDbDataParameter param16 = dbcmd.CreateParameter(); IDbDataParameter param17 = dbcmd.CreateParameter(); IDbDataParameter param18 = dbcmd.CreateParameter(); param1.ParameterName = "@developer"; param2.ParameterName = "@product"; param3.ParameterName = "@version"; param4.ParameterName = "@languages"; param5.ParameterName = "@architecture"; param6.ParameterName = "@targetos"; param7.ParameterName = "@format"; param8.ParameterName = "@description"; param9.ParameterName = "@oem"; param10.ParameterName = "@upgrade"; param11.ParameterName = "@update"; param12.ParameterName = "@source"; param13.ParameterName = "@files"; param14.ParameterName = "@installer"; param15.ParameterName = "@xml"; param16.ParameterName = "@json"; param17.ParameterName = "@mdid"; param18.ParameterName = "@icon"; param1.DbType = DbType.String; param2.DbType = DbType.String; param3.DbType = DbType.String; param4.DbType = DbType.String; param5.DbType = DbType.String; param7.DbType = DbType.String; param8.DbType = DbType.String; param9.DbType = DbType.Boolean; param10.DbType = DbType.Boolean; param11.DbType = DbType.Boolean; param12.DbType = DbType.Boolean; param13.DbType = DbType.Boolean; param14.DbType = DbType.Boolean; param15.DbType = DbType.Object; param16.DbType = DbType.Object; param17.DbType = DbType.String; param18.DbType = DbType.Object; param1.Value = entry.Developer; param2.Value = entry.Product; param3.Value = entry.Version; param4.Value = entry.Languages; param5.Value = entry.Architecture; param6.Value = entry.TargetOs; param7.Value = entry.Format; param8.Value = entry.Description; param9.Value = entry.Oem; param10.Value = entry.Upgrade; param11.Value = entry.Update; param12.Value = entry.Source; param13.Value = entry.Files; param14.Value = entry.Installer; param15.Value = entry.Xml; param16.Value = entry.Json; param17.Value = entry.Mdid; param18.Value = entry.Icon; 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); dbcmd.Parameters.Add(param8); dbcmd.Parameters.Add(param9); dbcmd.Parameters.Add(param10); dbcmd.Parameters.Add(param11); dbcmd.Parameters.Add(param12); dbcmd.Parameters.Add(param13); dbcmd.Parameters.Add(param14); dbcmd.Parameters.Add(param15); dbcmd.Parameters.Add(param16); dbcmd.Parameters.Add(param17); dbcmd.Parameters.Add(param18); return(dbcmd); }