/// <summary> /// Occurs when the Explore Current Users Path menu item is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnExploreCurrentUsersPathClicked(object sender, EventArgs e) { if (Directory.Exists(SnapInHostingEngine.LocalUserDataPath)) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.Verb = "EXPLORE"; p.StartInfo.FileName = SnapInHostingEngine.LocalUserDataPath; p.Start(); } else { ExceptionEngine.DisplayException(this, "Directory does not exist", MessageBoxIcon.Information, MessageBoxButtons.OK, null, "The path '" + SnapInHostingEngine.LocalUserDataPath + "' could not be found."); } }
public void Run(string[] args, System.Reflection.Assembly executable) { bool tracedExceptionThrown = false; try { using (SplashWindowThread splashThread = new SplashWindowThread(executable, false)) { splashThread.ShowAsynchronously(); splashThread.Window.SetMarqueeMoving(true, true); ProgressViewer.SetExtendedDescription(splashThread.Window, "Bootstrap: Parsing command line..."); // create a new command line parsing engine CommandLineParsingEngine pe = new CommandLineParsingEngine(args); // determine if we are going to keep the old versions bool keepOld = pe.ToBoolean("keepold"); // the process id of an app int pid = pe.ToInt32("pid"); // whether we should wait on the specified pid to die before launching new version bool wait = pe.ToBoolean("wait"); ProgressViewer.SetExtendedDescription(splashThread.Window, "Bootstrap: Searching for runnable version..."); // create a search for all of the subdirectories Search search = new Search("Versions", Application.StartupPath, "*", false, false); // find all of the directories DirectoryInfo[] directories = search.GetDirectories(); // create versioned files around each directory that can be parsed to a version VersionedDirectory[] versionedDirectories = this.CreateVersionedFiles(directories); // if we have been instructed to wait on the process specified by pid to die, do it now if (wait && pid != 0) { try { // snag it and wait on it to exit Process p = Process.GetProcessById(pid); if (p != null) { ProgressViewer.SetExtendedDescription(splashThread.Window, "Bootstrap: Closing previous instance..."); p.WaitForExit(); } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } } ProgressViewer.SetExtendedDescription(splashThread.Window, "Bootstrap: Selecting latest runnable version..."); // try and start the newest version VersionedDirectory versionStarted; bool startedVersion = this.StartNewestVersion(executable, versionedDirectories, out versionStarted, splashThread.Window); // this will fall back upon older versions until it runs out of versions or one of the versions starts if (!startedVersion) { string exeName = string.Format("{0}.exe", executable.GetName().Name); ExceptionEngine.DisplayException(null, "BootStrap failed for " + exeName, MessageBoxIcon.Stop, MessageBoxButtons.OK, null, "No suitable executable was found or able to be started."); } // if we're not keeping the old versions if (!keepOld) { // delete the older versions if (!this.DeleteOlderVersions(versionedDirectories, versionStarted, splashThread.Window)) { // um, who cares if we can't delete the older versions // also we need to see about security rights to the directories } } // if we started a version if (startedVersion) { // notify that we are transferring control now to it... ProgressViewer.SetExtendedDescription(splashThread.Window, "Bootstrap: Transferring control to version " + versionStarted.Version.ToString() + "..."); } } } catch (System.Exception systemException) { tracedExceptionThrown = true; System.Diagnostics.Trace.WriteLine(systemException); System.Windows.Forms.MessageBox.Show(null, systemException.ToString(), "Application Exiting"); Application.ExitThread(); } finally { System.Diagnostics.Trace.WriteLine("'" + Application.ProductName + (tracedExceptionThrown ? "' has terminated because of an exception." : "' has exited gracefully.")); } }