/// <summary> /// Добавление операционной системы /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void operatingSystemNavigation_Click(object sender, EventArgs e) { var form = new AddOS(); form.ShowDialog(); throw new NotImplementedException(); }
public static void GetAllOSes() { try { #if DEBUG stopwatch.Restart(); #endif dbCore.DbOps.GetAllOSes(out List <DbEntry> oses); #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.GetAllOSes(): Took {0} seconds to get OSes from database", stopwatch.Elapsed.TotalSeconds); #endif if (AddOS != null) { #if DEBUG stopwatch.Restart(); #endif int counter = 0; // TODO: Check file name and existence foreach (DbEntry os in oses) { UpdateProgress?.Invoke("Populating OSes table", $"{os.Developer} {os.Product}", counter, oses.Count); 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); counter++; } #if DEBUG stopwatch.Stop(); Console.WriteLine("Core.GetAllOSes(): Took {0} seconds to add OSes to the GUI", stopwatch.Elapsed.TotalSeconds); #endif } 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 } }
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 } }