public void DoQuickGen(QuickGenMode quickgenMode) { if (App.appMode == App.AppMode.quickgen) return; App.appMode = App.AppMode.quickgen; App.ExecuteAction(new Action(() => App.mainWindow.IsEnabled = false)); App.PerformQuickGenLocally(quickgenMode); // show a visual indicator of successfull password generation - green taskbar button App.ExecuteAction(new Action(() => App.mainWindow.TaskbarItemInfo.ProgressValue = 1)); App.ExecuteAction(new Action(() => App.mainWindow.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal)); // show green taskbar button for a while Thread.Sleep(1000); App.ExecuteAction(new Action(() => App.mainWindow.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None)); App.appMode = App.AppMode.normal; App.ExecuteAction(new Action(() => App.mainWindow.IsEnabled = true)); }
//-------------------------------------------------- /// <summary> /// do QuickGen in the current process /// </summary> public static bool PerformQuickGenLocally(QuickGenMode quickgenMode) { PasswordGenerator pswgen = null; switch (quickgenMode) { case QuickGenMode.password: ExecuteAction(new Action(() => mainWindow.PrepareToGeneration(Awesome_Password_Generator.MainWindow.genType.Single, Awesome_Password_Generator.MainWindow.pswType.Password, ref pswgen))); break; case QuickGenMode.wpa: ExecuteAction(new Action(() => mainWindow.PrepareToGeneration(Awesome_Password_Generator.MainWindow.genType.Single, Awesome_Password_Generator.MainWindow.pswType.WPA, ref pswgen))); break; } if (!pswgen.isReady) { MessageBox.Show(String.Format("Can't generate a password!\n\nRun app normally and check generation settings."), "QuickGen - Awesome Password Generator", MessageBoxButton.OK, MessageBoxImage.Error); return false; // error } else { string psw = pswgen.GeneratePassword(); ExecuteAction(new Action(() => Clipboard.SetText(psw))); if (mainWindow.showQuickGenInfoWindow) { ExecuteAction(new Action(() => new QuickGenInfo().ShowDialog())); } else { System.Media.SystemSounds.Asterisk.Play(); } } return true; // ok }
//-------------------------------------------------- // fill the pgo struct and initialize PasswordGenerator class with it void ProcessCmdline() { // quickgen if (CommandLineArgs.ContainsKey("--quickgen")) { App.appMode = App.AppMode.quickgen; string quickGen = CommandLineArgs["--quickgen"].ToString(); if (quickGen.Length == 0) { ReportErrorAndExit("Required argument value is empty: --quickgen", ExitCodes.cmdlineArgError); } switch (GetLongArgOrValueName(quickGen.Split(':')[0])) { case "password": quickGenMode = QuickGenMode.password; break; case "wpa": quickGenMode = QuickGenMode.wpa; break; default: ReportErrorAndExit("Unknown QuickGen mode: --quickgen:" + quickGen.Split(':')[0], ExitCodes.cmdlineArgError); break; } } }