public DialogResult CommandBox(string title, string mainInstruction, string content, string expandedInfo, string help, string verificationText, string commandButtons, bool showCancelButton, SysIcons mainIcon, SysIcons footerIcon, DialogResponseHandler handler) { //BringToFront(); TaskDialog dialog = new TaskDialog(); dialog.HelpDelegate = delegate(string url) { Utils.StartProcess(url); }; DialogResult result = dialog.ShowCommandBox(this, title, mainInstruction, content, expandedInfo, FormatHelp(help), verificationText, commandButtons, showCancelButton, mainIcon, footerIcon); handler(dialog.CommandButtonResult, dialog.VerificationChecked); return(result); }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <returns>Crash report as string</returns> public void Write(Exception e) { ExceptionReportInfo info = new ExceptionReportInfo { MainException = e }; ExceptionReportGenerator reportGenerator = new ExceptionReportGenerator(info); ExceptionReport report = reportGenerator.CreateExceptionReport(); string crashDir = Path.Combine(Preferences.instance().getProperty("application.support.path"), "CrashReporter"); Directory.CreateDirectory(crashDir); using (StreamWriter outfile = new StreamWriter(Path.Combine(crashDir, DateTime.Now.Ticks + ".txt"))) { outfile.Write(report.ToString()); } TaskDialog prompt = new TaskDialog(); DialogResult result = prompt.ShowCommandBox(Locale.localizedString("Do you want to report the last crash?", "Crash"), Locale.localizedString("Do you want to report the last crash?", "Crash"), Locale.localizedString( "The application %@ has recently crashed. To help improve it, you can send the crash log to the author.", "Crash").Replace("%@", Preferences.instance().getProperty("application.name")), String.Format("{0}|{1}", Locale.localizedString("Send", "Crash"), Locale.localizedString("Don't Send", "Crash")), false, SysIcons.Error); if (DialogResult.OK == result) { if (0 == prompt.CommandButtonResult) { Post(report.ToString()); } } }
public override bool isTrusted(String hostName, X509Certificate[] certs) { X509Certificate2 serverCert = ConvertCertificate(certs[0]); X509Chain chain = new X509Chain(); //todo Online revocation check. Preference. chain.ChainPolicy.RevocationMode = X509RevocationMode.Offline; // | X509RevocationMode.Online chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0, 10); // set timeout to 10 seconds chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag; for (int index = 1; index < certs.Length; index++) { chain.ChainPolicy.ExtraStore.Add(ConvertCertificate(certs[index])); } chain.Build(serverCert); string errorFromChainStatus = GetErrorFromChainStatus(chain, hostName); bool certError = null != errorFromChainStatus; bool hostnameMismatch = !HostnameVerifier.CheckServerIdentity(certs[0], serverCert, hostName) && !CheckForException(hostName, serverCert); // check if host name matches if (null == errorFromChainStatus && hostnameMismatch) { errorFromChainStatus = Locale.localizedString( "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “%@” which could put your confidential information at risk. Would you like to connect to the server anyway?", "Keychain").Replace("%@", hostName); } if (null != errorFromChainStatus) { while (true) { TaskDialog d = new TaskDialog(); DialogResult r = d.ShowCommandBox(Locale.localizedString("This certificate is not valid", "Keychain"), Locale.localizedString("This certificate is not valid", "Keychain"), errorFromChainStatus, null, null, Locale.localizedString("Always Trust", "Keychain"), String.Format("{0}|{1}|{2}", Locale.localizedString("Continue", "Credentials"), Locale.localizedString("Disconnect"), Locale.localizedString("Show Certificate", "Keychain")), false, SysIcons.Warning, SysIcons.Information); if (r == DialogResult.OK) { if (d.CommandButtonResult == 0) { if (d.VerificationChecked) { if (certError) { //todo can we use the Trusted People and Third Party Certificate Authority Store? Currently X509Chain is the problem. AddCertificate(serverCert, StoreName.Root); } if (hostnameMismatch) { Preferences.instance().setProperty(hostName + ".certificate.accept", serverCert.SubjectName.Name); } } return(true); } if (d.CommandButtonResult == 1) { return(false); } if (d.CommandButtonResult == 2) { X509Certificate2UI.DisplayCertificate(serverCert); } } } } return(true); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); TaskDialog.ForceEmulationMode = true; Version newVersion = null; string version = string.Empty; if (args.Length > 1 && args[0] == "-v") { version = args[1]; newVersion = new Version(version); } else { TaskDialog.ShowCommandBox(Resources.TaskDialog_UpdateToBeta_Title, Resources.TaskDialog_UpdateToBeta_Caption, Resources.TaskDialog_UpdateToBeta_Text, Resources.TaskDialog_UpdateToBeta_Buttons, false); AssemblyName assemblyName = AssemblyName.GetAssemblyName(Path.Combine(Application.StartupPath, "MLifter.exe")); WebClient client = new WebClient(); version = client.DownloadString(string.Format("{0}?base={1}&beta={2}&onstick={3}", Settings.Default.UpdateVersionUrl, assemblyName.Version.ToString(2), (TaskDialog.CommandButtonResult == 0).ToString(), MLifter.Generics.Methods.IsRunningFromStick())); newVersion = new Version(version); if (newVersion <= assemblyName.Version) { TaskDialog.MessageBox(Resources.TASK_DIALOG_NoNewVersionFound_Title, Resources.TASK_DIALOG_NoNewVersionFound_Caption, Resources.TASK_DIALOG_NoNewVersionFound_Text, TaskDialogButtons.OK, TaskDialogIcons.Information); Environment.Exit(-1); } } FileStream stream = null; try { UpdateService updateService = new UpdateService(); byte[] dll = updateService.ServeLatestMLVersion(newVersion.ToString(3), MLifter.Generics.Methods.IsRunningFromStick()); string dllPath = Path.GetTempFileName(); stream = File.OpenWrite(dllPath); stream.Write(dll, 0, dll.Length); stream.Close(); stream = null; Assembly assembly = null; string typeName = string.Empty; Type pluginType = null; if (File.Exists(dllPath)) { assembly = Assembly.LoadFile(dllPath); } else { throw new FileNotFoundException(); } if (assembly != null) { foreach (Type type in assembly.GetTypes()) { if (type.IsAbstract) { continue; } if (type.IsDefined(typeof(UpdateHandler), true)) { pluginType = type; break; } } if (pluginType != null) { IUpdateHandler updateHandler = Activator.CreateInstance(pluginType) as IUpdateHandler; updateHandler.StartUpdateProcess(newVersion); } else { throw new Exception(Resources.Exception_CouldNotFindUpdateLogic); } } else { throw new Exception(Resources.Exception_ErrorLoadingUpdateLogic); } } catch (Exception e) { TaskDialog.MessageBox(Resources.TaskDialog_ErrorStartingUpdate_Title, Resources.TaskDialog_ErrorStartingUpdate_Title, Resources.TaskDialog_ErrorStartingUpdate_Content, e.ToString(), string.Empty, string.Empty, TaskDialogButtons.OK, TaskDialogIcons.Error, TaskDialogIcons.Error); } finally { if (stream != null) { stream.Close(); } } }
/// <summary> /// Handles the UserDialog event of the learnlogic control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MLifter.BusinessLayer.UserDialogEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-04-29</remarks> void learnlogic_UserDialog(object sender, UserDialogEventArgs e) { if (e is UserGradingDialogEventArgs) { int cardbox = e.dictionary.Cards.GetCardByID(e.cardid).BaseCard.Box; int boxcount = e.dictionary.Boxes.Count; UserGradingDialogEventArgs args = (UserGradingDialogEventArgs)e; switch (args.dialogkind) { case UserGradingDialogEventArgs.GradingDialogKind.ConfirmDemote: args.promote = ShowGradeDialog( Resources.CONFIRM_DEMOTE_TITLE, Resources.CONFIRM_DEMOTE_TEXT, Resources.CONFIRM_DEMOTE_DESCRIPTION, string.Empty, false, cardbox, boxcount); break; case UserGradingDialogEventArgs.GradingDialogKind.GradeSynonym: args.promote = ShowGradeDialog( Resources.SYNONYM_GRADING_CAPTION, Resources.SYNONYM_GRADING_TEXT, string.Empty, Resources.SYNONYM_GRADING_EXPANDEDINFO, true, cardbox, boxcount); break; case UserGradingDialogEventArgs.GradingDialogKind.GradeTypo: args.promote = ShowGradeDialog( Resources.ALMOST_CAPTION, Resources.ALMOST_TEXT, string.Empty, Resources.ALMOST_EXPANDEDINFO, true, cardbox, boxcount); break; } } else if (e is UserNotifyDialogEventArgs) { UserNotifyDialogEventArgs args = (UserNotifyDialogEventArgs)e; switch (args.dialogkind) { case UserNotifyDialogEventArgs.NotifyDialogKind.NoWords: ShowNoWordsMessage(); break; case UserNotifyDialogEventArgs.NotifyDialogKind.PoolEmpty: //gets displayed in LearningWindow case UserNotifyDialogEventArgs.NotifyDialogKind.NotEnoughMultipleChoices: //gets displayed in LearningWindow default: break; } } else if (e is UserModuleNotSavedDialogEventArgs) { UserModuleNotSavedDialogEventArgs args = (UserModuleNotSavedDialogEventArgs)e; int command = TaskDialog.ShowCommandBox(Resources.MAIN_CLOSEWITHOUTSAVE_CAPTION, Resources.MAIN_CLOSEWITHOUTSAVE_TEXT, Resources.MAIN_CLOSEWITHOUTSAVE_CONTENT, Resources.MAIN_CLOSEWITHOUTSAVE_COMMANDS, false); switch (command) { case 0: args.tryagain = true; break; case 1: args.cancelClosing = true; break; case 2: break; } } else if (e is BackupCompletedNotifyDialogEventArgs) { ShowBackupCompletedMessage(((BackupCompletedNotifyDialogEventArgs)e).backupFilename); } }
static void Main(string[] arguments) { try { using (var stream = typeof(Program).Assembly.GetManifestResourceStream(DroidExplorer.Resources.Strings.Log4NetDroidExplorer)) { XmlConfigurator.Configure(stream); } var errorMessages = new List <string>(); var args = new Arguments(arguments); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += (sender, e) => DroidExplorer.Core.Logger.LogError(typeof(Program), e.Exception.Message, e.Exception); // show the splash dialog Program.SplashManager.ShowSplashDialog(StartUpStepCount); // load settings Logger.LogDebug(typeof(Program), "Loading Droid Explorer Settings"); Program.SplashManager.SplashDialog.SetStepText("Loading Settings..."); CommandRunner.Settings = Settings.Instance; Settings.Instance.SystemSettings = RegistrySettings.Instance; Program.SplashManager.SplashDialog.IncrementLoadStep(1); // cleanup adb? should this be done? Application.ApplicationExit += delegate(object sender, EventArgs e) { //CommandRunner.Instance.AdbProcessCleanUp ( ); }; // locate sdk tools Logger.LogDebug(typeof(Program), "Locating SDK Path"); Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashLocatingSdk); var sdkPath = Settings.Instance.SystemSettings.SdkPath; Logger.LogDebug(typeof(Program), "SDK Path Set to {0}", sdkPath); if (string.IsNullOrEmpty(sdkPath)) { throw new ApplicationException("Unable to locate the android SDK tools, please reinstall the application."); } Program.SplashManager.SplashDialog.IncrementLoadStep(1); // verify the sdk tools Logger.LogDebug(typeof(Program), "Verifying SDK Tools"); Program.SplashManager.SplashDialog.SetStepText("Verifying SDK Tools"); // verify the sdk tools. var valid = FolderManagement.VerifyAndroidSdkTools(); if (!valid) { // if not valid - lets ask the user where it is. Program.SplashManager.SplashDialog.HideExt(); Logger.LogWarn(typeof(Program), "Unable to verify the SDK tools"); var browser = new FolderBrowserDialog(); browser.Description = "Unable to locate SDK tools path. Please select the location where you have the Android SDK installed."; browser.ShowNewFolderButton = false; var dResult = DialogResult.OK; do { dResult = browser.ShowDialog(); if (dResult == DialogResult.OK) { Settings.Instance.SystemSettings.SdkPath = browser.SelectedPath; valid = FolderManagement.VerifyAndroidSdkTools(); } // keep asking until the user selects a valid location, or they cancel. } while(!valid && dResult == DialogResult.OK); if (!valid) { // they canceled. we are out of here. throw new ApplicationException(DroidExplorer.Resources.Strings.SdkPathNotFoundMessage); } // bring it back. Program.SplashManager.SplashDialog.AsyncShow(); } Program.SplashManager.SplashDialog.IncrementLoadStep(1); // set the sdk path CommandRunner.Instance.SdkPath = sdkPath; Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashStartAdb); try { // start the adb server Logger.LogDebug(typeof(Program), "Starting ADB Server"); CommandRunner.Instance.StartServer(); Program.SplashManager.SplashDialog.IncrementLoadStep(1); } catch (AdbRootException arex) { Logger.LogWarn(typeof(Program), arex.Message); } // get the attached devices Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashGetDevices); // BUG: 15695 // fixed this. It was because adb root was disconnecting the device and restarting it. // adb root is now called when you connect to a device. Although, it can cause the device to // not be found... another bug... Logger.LogDebug(typeof(Program), "Getting connected devices"); var devices = CommandRunner.Instance.GetDevices().ToList(); Program.SplashManager.SplashDialog.IncrementLoadStep(1); new Thread(() => { // process the devices and send them off to the cloud Logger.LogDebug(typeof(Program), "Registering anonymous statistics for device types"); CloudStatistics.Instance.RegisterModels(devices); }).Start(); // we will increment even though the process is on a new thread. Program.SplashManager.SplashDialog.IncrementLoadStep(1); // pass in the initial path? // TODO: Not yet implemented. //var initialPath = "/"; //if ( args.Contains ( "p", "path" ) && !string.IsNullOrWhiteSpace ( args["p", "path"] ) ) { // initialPath = args["p", "path"]; //} // are we attaching to a specific device? if (args.Contains("d", "device")) { CommandRunner.Instance.DefaultDevice = args["d", "device"]; Logger.LogDebug(typeof(Program), DroidExplorer.Resources.Strings.SplashConnectingDevice, CommandRunner.Instance.DefaultDevice); Application.Run(new MainForm( )); } else { // get the attached devices String selectedDevice = null; if (devices.Count() != 1) { // we have 0 or > 1 so we need to display the "selection dialog" var dsf = new GenericDeviceSelectionForm(); Program.SplashManager.SplashDialog.HideExt(); if (dsf.ShowDialog(null) == DialogResult.OK) { CommandRunner.Instance.DefaultDevice = dsf.SelectedDevice; Logger.LogDebug(typeof(Program), DroidExplorer.Resources.Strings.SplashConnectingDevice, CommandRunner.Instance.DefaultDevice); selectedDevice = dsf.SelectedDevice; } else { Program.SplashManager.CloseSplashDialog(); return; } Program.SplashManager.SplashDialog.AsyncShow(); } else { selectedDevice = devices[0].SerialNumber; CommandRunner.Instance.DefaultDevice = selectedDevice; } // try to run adb as root: try { Program.SplashManager.SplashDialog.SetStepText(DroidExplorer.Resources.Strings.SplashRunAdbAsRoot); Logger.LogDebug(typeof(Program), DroidExplorer.Resources.Strings.SplashRunAdbAsRoot); CommandRunner.Instance.StartAdbAsRoot(selectedDevice); // sleep a half second to let it start up. Thread.Sleep(500); } catch (AdbRootException are) { Logger.LogDebug(typeof(Program), "Unable to launch ADB as root"); // if we are unable to run as adb root if (Settings.Instance.WarnWhenNoAdbRoot) { SplashManager.SplashDialog.Invoke((Action)(() => { SplashManager.SplashDialog.Visible = false; })); //NoAdbRootCommands Continue|Show more information|Exit var result = TaskDialog.ShowCommandBox( DroidExplorer.Resources.Strings.NoAdbRootTitle, are.Message, DroidExplorer.Resources.Strings.NoAdbRootMessage, string.Empty, string.Empty, DroidExplorer.Resources.Strings.NoAdbRootCheckboxText, DroidExplorer.Resources.Strings.NoAdbRootCommands, false, SysIcons.Warning, SysIcons.Warning); switch (TaskDialog.CommandButtonResult) { case 0: // Continue // continue if (TaskDialog.VerificationChecked) { // do not warn again. Settings.Instance.WarnWhenNoAdbRoot = false; } break; case 1: // continue and get more info : http://android.stackexchange.com/a/96066/1951 // android enthusiasts CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.AdbRootQAUrl, string.Empty, true); if (TaskDialog.VerificationChecked) { // do not warn again. Settings.Instance.WarnWhenNoAdbRoot = false; } break; case 2: // link to adbd insecure by chainfire on google play CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.AdbdInsecureAppUrl, string.Empty, true); Application.Exit(); return; default: // 3 Application.Exit(); return; } SplashManager.SplashDialog.Invoke((Action)(() => { SplashManager.SplashDialog.Visible = true; })); } } // increment for adb root Program.SplashManager.SplashDialog.IncrementLoadStep(1); // minor hackory for getting the device for cloud stats var d = new Core.Adb.Device(selectedDevice, Core.Adb.DeviceState.Online); // get the device properties for registration foreach (var i in CommandRunner.Instance.GetProperties(selectedDevice)) { d.Properties.Add(i.Key, i.Value); } if (!Settings.Instance.SystemSettings.RecordDeviceInformationToCloud) { Program.SplashManager.SplashDialog.SetStepText( String.Format(DroidExplorer.Resources.Strings.SplashRegisterDevice, KnownDeviceManager.Instance.GetDeviceFriendlyName(selectedDevice) ) ); // register the device CloudStatistics.Instance.RegisterDevice(d, devices.Single(x => x.SerialNumber == d.SerialNumber)); Program.SplashManager.SplashDialog.IncrementLoadStep(1); } else { // we have to increment but nothing else here Program.SplashManager.SplashDialog.IncrementLoadStep(1); } Logger.LogDebug(typeof(Program), "Launching Main UI"); // connect to device Program.SplashManager.SplashDialog.SetStepText(string.Format(DroidExplorer.Resources.Strings.SplashConnectingDevice, KnownDeviceManager.Instance.GetDeviceFriendlyName(CommandRunner.Instance.DefaultDevice))); Application.Run(new MainForm( )); } } catch (Exception ex) { var result = TaskDialog.ShowCommandBox(DroidExplorer.Resources.Strings.ErrorUncaughtTitle, ex.Message, DroidExplorer.Resources.Strings.ErrorUncaughtMessage, ex.ToString(), string.Empty, string.Empty, DroidExplorer.Resources.Strings.ErrorUncaughtCommands, false, SysIcons.Error, SysIcons.Error); switch (TaskDialog.CommandButtonResult) { case 1: // continue break; case 2: // android enthusiasts CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.SupportUrl, string.Empty, true); break; case 3: // report bug CommandRunner.Instance.LaunchProcessWindow(DroidExplorer.Resources.Strings.IssueTrackerCreateUrl, string.Empty, true); break; default: // 0 Application.Restart(); break; } } }