public void CompareTest() { string[] versionA = { "1.0", "1.0 beta 1", "1 a", "1.0 Beta .5", ".9", "1.1.0", "1.0rc2", "1.0beta1", "1.2.03", "1.2rc" }; string[] versionB = { "1.0.0.0", "1.0.0.0 beta 1", "1.0 beta", "1.0 Beta 4", "1.0", "2.1.0", "1.0rc3", "1.0rc2", "1 2 3", "1.2 release candidate" }; int[] expected = { 0, 0, 1, -1, -1, -1, -1, -1, 0, 0 }; //TODO: update this test to use the actual proper return codes from version compare for (int i = 0; i < versionA.Length; i++) { int actual = VersionTools.Compare(versionA[i], versionB[i]); Assert.AreEqual(expected[i], actual); } }
/// <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); } } } } }
//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); } } } } }
void SelfUpdateProgress(int percentDone, int unweightedPercent, string extraStatus, ProgressStatus status, Object payload) { if (IsDisposed) { return; } //update progress bar if (percentDone > -1 && percentDone < 101) { panelDisplaying.Progress = percentDone; } //update bottom status if (!string.IsNullOrEmpty(extraStatus) && extraStatus != panelDisplaying.ProgressStatus) { panelDisplaying.ProgressStatus = extraStatus; } if (installUpdate != null && (status == ProgressStatus.Success || status == ProgressStatus.Failure)) { installUpdate.ProgressChanged -= SelfUpdateProgress; } if (status == ProgressStatus.Success) { if (frameOn == Frame.Checking) { clientSFLoc = downloader.DownloadingTo; try { // client server file downloaded sucessfully DownloadClientSFSuccess(); } catch (Exception e) { //error occured, show error screen status = ProgressStatus.Failure; payload = e; } } else { switch (update.CurrentlyUpdating) { case UpdateOn.DownloadingSelfUpdate: //set the filename of the downloaded client update file updateFilename = downloader.DownloadingTo; if (isAutoUpdateMode) { SelfUpdateState = SelfUpdateState.Downloaded; // save autoupdate file (new selfupdate state is saved) SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable); // begin extracting self update.CurrentlyUpdating = UpdateOn.ExtractSelfUpdate; InstallUpdates(update.CurrentlyUpdating); } else // regular self update mode { panelDisplaying.UpdateItems[0].Status = UpdateItemStatus.Success; //begin extracting and installing the update update.CurrentlyUpdating = UpdateOn.FullSelfUpdate; InstallUpdates(update.CurrentlyUpdating); } break; case UpdateOn.FullSelfUpdate: panelDisplaying.UpdateItems[1].Status = UpdateItemStatus.Success; //start the newly installed client and resume "normal" downloading & updating StartSelfElevated(); break; case UpdateOn.ExtractSelfUpdate: SelfUpdateState = SelfUpdateState.Extracted; // oldSelfLocation already set in the InstallUpdates(ExtractSelfUpdate) newSelfLocation = installUpdate.NewSelfLoc; // save autoupdate file (new selfupdate state is saved) SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable); // start the new client StartNewSelfAndClose(); return; case UpdateOn.InstallSelfUpdate: SelfUpdateState = SelfUpdateState.None; // save autoupdate file (new selfupdate state is saved) SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateReadyToInstall); // we must set new self to false because it's used in StartSelfElevated() // to set the /ns argument for the newly launched wyUpdate IsNewSelf = false; // relaunch newly installed self to do regular update StartSelfElevated(); return; } } } if (status == ProgressStatus.Failure) { bool selfUpdateRequired = VersionTools.Compare(VersionTools.FromExecutingAssembly(), ServerFile.MinClientVersion) < 0; bool canTryCatchAllUpdate = frameOn != Frame.Checking // patch failed && payload.GetType() == typeof(PatchApplicationException) // if the catch-all update isn't the one that failed && updateFrom != SelfServerFile.VersionChoices[SelfServerFile.VersionChoices.Count - 1] // and there is a catch-all update && SelfServerFile.VersionChoices[SelfServerFile.VersionChoices.Count - 1].Version == SelfServerFile.NewVersion; // if a new client is *required* to install the update... if (selfUpdateRequired && !canTryCatchAllUpdate) { //show an error and bail out error = clientLang.SelfUpdateInstallError; errorDetails = ((Exception)payload).Message; ShowFrame(Frame.Error); } else if (frameOn == Frame.Checking) { // client server file failed to download, continue as usual: SelfUpdateState = SelfUpdateState.None; // Show update info page (or just start downloading & installing) if (SkipUpdateInfo) { // check if elevation is needed needElevation = NeedElevationToUpdate(); if (needElevation) { StartSelfElevated(); } else { ShowFrame(Frame.InstallUpdates); } } else { ShowFrame(Frame.UpdateInfo); } } else { if (canTryCatchAllUpdate) { // select the catch all update updateFrom = SelfServerFile.VersionChoices[SelfServerFile.VersionChoices.Count - 1]; // clear errors error = null; errorDetails = null; panelDisplaying.UpdateItems[1].Status = UpdateItemStatus.Nothing; if (isAutoUpdateMode) { // change update state from Downloaded to WillUpdate (just autoupdate) SelfUpdateState = SelfUpdateState.WillUpdate; // save the fact that there's no longer an update file SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable); } // download the catch-all update DownloadUpdate(); return; } if (isAutoUpdateMode) { SelfUpdateState = SelfUpdateState.None; if (update.CurrentlyUpdating == UpdateOn.InstallSelfUpdate) { // update has already been downloaded & extracted SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateReadyToInstall); UpdateHelper_RequestReceived(this, UpdateAction.UpdateStep, UpdateStep.Install); } else { // update hasn't been downloaded yet SaveAutoUpdateData(wyDay.Controls.UpdateStepOn.UpdateAvailable); UpdateHelper_RequestReceived(this, UpdateAction.UpdateStep, UpdateStep.DownloadUpdate); } } else { //self-update failed to download or install //just relaunch old client and continue with update StartSelfElevated(); } } } }