Пример #1
0
        public static int Main()
        {
            SetupReturnValues returnValue = SetupReturnValues.Failed;

            // This is needed to load the WPF stuff so
            // that we can get at the resources.
            Application apptry = Application.Current;

            Application.Equals(apptry, null);

            SetDefaultPropertyValues();

            SetupLogger.Initialize(PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagConstants.DefaultLogName));
            SetupLogger.LogInfo("Application Started");
            bool  createdNew;
            Mutex mSetupwizard = new Mutex(true, @"Global\Phoenix Setup", out createdNew);

            if (!createdNew)
            {
                SetupLogger.LogInfo("There is already another setup wizard running on this computer.");
                SetupLogger.LogInfo("Please wait until that program is finished.");
                returnValue = SetupReturnValues.AnotherSetupRunningOnThisMachine;
                MessageBox.Show(WPFResourceDictionary.AnotherSetupRunningOnThisMachineMessage, WPFResourceDictionary.SetupMessageBoxTitle, MessageBoxButton.OK);
                goto AllDone;
            }

            try
            {
                // Set CurrentDirectory
                Environment.CurrentDirectory = PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagDictionary.SetupExePath);

                try
                {
                    SetupLogger.Initialize(SetupHelpers.SetLogFilePath("SetupWizardAdditional.log"), LogLevel.Verbose, true);
                }
                catch (Exception exception)
                {
                    // Since the exception is thrown before the logger is initialized,
                    // just display the message in a message box
                    MessageBox.Show(exception.Message, WPFResourceDictionary.SetupMessageBoxTitle, MessageBoxButton.OK);
                    goto AllDone;
                }

                if (!ParseCommandLine())
                {
                    // Could not parse the command line
                    returnValue = SetupReturnValues.InvalidCommandLine;
                    goto AllDone;
                }

                // Get the state of the components on; this machine
                SystemStateDetection.CheckInstalledComponents();

                // If not silent, show splash screen here
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.Silent))
                {
                    Program.splashPage = new SplashPage();
                    Program.splashPage.Show();
                }
                else
                {
                    // Silent setup
                    // Check command line against the existing components
                    if (!CheckCommandLine())
                    {
                        returnValue = SetupReturnValues.InvalidCommandLine;
                        goto AllDone;
                    }
                }

                // If we don't have a location for the setup files, assume current location.
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.LocationOfSetupFiles))
                {
                    PropertyBagDictionary.Instance.SafeAdd(
                        PropertyBagConstants.LocationOfSetupFiles,
                        PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagDictionary.SetupExePath));
                }

                // Check to see if the path is valid for our install
                if (!SetupValidationHelpers.IsValidPathForInstall(SetupInputs.Instance.FindItem(SetupInputTags.BinaryInstallLocationTag)))
                {
                    SetupLogger.LogInfo("Invalid path passed to the setup. {0}", SetupInputs.Instance.FindItem(SetupInputTags.BinaryInstallLocationTag));
                    returnValue = SetupReturnValues.InvalidCommandLine;
                    if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.Silent))
                    {
                        goto AllDone;
                    }
                }

                // What we have selected is valid given the machine state, etc...
                if (!SetupHelpers.RationalizeComponents())
                {
                    SetupLogger.LogInfo("We could not rationalize the component choices.  We must fail.");
                    returnValue = SetupReturnValues.InvalidCommandLine;

                    goto AllDone;
                }

                // Need to load the install data items
                XmlSerializer dataItemSerializer = new XmlSerializer(typeof(InstallItems));
                using (MemoryStream stream = new MemoryStream())
                {
                    StreamWriter writer = new StreamWriter(stream);
                    writer.Write(Properties.Resources.InstallItems);
                    writer.Flush();
                    stream.Position = 0;
                    InstallItems inputInstallItems = (InstallItems)dataItemSerializer.Deserialize(stream);
                    SetupLogger.LogInfo("Start adding DataItems");
                    foreach (InstallItemsInstallDataItem installDataItem in inputInstallItems.InstallDataItem)
                    {
                        SetupLogger.LogInfo(installDataItem.DisplayTitle);

                        // localize the display title
                        installDataItem.DisplayTitle = InstallItemDisplayTitleEnumHelper.GetName((InstallItem)Enum.Parse(typeof(InstallItem), installDataItem.DisplayTitle));
                        // Add this Item to our data items
                        InstallDataItemRegistry.Instance.RegisterDataItem(installDataItem);
                    }
                    SetupLogger.LogInfo("Done adding DataItems");
                }

                if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.Silent))
                {
                    returnValue = Program.SilentRun();
                }
                else
                {
                    Program.UiRun();
                    // Set the application return value: Always success in UI mode
                    returnValue = SetupReturnValues.Successful;
                }
            }
            catch (Exception exception)
            {
                SetupLogger.LogInfo("Uncaught Exception", exception);
            }
            finally
            {
            }


            // All done with the install.
AllDone:
            // Reboot if we have to
            RebootIfNeeded();

            //release the setup wizard mutex
            mSetupwizard.ReleaseMutex();

            return((int)returnValue);
        }