Пример #1
0
        /// <summary>
        /// Loads the About Box. A browser window is filled with fixed HTML content describing version, copyrights etc.
        /// </summary>
        /// <param name="sender">Event Sender, unused.</param>
        /// <param name="e">Event Arguments, unused.</param>
        /// <remarks>Documented by Dev01, 2007-07-18</remarks>
        private void AboutBox_Load(object sender, System.EventArgs e)
        {
            Version.Text = String.Format(Resources.ABOUT_VERSION, Application.ProductVersion);
            if (Setup.RunningFromStick())
            {
                Version.Text += " " + Resources.RUNNING_FROM_STICK;
            }
            lblCopyright.Text = Resources.ABOUT_COPYRIGHT;

            string sBackGroundColor = ColorTranslator.ToHtml(Color.FromKnownColor(KnownColor.Control));
            string sForeGroundColor = ColorTranslator.ToHtml(Color.FromKnownColor(KnownColor.ControlText));

            webBrowserCredits.DocumentText = String.Format(Resources.DisclaimerText, sForeGroundColor, sBackGroundColor, Resources.ABOUT_HTML_DISCLAIMER_CAPTION, Resources.ABOUT_HTML_DISCLAIMER_TEXT);;
            webBrowserCredits.Visible      = true;
        }
