void LoadClientServerFile() { // load the self server file if it doesn't already exist if (SelfServerFile == null) { SelfServerFile = ServerFile.Load(clientSFLoc, updatePathVar, customUrlArgs); } updateFrom = SelfServerFile.GetVersionChoice(VersionTools.FromExecutingAssembly()); }
/// <summary> /// Called when the self-update server files has downloaded successfully. /// </summary> void DownloadClientSFSuccess() { // load the wyUpdate server file, and see if a new version is availiable ServerFile clientSF = ServerFile.Load(clientSFLoc, updatePathVar, customUrlArgs); // check if the wyUpdate is new enough. if (VersionTools.Compare(VersionTools.FromExecutingAssembly(), clientSF.NewVersion) < 0) { SelfUpdateState = SelfUpdateState.WillUpdate; // autoupdate will need this SF if (isAutoUpdateMode) { SelfServerFile = clientSF; LoadClientServerFile(); } } // Show update info page (or just start downloading & installing) if (SkipUpdateInfo) { // check if elevation is needed needElevation = NeedElevationToUpdate(); if (needElevation || SelfUpdateState == SelfUpdateState.WillUpdate) { StartSelfElevated(); } else { ShowFrame(Frame.InstallUpdates); } } else { ShowFrame(Frame.UpdateInfo); } }
//returns True if an update is necessary, otherwise false void LoadServerFile(bool setChangesText) { //load the server file ServerFile = ServerFile.Load(serverFileLoc); updateFilename = serverFileLoc; clientLang.NewVersion = ServerFile.NewVersion; // if no update is needed... if (VersionTools.Compare(update.InstalledVersion, ServerFile.NewVersion) >= 0) { if (isAutoUpdateMode) { // send reponse that there's no update available updateHelper.SendSuccess(null, null, true); // close this client isCancelled = true; // let wyUpdate cleanup the files isAutoUpdateMode = false; // let ServerDownloadedSuccessfully() exit early frameOn = Frame.AlreadyUpToDate; Close(); return; } // Show "All Finished" page ShowFrame(Frame.AlreadyUpToDate); return; } // get the correct update file to download updateFrom = ServerFile.GetVersionChoice(update.InstalledVersion); // if the update install the x64 system32 folder on an x86 machine we need to throw an error if ((updateFrom.InstallingTo & InstallingTo.SysDirx64) == InstallingTo.SysDirx64 && !SystemFolders.Is64Bit()) { error = "Update available, but can't install 64-bit files on a 32-bit machine."; errorDetails = "There's an update available (version " + ServerFile.NewVersion + "). However, this update will install files to the x64 (64-bit) system32 folder. And because this machine is an x86 (32-bit), there isn't an x64 system32 folder."; ShowFrame(Frame.Error); return; } // if the update install the x64 system32 folder on an x86 machine we need to throw an error if ((updateFrom.InstallingTo & InstallingTo.CommonFilesx64) == InstallingTo.CommonFilesx64 && !SystemFolders.Is64Bit()) { error = "Update available, but can't install 64-bit files on a 32-bit machine."; errorDetails = "There's an update available (version " + ServerFile.NewVersion + "). However, this update will install files to the x64 (64-bit) \"Program File\\Common Files\" folder. And because this machine is an x86 (32-bit), there isn't an x64 \"Program File\\Common Files\" folder."; ShowFrame(Frame.Error); return; } // Update the client language variables if (VersionTools.Compare(update.InstalledVersion, "1.0.0.0") < 0) { clientLang.UpdateInfo.Content = String.Format("Version {0} of Animatum is ready to be installed. Listed below is its current changelog:", ServerFile.NewVersion); clientLang.UpdateBottom = "Click Install to begin."; clientLang.DownInstall.Content = "Animatum Updater is installing Animatum. This process could take a few minutes."; clientLang.Download = "Downloading Animatum and its dependecies"; clientLang.SuccessUpdate.Content = String.Format("Animatum has been successfully updated to version {0}", ServerFile.NewVersion); clientLang.FinishBottom = "Click Finish to exit and start Animatum."; installing = true; } else { clientLang.UpdateInfo.Content = String.Format("The version of Animatum installed on this computer is {0}. The latest version is {1}. Listed below are the changes and improvements:", update.InstalledVersion, ServerFile.NewVersion); } // set the changes text if (setChangesText || isAutoUpdateMode) { int i = ServerFile.VersionChoices.IndexOf(updateFrom); //if there's a catch-all update start with one less than "update.VersionChoices.Count - 1" //build the changes from all previous versions for (int j = ServerFile.VersionChoices.Count - 1; j >= i; j--) { //show the version number for previous updates we may have missed if (j != ServerFile.VersionChoices.Count - 1 && (!ServerFile.CatchAllUpdateExists || ServerFile.CatchAllUpdateExists && j != ServerFile.VersionChoices.Count - 2)) { panelDisplaying.AppendAndBoldText("\r\n\r\n" + ServerFile.VersionChoices[j + 1].Version + ":\r\n\r\n"); } // append the changes to the total changes list if (!ServerFile.CatchAllUpdateExists || ServerFile.CatchAllUpdateExists && j != ServerFile.VersionChoices.Count - 2) { if (ServerFile.VersionChoices[j].RTFChanges) { panelDisplaying.AppendRichText(ServerFile.VersionChoices[j].Changes); } else { panelDisplaying.AppendText(ServerFile.VersionChoices[j].Changes); } } } } }
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; } }
//returns True if an update is necessary, otherwise false void LoadServerFile(bool setChangesText) { //load the server file ServerFile = ServerFile.Load(serverFileLoc, updatePathVar, customUrlArgs); clientLang.NewVersion = ServerFile.NewVersion; // if no update is needed... if (VersionTools.Compare(update.InstalledVersion, ServerFile.NewVersion) >= 0) { if (isAutoUpdateMode) { // send reponse that there's no update available updateHelper.SendSuccess(null, null, true); // close this client isCancelled = true; // let wyUpdate cleanup the files isAutoUpdateMode = false; // let ServerDownloadedSuccessfully() exit early frameOn = Frame.AlreadyUpToDate; Close(); return; } // Show "All Finished" page ShowFrame(Frame.AlreadyUpToDate); return; } // get the correct update file to download updateFrom = ServerFile.GetVersionChoice(update.InstalledVersion); // if the update install the x64 system32 folder on an x86 machine we need to throw an error if ((updateFrom.InstallingTo & InstallingTo.SysDirx64) == InstallingTo.SysDirx64 && !SystemFolders.Is64Bit()) { error = "Update available, but can't install 64-bit files on a 32-bit machine."; errorDetails = "There's an update available (version " + ServerFile.NewVersion + "). However, this update will install files to the x64 (64-bit) system32 folder. And because this machine is an x86 (32-bit), there isn't an x64 system32 folder."; ShowFrame(Frame.Error); return; } // if the update install the x64 system32 folder on an x86 machine we need to throw an error if ((updateFrom.InstallingTo & InstallingTo.CommonFilesx64) == InstallingTo.CommonFilesx64 && !SystemFolders.Is64Bit()) { error = "Update available, but can't install 64-bit files on a 32-bit machine."; errorDetails = "There's an update available (version " + ServerFile.NewVersion + "). However, this update will install files to the x64 (64-bit) \"Program File\\Common Files\" folder. And because this machine is an x86 (32-bit), there isn't an x64 \"Program File\\Common Files\" folder."; ShowFrame(Frame.Error); return; } // set the changes text if (setChangesText || isAutoUpdateMode) { int i = ServerFile.VersionChoices.IndexOf(updateFrom); //if there's a catch-all update start with one less than "update.VersionChoices.Count - 1" //build the changes from all previous versions for (int j = ServerFile.VersionChoices.Count - 1; j >= i; j--) { //show the version number for previous updates we may have missed if (j != ServerFile.VersionChoices.Count - 1 && (!ServerFile.CatchAllUpdateExists || ServerFile.CatchAllUpdateExists && j != ServerFile.VersionChoices.Count - 2)) { panelDisplaying.AppendAndBoldText("\r\n\r\n" + ServerFile.VersionChoices[j + 1].Version + ":\r\n\r\n"); } // append the changes to the total changes list if (!ServerFile.CatchAllUpdateExists || ServerFile.CatchAllUpdateExists && j != ServerFile.VersionChoices.Count - 2) { if (ServerFile.VersionChoices[j].RTFChanges) { panelDisplaying.AppendRichText(ServerFile.VersionChoices[j].Changes); } else { panelDisplaying.AppendText(ServerFile.VersionChoices[j].Changes); } } } } }