IDbCommand GetOsCommand(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(); param1.ParameterName = "@developer"; param2.ParameterName = "@product"; param3.ParameterName = "@version"; param4.ParameterName = "@languages"; param5.ParameterName = "@architecture"; param6.ParameterName = "@machine"; param7.ParameterName = "@format"; param8.ParameterName = "@description"; param9.ParameterName = "@oem"; param10.ParameterName = "@upgrade"; param11.ParameterName = "@update"; param12.ParameterName = "@source"; param13.ParameterName = "@files"; param14.ParameterName = "@netinstall"; param15.ParameterName = "@xml"; param16.ParameterName = "@json"; param17.ParameterName = "@mdid"; 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; param1.Value = entry.Developer; param2.Value = entry.Product; param3.Value = entry.Version; param4.Value = entry.Languages; param5.Value = entry.Architecture; param6.Value = entry.Machine; 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.Netinstall; param15.Value = entry.Xml; param16.Value = entry.Json; param17.Value = entry.Mdid; 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); return(dbcmd); }
public static void CheckDbForFiles() { try { long counter = 0; #if DEBUG stopwatch.Restart(); #endif Dictionary <string, DbOsFile> knownFiles = new Dictionary <string, DbOsFile>(); bool unknownFile = false; foreach (KeyValuePair <string, DbOsFile> kvp in Context.Hashes) { // Empty file with size zero if (kvp.Value.Sha256 == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") { AddFileForOS(kvp.Key, kvp.Value.Sha256, true, kvp.Value.Crack); counter++; continue; } UpdateProgress?.Invoke(null, "Checking files in database", counter, Context.Hashes.Count); AddFileForOS?.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 OSes from database", counter, Context.Hashes.Count); dbCore.DbOps.GetAllOSes(out List <DbEntry> oses); #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds get all OSes from DB", stopwatch.Elapsed.TotalSeconds); #endif if (oses != null && oses.Count > 0) { DbEntry[] osesArray = new DbEntry[oses.Count]; oses.CopyTo(osesArray); long osCounter = 0; #if DEBUG stopwatch.Restart(); #endif foreach (DbEntry os in osesArray) { UpdateProgress?.Invoke(null, $"Check OS id {os.Id}", osCounter, osesArray.Length); counter = 0; foreach (KeyValuePair <string, DbOsFile> kvp in knownFiles) { UpdateProgress2?.Invoke(null, $"Checking for file {kvp.Value.Path}", counter, knownFiles.Count); if (!dbCore.DbOps.ExistsFileInOs(kvp.Value.Sha256, os.Id)) { if (oses.Contains(os)) { oses.Remove(os); } // If one file is missing, the rest don't matter break; } counter++; } if (oses.Count == 0) { break; // No OSes left } } #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds correlate all files with all known OSes", stopwatch.Elapsed.TotalSeconds); #endif } if (AddOS != null) { foreach (DbEntry os in oses) { string destination = Path.Combine(Settings.Current.RepositoryPath, os.Mdid[0].ToString(), os.Mdid[1].ToString(), os.Mdid[2].ToString(), os.Mdid[3].ToString(), os.Mdid[4].ToString(), os.Mdid) + ".zip"; AddOS?.Invoke(os); } } 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 } }