Пример #1
0
        public frmMain(string[] args)
        {
            //sets to SegoeUI on Vista
            Font = SystemFonts.MessageBoxFont;

            // check if user is an admin for windows 2000+
            IsAdmin = VistaTools.IsUserAnAdmin();

            InitializeComponent();

            //enable Lazy SSL for all downloads
            FileDownloader.SetupSaneDownloadOptions();

            //resize the client so its client region = 500x360
            if (ClientRectangle.Width != 500)
            {
                Width = (Width - ClientRectangle.Width) + 500;
            }

            if (ClientRectangle.Height != 360)
            {
                Height = (Height - ClientRectangle.Height) + 360;
            }

            //add the panelDisplaying to form
            panelDisplaying.TabIndex = 0;
            Controls.Add(panelDisplaying);

            try
            {
                //process commandline argument
                Arguments commands = new Arguments(args);
                ProcessArguments(commands);

                // load the self update information
                if (!string.IsNullOrEmpty(selfUpdateFileLoc))
                {
                    //Note: always load the selfupdate data before the automatic update data
                    LoadSelfUpdateData(selfUpdateFileLoc);
                    ConfigureProxySettings();

                    //TODO: wyUp 3.0: excise this hack
                    //if the loaded file is from RC1, then update self and bail out
                    if (selfUpdateFromRC1)
                    {
                        //install the new client, and relaunch it to continue the update
                        if (needElevation && NeedElevationToUpdate())
                        {
                            //the user "elevated" as a non-admin user
                            //warn the user of their idiocy
                            error = clientLang.AdminError;

                            //set to false so new client won't be launched in frmMain_Load()
                            selfUpdateFromRC1 = false;

                            ShowFrame(Frame.Error);
                        }
                        else
                        {
                            needElevation = false;

                            FileAttributes atr             = File.GetAttributes(oldSelfLocation);
                            bool           resetAttributes = (atr & FileAttributes.Hidden) != 0 || (atr & FileAttributes.ReadOnly) != 0 || (atr & FileAttributes.System) != 0;

                            // remove the ReadOnly & Hidden atributes temporarily
                            if (resetAttributes)
                            {
                                File.SetAttributes(oldSelfLocation, FileAttributes.Normal);
                            }

                            //Install the new client
                            File.Copy(newSelfLocation, oldSelfLocation, true);

                            if (resetAttributes)
                            {
                                File.SetAttributes(oldSelfLocation, atr);
                            }

                            //Relaunch self in OnLoad()
                        }

                        //bail out
                        return;
                    }
                }
                else // not self-updating
                {
                    ConfigureProxySettings();
                }

                //Load the client information
                if (clientFileType == ClientFileType.PreRC2)
                {
                    //TODO: wyUp 3.0: stop supporting old client files (barely anyone uses RC2).
                    update.OpenObsoleteClientFile(clientFileLoc);
                }
                else
                {
                    update.OpenClientFile(clientFileLoc, clientLang, forcedLanguageCulture, updatePathVar, customUrlArgs);
                }

                clientLang.SetVariables(update.ProductName, update.InstalledVersion);
            }
            catch (Exception ex)
            {
                clientLang.SetVariables(update.ProductName, update.InstalledVersion);

                error        = "Client file failed to load. The client.wyc file might be corrupt.";
                errorDetails = ex.Message;

                ShowFrame(Frame.Error);
                return;
            }

            //sets up Next & Cancel buttons
            SetButtonText();

            //set header alignment, etc.
            panelDisplaying.HeaderImageAlign = update.HeaderImageAlign;

            if (update.HeaderTextIndent >= 0)
            {
                panelDisplaying.HeaderIndent = update.HeaderTextIndent;
            }

            panelDisplaying.HideHeaderDivider = update.HideHeaderDivider;

            // set the
            if (update.CustomWyUpdateTitle != null)
            {
                Text = update.CustomWyUpdateTitle;
            }

            try
            {
                if (!string.IsNullOrEmpty(update.HeaderTextColorName))
                {
                    panelDisplaying.HeaderTextColor = Color.FromName(update.HeaderTextColorName);
                }
            }
            catch { }

            //load the Side/Top images
            panelDisplaying.TopImage  = update.TopImage;
            panelDisplaying.SideImage = update.SideImage;

            if (isAutoUpdateMode)
            {
                try
                {
                    // create the temp folder where we'll store the updates long term
                    if (tempDirectory == null)
                    {
                        tempDirectory = CreateAutoUpdateTempFolder();
                    }
                }
                catch (Exception ex)
                {
                    error        = clientLang.GeneralUpdateError;
                    errorDetails = "Failed to create the automatic updater temp folder: " + ex.Message;

                    ShowFrame(Frame.Error);
                    return;
                }

                try
                {
                    // load the previous auto update state from "autoupdate"
                    LoadAutoUpdateData();
                    ConfigureProxySettings();
                }
                catch
                {
                    startStep = UpdateStepOn.Checking;
                }
            }
            else if (SelfUpdateState == SelfUpdateState.FullUpdate)
            {
                try
                {
                    // load the server file for MinClient needed details (i.e. failure case)
                    ServerFile = ServerFile.Load(serverFileLoc, updatePathVar, customUrlArgs);

                    //load the self-update server file
                    LoadClientServerFile();
                    clientLang.NewVersion = SelfServerFile.NewVersion;
                }
                catch (Exception ex)
                {
                    error        = clientLang.ServerError;
                    errorDetails = ex.Message;

                    ShowFrame(Frame.Error);
                    return;
                }

                if (needElevation && NeedElevationToUpdate())
                {
                    //the user "elevated" as a non-admin user
                    //warn the user of their idiocy
                    error = clientLang.AdminError;
                    ShowFrame(Frame.Error);
                }
                else
                {
                    needElevation = false;

                    //begin updating the product
                    ShowFrame(Frame.InstallUpdates);
                }
            }
            //continuing from elevation or self update (or both)
            else if (SelfUpdateState == SelfUpdateState.ContinuingRegularUpdate)
            {
                try
                {
                    //load the server file (without filling the 'changes' box & without downloading the wyUpdate Server file)
                    LoadServerFile(false);
                }
                catch (Exception ex)
                {
                    error        = clientLang.ServerError;
                    errorDetails = ex.Message;

                    ShowFrame(Frame.Error);
                    return;
                }

                if (needElevation && NeedElevationToUpdate())
                {
                    // the user "elevated" as a non-admin user
                    // warn the user of their idiocy
                    error = clientLang.AdminError;

                    ShowFrame(Frame.Error);
                }
                else
                {
                    needElevation = false;

                    //begin updating the product
                    ShowFrame(Frame.InstallUpdates);
                }
            }
            else if (!uninstalling)
            {
                startStep = UpdateStepOn.Checking;
            }
        }