Пример #1
0
        /// <summary>
        /// Launch Setup in Silent Mode
        /// </summary>
        /// <returns>a SetupReturnValues reflecting success or possible failure causes</returns>
        private static SetupReturnValues SilentRun()
        {
            // Setup the data for the items to install
            PrepareInstallData.PrepareInstallDataItems();

            // Check to see that we have all the install files we need.
            // Make sure the file locations are set for the install files.
            SetupFileValidation.ResetInstallItemFileLocations(
                PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagConstants.LocationOfSetupFiles),
                PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagConstants.LocationOfSetupFiles));

            if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
            {
                if (!SetupFileValidation.HaveAllNeededInstallItemFiles())
                {
                    return(SetupReturnValues.InvalidInstallImage);
                }

                SetupHelpers.SetFeatureSwitches();
                // If we are not uninstalling, Do the prereq check
                if (2 == SetupHelpers.DoAllPrerequisiteChecks())
                {
                    // We failed prereq tests so we will fail the install
                    SetupLogger.LogError("We failed the prerequisite checks.");
                    return(SetupReturnValues.FailedPrerequisiteChecks);
                }

                // If this is a server installation,
                // - check if there is an existing database,
                // and if so, check if upgrade is supported from that version
                // - make sure client is also installed with server.
                if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Server))
                {
                    // Error conditions
                    // An unsupported database found
                    // A supported database is found, but user didnt explicitly specify upgrade

                    // CheckDatabase will throw an exception if DB version is
                    // incompatible
                    string sqlMachineName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlMachineNameTag);

                    String fullInstanceName = SetupDatabaseHelper.ConstructFullInstanceName(
                        !SetupDatabaseHelper.SqlServerIsOnLocalComputer(sqlMachineName),
                        sqlMachineName,
                        (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlInstanceNameTag),
                        (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));
                }
            }

            // Do the install using the passed information
            InstallActionProcessor installs = new InstallActionProcessor();

            SetupLogger.LogInfo("Silent ProcessInstalls Starting");

            SetupReturnValues rturn = installs.ProcessInstalls();

            SetupLogger.LogInfo("Silent ProcessInstalls Done");

            return(rturn);
        }
Пример #2
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);
        }