Пример #1
0
        static void MainImpl(string[] args)
        {
            if (!PdnInfo.HandleExpiration(null))
            {
                return;
            }

            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
            UI.EnableDpiAware();

            // Uncomment to test German
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de");

            bool doInstall        = true;
            bool doMsiDump        = false;
            bool restartPdnOnExit = false;

            string[] propertyDefaults = PropertyNames.Defaults;

            SetupWizard setupWizard = new SetupWizard();

            // Parse through command-line options
            for (int i = 0; i < args.Length; ++i)
            {
                string arg      = args[i];
                string argLower = arg.ToLower();

                switch (argLower)
                {
                case "-?":
                case "/?":
                case "-help":
                case "/help":
                    ShowHelp();
                    doInstall = false;
                    break;

                case "-restartpdnonexit":
                case "/restartpdnonexit":
                    restartPdnOnExit = true;
                    break;

                case "-skipconfig":
                case "/skipconfig":
                    KillParentPdnExe();
                    setupWizard.SkipConfig = true;
                    setupWizard.SetMsiProperty(PropertyNames.PdnUpdating, "1");
                    break;

                case "-auto":
                case "/auto":
                    setupWizard.AutoMode   = true;
                    setupWizard.SkipConfig = true;
                    break;

                case "-createmsi":
                case "/createmsi":
                    doMsiDump        = true;
                    propertyDefaults = PropertyNames.AdGpoDefaults;
                    break;

                default:
                    setupWizard.AddPropertyFromArg(arg);
                    break;
                }
            }

            // Load all the propreties that we always need to have. Defaults will be loaded
            // for properties that are not already set.
            for (int i = 0; i < propertyDefaults.Length; i += 2)
            {
                setupWizard.GetMsiProperty(propertyDefaults[i], propertyDefaults[i + 1]);
            }

            setupWizard.SetMsiProperty(PropertyNames.PdnUpdating, "0");

            // Only allow 1 instance of setup wizard running at a time...
            bool  createdNew;
            Mutex mutex = new Mutex(false, mutexName, out createdNew);

            doInstall &= createdNew;

            if (doInstall)
            {
                if (CheckRequirements())
                {
                    if (doMsiDump)
                    {
                        setupWizard.ClearPageStack();
                        setupWizard.GoToPage(typeof(CreateMsiPage));
                    }

                    setupWizard.ShowDialog();
                }

                // When we do an update, Mono Paint launches our installer with the /restartPdnOnExit
                // flag. This tells us to run Mono Paint when the update is finished. This accomplishes
                // two things:
                //
                // 1. Adds a slight amount of continuity for the user. When they're installing an update
                //    they'll probably want to start-up Mono Paint right away. So we do it for them.
                // 2. Cleans up (deletes) the downloaded setup file. Otherwise, the user has to make sure
                //    that they immediately re-run Mono Paint under the same user account in order to
                //    clean this up.
                //
                // #2 does introduce a slight race condition, so PaintDotNet.exe will actually retry
                // up to 3 times to delete the file with a 1 second pause between retries. This should
                // give enough time for the setup processes to unwind without causing too horrible of
                // a delay in the worst case.
                if (restartPdnOnExit && !setupWizard.RebootRequired)
                {
                    string targetDir = setupWizard.GetMsiProperty(PropertyNames.TargetDir, null);

                    if (targetDir != null)
                    {
                        string pdnPathName = Path.Combine(targetDir, "PaintDotNet.exe");

                        if (File.Exists(pdnPathName))
                        {
                            Process.Start(pdnPathName);
                        }
                    }
                }

                setupWizard.Dispose();
            }

            mutex.Close();
        }