Пример #2
0
        static void Main(string[] args)
        {
            TaskDialog.ForceEmulationMode = true;
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();

            //register errorhandler as default unhandled exception handler
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            List <string> arguments = new List <string>(args);

            //check settings file before any other setting access occurs
            CheckSettings();

            #region Check for updates
            if (arguments.Contains("--no-autoupdate"))
            {
                arguments.Remove("--no-autoupdate");
                UpdateChecked = true;
            }
            else if (!Properties.Settings.Default.CheckForUpdates)
            {
                UpdateChecked = true;
            }
            else
            {
                try
                {
                    Thread updateChecker = new Thread(new ThreadStart(CheckForUpdate));
                    updateChecker.CurrentCulture   = Thread.CurrentThread.CurrentCulture;
                    updateChecker.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
                    updateChecker.IsBackground     = true;
                    updateChecker.Name             = "Check for Updates";
                    updateChecker.Priority         = ThreadPriority.BelowNormal;
                    updateChecker.Start();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                }
            }
            #endregion

            Mutex splashMutex = new Mutex(false, "Local\\MLifterSplashMutex");

            #region Running from stick
            //execute the program in a new appdomain with shadow copying enabled
            if (Setup.RunningFromStick() && !AppDomain.CurrentDomain.ShadowCopyFiles)
            {
                SplashManager splashManager = new SplashManager(typeof(Splash));
                splashManager.InitialMessage = Resources.SPLASHSCREEN_PREPARING;
                splashManager.ShowSplash();

                AppDomainSetup setup = new AppDomainSetup();
                setup.ShadowCopyFiles       = "true";
                setup.ShadowCopyDirectories = null;                 //all files

                Evidence evidence = System.Reflection.Assembly.GetEntryAssembly().Evidence;

                AppDomain appdomain = AppDomain.CreateDomain("MLifter", evidence, setup);
                appdomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                AssemblyName entryassembly = System.Reflection.Assembly.GetEntryAssembly().GetName();

                appdomain.Load(entryassembly);

                //test the mutex every 100 ms and hide the splash screen if it cannot be taken anymore
                Thread mutexWatcherThread = new Thread(new ThreadStart(delegate
                {
                    TimeSpan wait = new TimeSpan(0, 0, 0, 0, 20);
                    try
                    {
                        while (true)
                        {
                            Thread.Sleep(100);
                            if (splashMutex.WaitOne(wait, false))
                            {
                                splashMutex.ReleaseMutex();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    catch (AbandonedMutexException)
                    { }
                    finally
                    {
                        splashManager.HideSplash();
                    }
                }));
                mutexWatcherThread.Name         = "Splash Mutex Watcher Thread";
                mutexWatcherThread.IsBackground = true;
                mutexWatcherThread.Start();

                appdomain.ExecuteAssemblyByName(entryassembly, args);                 //evidence removed as second parameter to avoid compiler warning
                //let main function end
            }
            #endregion
            else
            {
                SplashManager splashManager = new SplashManager(typeof(Splash));
                splashManager.EnableFadingMainForm = true;

                #region Only one program instance
                //register IPC channel so that only one instance can be active
                GetIPCData(out UniqueChannelName, out UniqueChannelPortName, out ClientURL, out ServiceURL);

                //check if this is the first instance
                bool firstInstance = true;
                if (Settings.Default.AllowOnlyOneInstance)
                {
                    try
                    {
                        instanceMutex = new Mutex(false, "Local\\MLifterMutex", out firstInstance);
                    }
                    catch (Exception exp)
                    {
                        System.Diagnostics.Trace.WriteLine("Failed to create Mutex: " + exp.ToString());
                    }
                }

#if !DEBUG
                //show the splashscreen
                if (firstInstance || !Settings.Default.AllowOnlyOneInstance)
                {
                    splashManager.ShowSplash();
                }
#endif

                //begin preparing styles
                MLifter.Components.StyleHandler.BeginStylePreparation(System.IO.Path.Combine(Application.StartupPath, Properties.Settings.Default.AppDataFolderDesigns));

                try
                {
                    StartIPC();
                    SuspendIPC = true;                     //suspend IPC until ML is fully loaded
                }
                catch (Exception exp)
                {
                    System.Diagnostics.Trace.WriteLine("Failed to start IPC server: " + exp.ToString());
                }

                if (!firstInstance && Settings.Default.AllowOnlyOneInstance)
                {
                    try
                    {
                        if (arguments.Count > 0)
                        {
                            SendPathToIPC(arguments[0]);
                        }
                        else
                        {
                            BringMLifterToFront();
                        }
                        Environment.Exit(-1);
                    }
                    catch (Exception exp)
                    {
                        System.Diagnostics.Trace.WriteLine("Failed to SendPathToIPC/BringMLifterToFront with another instance active: "
                                                           + exp.ToString());
                    }
                }
                #endregion

                // Run Application
                Program.MainForm = new MainForm(arguments.ToArray());
#if !DEBUG
                splashManager.HideMainForm(Program.MainForm);                 //register MainForm to be automatically hidden and showed
#endif

                #region Running from stick (Mutex check)
                //take the mutex signal for 500 ms to trigger the hiding of the previous splash screen
                Thread mutexReleaseThread = new Thread(new ThreadStart(delegate
                {
                    TimeSpan wait = new TimeSpan(0, 0, 0, 0, 100);
                    try
                    {
                        if (splashMutex.WaitOne(wait, false))
                        {
                            Thread.Sleep(500);
                            splashMutex.ReleaseMutex();
                        }
                    }
                    catch (AbandonedMutexException)
                    { }
                }));
                mutexReleaseThread.Name         = "Splash Mutex Release Thread";
                mutexReleaseThread.IsBackground = true;
                mutexReleaseThread.Start();
                #endregion

                Application.Run(Program.MainForm);
            }
        }
Пример #3
0
        /// <summary>
        /// Checks for update.
        /// </summary>
        /// <remarks>Documented by Dev05, 2009-07-15</remarks>
        public static void CheckForUpdate()
        {
            try
            {
                WebClient client        = new WebClient();
                string    updateVersion = client.DownloadString(String.Format("{0}?base={1}&beta={2}&onstick={3}",
                                                                              Settings.Default.UpdateVersionUrl, MLifter.DAL.Tools.AssemblyData.Version.ToString(2),
                                                                              Settings.Default.CheckForBetaUpdates.ToString(), Setup.RunningFromStick()));
                if (updateVersion.Length == 0)
                {
                    Trace.WriteLine("CheckForUpdate got an empty version string.");
                    return;
                }
                Version newVersion = new Version(updateVersion);

                if (newVersion > MLifter.DAL.Tools.AssemblyData.Version)
                {
                    string updaterPath = Path.Combine(Application.StartupPath, "MLifterUpdateHandler.exe");
                    Process.Start(updaterPath, "-v " + updateVersion);
                    Environment.Exit(-1);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
            finally
            {
                UpdateChecked = true;
            }
        }