private void Save(string filename) { using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write)) { WriteFiles.WriteHeader(fileStream, "AUIF"); UpdateStepOn = UpdateStepOn.Nothing; WriteFiles.WriteDateTime(fileStream, 1, LastCheckedForUpdate); WriteFiles.WriteInt(fileStream, 2, (int)UpdateStepOn); WriteFiles.WriteInt(fileStream, 3, (int)AutoUpdaterStatus); if (!string.IsNullOrEmpty(UpdateVersion)) { WriteFiles.WriteString(fileStream, 4, UpdateVersion); } if (!string.IsNullOrEmpty(ChangesInLatestVersion)) { WriteFiles.WriteString(fileStream, 5, ChangesInLatestVersion); WriteFiles.WriteBool(fileStream, 6, ChangesIsRTF); } if (!string.IsNullOrEmpty(ErrorTitle)) { WriteFiles.WriteString(fileStream, 7, ErrorTitle); } if (!string.IsNullOrEmpty(ErrorMessage)) { WriteFiles.WriteString(fileStream, 8, ErrorMessage); } fileStream.WriteByte(byte.MaxValue); } }
void SetUpdateStepOn(UpdateStepOn uso) { switch (uso) { case UpdateStepOn.Checking: Text = currentActionText = translation.Checking; break; case UpdateStepOn.DownloadingUpdate: Text = currentActionText = translation.Downloading; break; case UpdateStepOn.ExtractingUpdate: Text = currentActionText = translation.Extracting; break; case UpdateStepOn.UpdateAvailable: Text = translation.UpdateAvailable; break; case UpdateStepOn.UpdateDownloaded: Text = translation.UpdateAvailable; break; case UpdateStepOn.UpdateReadyToInstall: Text = translation.InstallOnNextStart; break; } }
void UpdateStepFailed(UpdateStepOn us, FailArgs args) { SetLastSuccessfulStep(); switch (us) { case UpdateStepOn.Checking: if (CheckingFailed != null) { CheckingFailed(this, args); } break; case UpdateStepOn.DownloadingUpdate: if (DownloadingFailed != null) { DownloadingFailed(this, args); } break; case UpdateStepOn.ExtractingUpdate: if (ExtractingFailed != null) { ExtractingFailed(this, args); } break; } }
void Load(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!ReadFiles.IsHeaderValid(fs, "AUIF")) { //free up the file so it can be deleted fs.Close(); throw new Exception("Auto update state file ID is wrong."); } byte bType = (byte)fs.ReadByte(); while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF)) { switch (bType) { case 0x01: // Date last checked for update LastCheckedForUpdate = ReadFiles.ReadDateTime(fs); break; case 0x02: // update step on UpdateStepOn = (UpdateStepOn)ReadFiles.ReadInt(fs); break; case 0x03: AutoUpdaterStatus = (AutoUpdaterStatus)ReadFiles.ReadInt(fs); break; case 0x04: // update succeeded UpdateVersion = ReadFiles.ReadString(fs); break; case 0x05: ChangesInLatestVersion = ReadFiles.ReadString(fs); break; case 0x06: ChangesIsRTF = ReadFiles.ReadBool(fs); break; case 0x07: // update failed ErrorTitle = ReadFiles.ReadString(fs); break; case 0x08: ErrorMessage = ReadFiles.ReadString(fs); break; default: ReadFiles.SkipField(fs, bType); break; } bType = (byte)fs.ReadByte(); } } }
private void Load(string filename) { using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!ReadFiles.IsHeaderValid(fileStream, "AUIF")) { fileStream.Close(); throw new Exception("Auto update state file ID is wrong."); } byte b = (byte)fileStream.ReadByte(); while (!ReadFiles.ReachedEndByte(fileStream, b, byte.MaxValue)) { switch (b) { case 1: LastCheckedForUpdate = ReadFiles.ReadDateTime(fileStream); break; case 2: UpdateStepOn = (UpdateStepOn)ReadFiles.ReadInt(fileStream); break; case 3: AutoUpdaterStatus = (AutoUpdaterStatus)ReadFiles.ReadInt(fileStream); break; case 4: UpdateVersion = ReadFiles.ReadString(fileStream); break; case 5: ChangesInLatestVersion = ReadFiles.ReadString(fileStream); break; case 6: ChangesIsRTF = ReadFiles.ReadBool(fileStream); break; case 7: ErrorTitle = ReadFiles.ReadString(fileStream); break; case 8: ErrorMessage = ReadFiles.ReadString(fileStream); break; default: ReadFiles.SkipField(fileStream, b); break; } b = (byte)fileStream.ReadByte(); } } }
void Save(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write)) { // Write any file-identification data you want to here WriteFiles.WriteHeader(fs, "AUIF"); #if CLIENT UpdateStepOn = UpdateStepOn.Nothing; #endif // Date last checked for update WriteFiles.WriteDateTime(fs, 0x01, LastCheckedForUpdate); // update step on WriteFiles.WriteInt(fs, 0x02, (int)UpdateStepOn); #if CLIENT // only save the AutoUpdaterStatus when wyUpdate writes the file WriteFiles.WriteInt(fs, 0x03, (int)AutoUpdaterStatus); #endif if (!string.IsNullOrEmpty(UpdateVersion)) { WriteFiles.WriteString(fs, 0x04, UpdateVersion); } if (!string.IsNullOrEmpty(ChangesInLatestVersion)) { WriteFiles.WriteString(fs, 0x05, ChangesInLatestVersion); WriteFiles.WriteBool(fs, 0x06, ChangesIsRTF); } #if CLIENT if (!string.IsNullOrEmpty(ErrorTitle)) { WriteFiles.WriteString(fs, 0x07, ErrorTitle); } if (!string.IsNullOrEmpty(ErrorMessage)) { WriteFiles.WriteString(fs, 0x08, ErrorMessage); } #endif fs.WriteByte(0xFF); } }
public MainForm(string[] args) { IsAdmin = Win32.IsUserAnAdmin(); InitializeComponent(); panelDisplaying = new PanelDisplay(mainPanel.Width, mainPanel.Height); panelDisplaying.Dock = DockStyle.Fill; panelDisplaying.BackColor = this.BackColor; mainPanel.Controls.Add(panelDisplaying); mainPanel.Width = ClientRectangle.Width; update.ServerFileSites.Add("http://web.cecs.pdx.edu/~chances/animatum/animatum.update"); animatumLocation = Path.Combine(baseDirectory, "Animatum.exe"); if (File.Exists(animatumLocation)) { update.InstalledVersion = FileVersionInfo.GetVersionInfo(animatumLocation).FileVersion; } else { update.InstalledVersion = "0.0.0.0"; } panelDisplaying.UpdateItems[1].Text = "Installing dependencies"; panelDisplaying.UpdateItems[2].Text = "Backing up and updating files"; //process commandline argument Arguments commands = new Arguments(args); ProcessArguments(commands); //sets up Next & Cancel buttons SetButtonText(); if (isAutoUpdateMode) { } startStep = UpdateStepOn.Checking; }
void PrepareStepOn(UpdateStepOn step) { switch (step) { case UpdateStepOn.Checking: ShowFrame(Frame.Checking); break; case UpdateStepOn.UpdateAvailable: ShowFrame(Frame.UpdateInfo); break; case UpdateStepOn.UpdateDownloaded: // set the update step pending (extracting) update.CurrentlyUpdating = UpdateOn.Extracting; needElevation = NeedElevationToUpdate(); // show frame InstallUpdate ShowFrame(Frame.InstallUpdates); // put a checkmark next to downloaded panelDisplaying.UpdateItems[0].Status = UpdateItemStatus.Success; break; case UpdateStepOn.UpdateReadyToInstall: string updtDetailsFilename = Path.Combine(tempDirectory, "updtdetails.udt"); // Try to load the update details file if (File.Exists(updtDetailsFilename)) { updtDetails = UpdateDetails.Load(updtDetailsFilename); } else throw new Exception("Update details file does not exist."); // set the update step pending (closing processes & installing files, etc.) update.CurrentlyUpdating = UpdateOn.ClosingProcesses; needElevation = NeedElevationToUpdate(); // show frame InstallUpdate ShowFrame(Frame.InstallUpdates); // put a checkmark next to downloaded panelDisplaying.UpdateItems[0].Status = UpdateItemStatus.Success; // set the "Extracting" text SetStepStatus(1, clientLang.Extract); break; default: throw new Exception("Can't restore from this automatic update state: " + step); } }
public AutoUpdaterInfo(string auID, string oldAUTempFolder) { autoUpdateID = auID; // get the admin filename filenames[0] = GetFilename(); #if CLIENT // if tempFolder is not in ApplicationData, then we're updating on behalf of a limited user if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder)) { // AutoUpdateFiles are stored in: %appdata%\wyUpdate AU\ // The tempFolder is: %appdata%\wyUpdate AU\cache\AppGUID\ // get the limited user's AutoUpdate file filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate"); // check if LimitedUser AutoUpdateFile exists if (!File.Exists(filenames[1])) filenames[1] = null; } #endif bool failedToLoad; bool firstFailed = false; int retriedTimes = 0; while (true) { try { // try to load the AutoUpdatefile for limited user if (filenames[1] != null && !firstFailed) Load(filenames[1]); else // load the admin user Load(filenames[0]); failedToLoad = false; } catch (IOException IOEx) { int HResult = Marshal.GetHRForException(IOEx); // if sharing violation if ((HResult & 0xFFFF) == 32) { // sleep for 1/2 second Thread.Sleep(500); // if we're skipping UI and we've already waited 20 seconds for a file to be released // then throw the exception, rollback updates, etc if (retriedTimes != 20) { // otherwise, retry file copy ++retriedTimes; continue; } } failedToLoad = true; // the first has already failed (the second just failed) if (firstFailed) break; firstFailed = true; continue; } catch { failedToLoad = true; // the first has already failed (the second just failed) if (firstFailed) break; firstFailed = true; continue; } break; } if (failedToLoad) { LastCheckedForUpdate = DateTime.MinValue; UpdateStepOn = UpdateStepOn.Nothing; } }
void Save(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write)) { // Write any file-identification data you want to here WriteFiles.WriteHeader(fs, "AUIF"); #if CLIENT UpdateStepOn = UpdateStepOn.Nothing; #endif // Date last checked for update WriteFiles.WriteDateTime(fs, 0x01, LastCheckedForUpdate); // update step on WriteFiles.WriteInt(fs, 0x02, (int)UpdateStepOn); #if CLIENT // only save the AutoUpdaterStatus when wyUpdate writes the file WriteFiles.WriteInt(fs, 0x03, (int)AutoUpdaterStatus); #endif if (!string.IsNullOrEmpty(UpdateVersion)) WriteFiles.WriteString(fs, 0x04, UpdateVersion); if (!string.IsNullOrEmpty(ChangesInLatestVersion)) { WriteFiles.WriteString(fs, 0x05, ChangesInLatestVersion); WriteFiles.WriteBool(fs, 0x06, ChangesIsRTF); } #if CLIENT if (!string.IsNullOrEmpty(ErrorTitle)) WriteFiles.WriteString(fs, 0x07, ErrorTitle); if (!string.IsNullOrEmpty(ErrorMessage)) WriteFiles.WriteString(fs, 0x08, ErrorMessage); #endif fs.WriteByte(0xFF); } }
void Load(string filename) { #if !CLIENT // Disable filesystem redirection on x64 (mostly for Windows Services) if (Is32BitProcessOn64BitProcessor()) EnableWow64FSRedirection(false); try { #endif using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!ReadFiles.IsHeaderValid(fs, "AUIF")) { //free up the file so it can be deleted fs.Close(); throw new Exception("Auto update state file ID is wrong."); } byte bType = (byte)fs.ReadByte(); while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF)) { switch (bType) { case 0x01: // Date last checked for update LastCheckedForUpdate = ReadFiles.ReadDateTime(fs); break; case 0x02: // update step on UpdateStepOn = (UpdateStepOn) ReadFiles.ReadInt(fs); break; case 0x03: AutoUpdaterStatus = (AutoUpdaterStatus) ReadFiles.ReadInt(fs); break; case 0x04: // update succeeded UpdateVersion = ReadFiles.ReadString(fs); break; case 0x05: ChangesInLatestVersion = ReadFiles.ReadString(fs); break; case 0x06: ChangesIsRTF = ReadFiles.ReadBool(fs); break; case 0x07: // update failed ErrorTitle = ReadFiles.ReadString(fs); break; case 0x08: ErrorMessage = ReadFiles.ReadString(fs); break; default: ReadFiles.SkipField(fs, bType); break; } bType = (byte)fs.ReadByte(); } } #if !CLIENT } finally { // Re-enable filesystem redirection on x64 if (Is32BitProcessOn64BitProcessor()) EnableWow64FSRedirection(true); } #endif }
public AutoUpdaterInfo(string auID, string oldAUTempFolder) { autoUpdateID = auID; // get the admin filename filenames[0] = GetFilename(); #if CLIENT // if tempFolder is not in ApplicationData, then we're updating on behalf of a limited user if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder)) { // AutoUpdateFiles are stored in: %appdata%\wyUpdate AU\ // The tempFolder is: %appdata%\wyUpdate AU\cache\AppGUID\ // get the limited user's AutoUpdate file filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate"); // check if LimitedUser AutoUpdateFile exists if (!File.Exists(filenames[1])) { filenames[1] = null; } } #endif bool failedToLoad = false; try { // try to load the AutoUpdatefile for limited user if (filenames[1] != null) { Load(filenames[1]); } else // load the admin user { Load(filenames[0]); } } catch { if (filenames[1] != null) { try { // try to load the AutoUpdateFile for the admin user Load(filenames[0]); } catch { failedToLoad = true; } } else { failedToLoad = true; } } if (failedToLoad) { LastCheckedForUpdate = DateTime.MinValue; UpdateStepOn = UpdateStepOn.Nothing; } }
void PrepareStepOn(UpdateStepOn step) { switch (step) { case UpdateStepOn.Checking: ShowFrame(Frame.Checking); break; case UpdateStepOn.UpdateAvailable: ShowFrame(Frame.UpdateInfo); break; case UpdateStepOn.UpdateDownloaded: // set the update step pending (extracting) update.CurrentlyUpdating = UpdateOn.Extracting; needElevation = NeedElevationToUpdate(); // show frame InstallUpdate ShowFrame(Frame.InstallUpdates); // put a checkmark next to downloaded panelDisplaying.UpdateItems[0].Status = UpdateItemStatus.Success; break; case UpdateStepOn.UpdateReadyToInstall: string updtDetailsFilename = Path.Combine(tempDirectory, "updtdetails.udt"); // Try to load the update details file if (File.Exists(updtDetailsFilename)) { updtDetails = UpdateDetails.Load(updtDetailsFilename); } else { throw new Exception("Update details file does not exist."); } // set the update step pending (closing processes & installing files, etc.) update.CurrentlyUpdating = UpdateOn.ClosingProcesses; needElevation = NeedElevationToUpdate(); // show frame InstallUpdate ShowFrame(Frame.InstallUpdates); // put a checkmark next to downloaded panelDisplaying.UpdateItems[0].Status = UpdateItemStatus.Success; // set the "Extracting" text SetStepStatus(1, clientLang.Extract); break; default: throw new Exception("Can't restore from this automatic update state: " + step); } }
protected override void SetVisibleCore(bool value) { base.SetVisibleCore(value); if (!_isApplicationRun) { return; } _isApplicationRun = false; if (isAutoUpdateMode) { /* SetupAutoupdateMode must happen after the handle is created * (aka. in OnHandleCreated, or after base.SetVisibleCore() is called) * because Control.Invoke() used in UpdateHelper * requires the handle to be created. * * This solves the problem where the AutomaticUpdater control sends a message, * it thinks the message was recieved successfully because there * wasn't an error on the pipe stream, however in reality it never gets past * the try-catch block in 'pipeServer_MessageReceived'. The exception is gobbled up * and there's a stalemate: wyUpdate is waiting for its first message, AutomaticUpdater * is waiting for a progress report. */ SetupAutoupdateMode(); } // run the OnLoad code if (startStep != UpdateStepOn.Nothing) { // either begin checking or load the step from the autoupdate file try { PrepareStepOn(startStep); // selfupdate & post-selfupdate installation if (beginAutoUpdateInstallation) { UpdateHelper_RequestReceived(this, UpdateAction.UpdateStep, UpdateStep.Install); } } catch (Exception ex) { if (startStep != UpdateStepOn.Checking) { startStep = UpdateStepOn.Checking; } else { // show the error screen error = "Automatic update state failed to load."; errorDetails = ex.Message; ShowFrame(Frame.Error); return; } try { PrepareStepOn(startStep); } catch (Exception ex2) { // show the error screen error = "Automatic update state failed to load."; errorDetails = ex2.Message; ShowFrame(Frame.Error); } } } }
void UpdateStepFailed(UpdateStepOn us, FailArgs args) { SetLastSuccessfulStep(); switch (us) { case UpdateStepOn.Checking: if (CheckingFailed != null) CheckingFailed(this, args); break; case UpdateStepOn.DownloadingUpdate: if (DownloadingFailed != null) DownloadingFailed(this, args); break; case UpdateStepOn.ExtractingUpdate: if (ExtractingFailed != null) ExtractingFailed(this, args); break; } }
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; } }
public AutoUpdaterInfo(string auID, string oldAUTempFolder) { autoUpdateID = auID; filenames[0] = GetFilename(); if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder)) { filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate"); if (!File.Exists(filenames[1])) { filenames[1] = null; } } bool flag = false; int num = 0; bool flag2; while (true) { try { if (filenames[1] != null && !flag) { Load(filenames[1]); } else { Load(filenames[0]); } flag2 = false; } catch (IOException e) { int hRForException = Marshal.GetHRForException(e); if ((hRForException & 0xFFFF) == 32) { Thread.Sleep(500); if (num != 20) { num++; continue; } } flag2 = true; if (!flag) { flag = true; continue; } } catch { flag2 = true; if (!flag) { flag = true; continue; } } break; } if (flag2) { LastCheckedForUpdate = DateTime.MinValue; UpdateStepOn = UpdateStepOn.Nothing; } }
public MainForm(string[] args) { IsAdmin = Win32.IsUserAnAdmin(); InitializeComponent(); panelDisplaying = new PanelDisplay(mainPanel.Width, mainPanel.Height); panelDisplaying.Dock = DockStyle.Fill; panelDisplaying.BackColor = this.BackColor; mainPanel.Controls.Add(panelDisplaying); mainPanel.Width = ClientRectangle.Width; update.ServerFileSites.Add("http://web.cecs.pdx.edu/~chances/animatum/animatum.update"); animatumLocation = Path.Combine(baseDirectory, "Animatum.exe"); if (File.Exists(animatumLocation)) update.InstalledVersion = FileVersionInfo.GetVersionInfo(animatumLocation).FileVersion; else update.InstalledVersion = "0.0.0.0"; panelDisplaying.UpdateItems[1].Text = "Installing dependencies"; panelDisplaying.UpdateItems[2].Text = "Backing up and updating files"; //process commandline argument Arguments commands = new Arguments(args); ProcessArguments(commands); //sets up Next & Cancel buttons SetButtonText(); if (isAutoUpdateMode) { } startStep = UpdateStepOn.Checking; }
void Load(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!ReadFiles.IsHeaderValid(fs, "AUIF")) { //free up the file so it can be deleted fs.Close(); throw new Exception("Auto update state file ID is wrong."); } byte bType = (byte)fs.ReadByte(); while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF)) { switch (bType) { case 0x01: // Date last checked for update LastCheckedForUpdate = ReadFiles.ReadDateTime(fs); break; case 0x02: // update step on UpdateStepOn = (UpdateStepOn) ReadFiles.ReadInt(fs); break; case 0x03: AutoUpdaterStatus = (AutoUpdaterStatus) ReadFiles.ReadInt(fs); break; case 0x04: // update succeeded UpdateVersion = ReadFiles.ReadString(fs); break; case 0x05: ChangesInLatestVersion = ReadFiles.ReadString(fs); break; case 0x06: ChangesIsRTF = ReadFiles.ReadBool(fs); break; case 0x07: // update failed ErrorTitle = ReadFiles.ReadString(fs); break; case 0x08: ErrorMessage = ReadFiles.ReadString(fs); break; default: ReadFiles.SkipField(fs, bType); break; } bType = (byte)fs.ReadByte(); } } }
protected override void SetVisibleCore(bool value) { base.SetVisibleCore(value); if (!_isApplicationRun) return; _isApplicationRun = false; if (isAutoUpdateMode) { /* SetupAutoupdateMode must happen after the handle is created * (aka. in OnHandleCreated, or after base.SetVisibleCore() is called) * because Control.Invoke() used in UpdateHelper * requires the handle to be created. * * This solves the problem where the AutomaticUpdater control sends a message, * it thinks the message was recieved successfully because there * wasn't an error on the pipe stream, however in reality it never gets past * the try-catch block in 'pipeServer_MessageReceived'. The exception is gobbled up * and there's a stalemate: wyUpdate is waiting for its first message, AutomaticUpdater * is waiting for a progress report. */ SetupAutoupdateMode(); } // run the OnLoad code if (startStep != UpdateStepOn.Nothing) { // either begin checking or load the step from the autoupdate file try { PrepareStepOn(startStep); // selfupdate & post-selfupdate installation if (beginAutoUpdateInstallation) UpdateHelper_RequestReceived(this, UpdateAction.UpdateStep, UpdateStep.Install); } catch (Exception ex) { if (startStep != UpdateStepOn.Checking) startStep = UpdateStepOn.Checking; else { // show the error screen error = "Automatic update state failed to load."; errorDetails = ex.Message; ShowFrame(Frame.Error); return; } try { PrepareStepOn(startStep); } catch (Exception ex2) { // show the error screen error = "Automatic update state failed to load."; errorDetails = ex2.Message; ShowFrame(Frame.Error); } } } }
/// <summary> /// The function that must be called when your app has loaded. /// </summary> public void AppLoaded() { if (AutoUpdaterInfo == null) { throw new FailedToInitializeException(); } // if we want to kill ourself, then don't bother checking for updates if (ClosingForInstall) { return; } // get the current update step from the info file m_UpdateStepOn = AutoUpdaterInfo.UpdateStepOn; if (UpdateStepOn != UpdateStepOn.Nothing) { version = AutoUpdaterInfo.UpdateVersion; changes = AutoUpdaterInfo.ChangesInLatestVersion; changesAreRTF = AutoUpdaterInfo.ChangesIsRTF; switch (UpdateStepOn) { case UpdateStepOn.UpdateAvailable: if (internalUpdateType == UpdateType.CheckAndDownload || internalUpdateType == UpdateType.Automatic) { DownloadUpdate(); // begin downloading the update } else { UpdateReady(); } break; case UpdateStepOn.UpdateReadyToInstall: UpdateReadyToInstall(); break; case UpdateStepOn.UpdateDownloaded: if (internalUpdateType == UpdateType.Automatic) { ExtractUpdate(); // begin extraction } else { UpdateReadyToExtract(); } break; } } else // UpdateStepOn == UpdateStepOn.Nothing { switch (AutoUpdaterInfo.AutoUpdaterStatus) { case AutoUpdaterStatus.UpdateSucceeded: // set the version & changes version = AutoUpdaterInfo.UpdateVersion; changes = AutoUpdaterInfo.ChangesInLatestVersion; changesAreRTF = AutoUpdaterInfo.ChangesIsRTF; if (UpdateSuccessful != null) { UpdateSuccessful(this, new SuccessArgs { Version = version }); } break; case AutoUpdaterStatus.UpdateFailed: if (UpdateFailed != null) { UpdateFailed(this, new FailArgs { ErrorTitle = AutoUpdaterInfo.ErrorTitle, ErrorMessage = AutoUpdaterInfo.ErrorMessage }); } break; } // clear the changes and resave AutoUpdaterInfo.ClearSuccessError(); AutoUpdaterInfo.Save(); } }
void SaveAutoUpdateData(UpdateStepOn updateStepOn) { using (FileStream fs = new FileStream(autoUpdateStateFile, FileMode.Create, FileAccess.Write)) { // Write any file-identification data you want to here WriteFiles.WriteHeader(fs, "IUAUFV1"); if (SelfUpdateState == SelfUpdateState.Extracted) { string selfUpdatePath = Path.Combine(tempDirectory, "selfUpdate.sup"); // save the self update file SaveSelfUpdateData(selfUpdatePath); WriteFiles.WriteString(fs, 0x0D, selfUpdatePath); } // Step on {Checked = 2, Downloaded = 4, Extracted = 6} WriteFiles.WriteInt(fs, 0x01, (int)updateStepOn); // file to execute if (updateHelper.FileOrServiceToExecuteAfterUpdate != null) WriteFiles.WriteString(fs, 0x02, updateHelper.FileOrServiceToExecuteAfterUpdate); if (updateHelper.AutoUpdateID != null) WriteFiles.WriteString(fs, 0x03, updateHelper.AutoUpdateID); if (updateHelper.ExecutionArguments != null) WriteFiles.WriteString(fs, 0x0C, updateHelper.ExecutionArguments); // is the file a service? if (updateHelper.IsAService) fs.WriteByte(0x80); // Server data file location if (!string.IsNullOrEmpty(serverFileLoc)) WriteFiles.WriteString(fs, 0x04, serverFileLoc); // Client's server file location (self update server file) if (!string.IsNullOrEmpty(clientSFLoc)) WriteFiles.WriteString(fs, 0x05, clientSFLoc); // temp directory if (!string.IsNullOrEmpty(oldAUTempFolder)) WriteFiles.WriteString(fs, 0x06, oldAUTempFolder); if (!string.IsNullOrEmpty(tempDirectory)) WriteFiles.WriteString(fs, 0x0B, tempDirectory); // the update filename if (!string.IsNullOrEmpty(updateFilename)) WriteFiles.WriteString(fs, 0x07, updateFilename); if (SelfUpdateState != SelfUpdateState.None) { WriteFiles.WriteInt(fs, 0x08, (int) SelfUpdateState); if (SelfUpdateState == SelfUpdateState.Downloaded) WriteFiles.WriteString(fs, 0x09, updateFilename); else if (SelfUpdateState == SelfUpdateState.Extracted) { WriteFiles.WriteString(fs, 0x09, newSelfLocation); WriteFiles.WriteString(fs, 0x0A, oldSelfLocation); } } fs.WriteByte(0xFF); } }
void Load(string filename) { #if !CLIENT // Disable filesystem redirection on x64 (mostly for Windows Services) if (Is32BitProcessOn64BitProcessor()) { EnableWow64FSRedirection(false); } try { #endif using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!ReadFiles.IsHeaderValid(fs, "AUIF")) { //free up the file so it can be deleted fs.Close(); throw new Exception("Auto update state file ID is wrong."); } byte bType = (byte)fs.ReadByte(); while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF)) { switch (bType) { case 0x01: // Date last checked for update LastCheckedForUpdate = ReadFiles.ReadDateTime(fs); break; case 0x02: // update step on UpdateStepOn = (UpdateStepOn)ReadFiles.ReadInt(fs); break; case 0x03: AutoUpdaterStatus = (AutoUpdaterStatus)ReadFiles.ReadInt(fs); break; case 0x04: // update succeeded UpdateVersion = ReadFiles.ReadString(fs); break; case 0x05: ChangesInLatestVersion = ReadFiles.ReadString(fs); break; case 0x06: ChangesIsRTF = ReadFiles.ReadBool(fs); break; case 0x07: // update failed ErrorTitle = ReadFiles.ReadString(fs); break; case 0x08: ErrorMessage = ReadFiles.ReadString(fs); break; default: ReadFiles.SkipField(fs, bType); break; } bType = (byte)fs.ReadByte(); } } #if !CLIENT } finally { // Re-enable filesystem redirection on x64 if (Is32BitProcessOn64BitProcessor()) { EnableWow64FSRedirection(true); } } #endif }
public AutoUpdaterInfo(string auID, string oldAUTempFolder) { autoUpdateID = auID; // get the admin filename filenames[0] = GetFilename(); #if CLIENT // if tempFolder is not in ApplicationData, then we're updating on behalf of a limited user if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder)) { // AutoUpdateFiles are stored in: %appdata%\wyUpdate AU\ // The tempFolder is: %appdata%\wyUpdate AU\cache\AppGUID\ // get the limited user's AutoUpdate file filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate"); // check if LimitedUser AutoUpdateFile exists if (!File.Exists(filenames[1])) { filenames[1] = null; } } #endif bool failedToLoad; bool firstFailed = false; int retriedTimes = 0; while (true) { try { // try to load the AutoUpdatefile for limited user if (filenames[1] != null && !firstFailed) { Load(filenames[1]); } else // load the admin user { Load(filenames[0]); } failedToLoad = false; } catch (IOException IOEx) { int HResult = Marshal.GetHRForException(IOEx); // if sharing violation if ((HResult & 0xFFFF) == 32) { // sleep for 1/2 second Thread.Sleep(500); // if we're skipping UI and we've already waited 20 seconds for a file to be released // then throw the exception, rollback updates, etc if (retriedTimes != 20) { // otherwise, retry file copy ++retriedTimes; continue; } } failedToLoad = true; // the first has already failed (the second just failed) if (firstFailed) { break; } firstFailed = true; continue; } catch { failedToLoad = true; // the first has already failed (the second just failed) if (firstFailed) { break; } firstFailed = true; continue; } break; } if (failedToLoad) { LastCheckedForUpdate = DateTime.MinValue; UpdateStepOn = UpdateStepOn.Nothing; } }
void SaveAutoUpdateData(UpdateStepOn updateStepOn) { using (FileStream fs = new FileStream(autoUpdateStateFile, FileMode.Create, FileAccess.Write)) { // Write any file-identification data you want to here WriteFiles.WriteHeader(fs, "IUAUFV1"); if (SelfUpdateState == SelfUpdateState.Extracted) { string selfUpdatePath = Path.Combine(tempDirectory, "selfUpdate.sup"); // save the self update file SaveSelfUpdateData(selfUpdatePath); WriteFiles.WriteString(fs, 0x0D, selfUpdatePath); } // Step on {Checked = 2, Downloaded = 4, Extracted = 6} WriteFiles.WriteInt(fs, 0x01, (int)updateStepOn); // file to execute if (updateHelper.FileOrServiceToExecuteAfterUpdate != null) { WriteFiles.WriteString(fs, 0x02, updateHelper.FileOrServiceToExecuteAfterUpdate); } if (updateHelper.AutoUpdateID != null) { WriteFiles.WriteString(fs, 0x03, updateHelper.AutoUpdateID); } if (updateHelper.ExecutionArguments != null) { WriteFiles.WriteString(fs, 0x0C, updateHelper.ExecutionArguments); } // is the file a service? if (updateHelper.IsAService) { fs.WriteByte(0x80); } // Server data file location if (!string.IsNullOrEmpty(serverFileLoc)) { WriteFiles.WriteString(fs, 0x04, serverFileLoc); } // Client's server file location (self update server file) if (!string.IsNullOrEmpty(clientSFLoc)) { WriteFiles.WriteString(fs, 0x05, clientSFLoc); } // temp directory if (!string.IsNullOrEmpty(oldAUTempFolder)) { WriteFiles.WriteString(fs, 0x06, oldAUTempFolder); } if (!string.IsNullOrEmpty(tempDirectory)) { WriteFiles.WriteString(fs, 0x0B, tempDirectory); } // the update filename if (!string.IsNullOrEmpty(updateFilename)) { WriteFiles.WriteString(fs, 0x07, updateFilename); } if (SelfUpdateState != SelfUpdateState.None) { WriteFiles.WriteInt(fs, 0x08, (int)SelfUpdateState); if (SelfUpdateState == SelfUpdateState.Downloaded) { WriteFiles.WriteString(fs, 0x09, updateFilename); } else if (SelfUpdateState == SelfUpdateState.Extracted) { WriteFiles.WriteString(fs, 0x09, newSelfLocation); WriteFiles.WriteString(fs, 0x0A, oldSelfLocation); } } fs.WriteByte(0xFF); } }
public AutoUpdaterInfo(string auID, string oldAUTempFolder) { autoUpdateID = auID; // get the admin filename filenames[0] = GetFilename(); #if CLIENT // if tempFolder is not in ApplicationData, then we're updating on behalf of a limited user if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder)) { // AutoUpdateFiles are stored in: %appdata%\wyUpdate AU\ // The tempFolder is: %appdata%\wyUpdate AU\cache\AppGUID\ // get the limited user's AutoUpdate file filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate"); // check if LimitedUser AutoUpdateFile exists if (!File.Exists(filenames[1])) filenames[1] = null; } #endif bool failedToLoad = false; try { // try to load the AutoUpdatefile for limited user if (filenames[1] != null) Load(filenames[1]); else // load the admin user Load(filenames[0]); } catch { if (filenames[1] != null) { try { // try to load the AutoUpdateFile for the admin user Load(filenames[0]); } catch { failedToLoad = true; } } else failedToLoad = true; } if (failedToLoad) { LastCheckedForUpdate = DateTime.MinValue; UpdateStepOn = UpdateStepOn.Nothing; } }
/// <summary> /// The function that must be called when your app has loaded. /// </summary> public void AppLoaded() { if (AutoUpdaterInfo == null) throw new FailedToInitializeException(); // if we want to kill ourself, then don't bother checking for updates if (ClosingForInstall) return; // get the current update step from the info file m_UpdateStepOn = AutoUpdaterInfo.UpdateStepOn; if (UpdateStepOn != UpdateStepOn.Nothing) { version = AutoUpdaterInfo.UpdateVersion; changes = AutoUpdaterInfo.ChangesInLatestVersion; changesAreRTF = AutoUpdaterInfo.ChangesIsRTF; switch (UpdateStepOn) { case UpdateStepOn.UpdateAvailable: if (internalUpdateType == UpdateType.CheckAndDownload || internalUpdateType == UpdateType.Automatic) DownloadUpdate(); // begin downloading the update else UpdateReady(); break; case UpdateStepOn.UpdateReadyToInstall: UpdateReadyToInstall(); break; case UpdateStepOn.UpdateDownloaded: if (internalUpdateType == UpdateType.Automatic) ExtractUpdate(); // begin extraction else UpdateReadyToExtract(); break; } } else // UpdateStepOn == UpdateStepOn.Nothing { switch (AutoUpdaterInfo.AutoUpdaterStatus) { case AutoUpdaterStatus.UpdateSucceeded: // set the version & changes version = AutoUpdaterInfo.UpdateVersion; changes = AutoUpdaterInfo.ChangesInLatestVersion; changesAreRTF = AutoUpdaterInfo.ChangesIsRTF; if (UpdateSuccessful != null) UpdateSuccessful(this, new SuccessArgs { Version = version }); break; case AutoUpdaterStatus.UpdateFailed: if (UpdateFailed != null) UpdateFailed(this, new FailArgs { ErrorTitle = AutoUpdaterInfo.ErrorTitle, ErrorMessage = AutoUpdaterInfo.ErrorMessage }); break; } // clear the changes and resave AutoUpdaterInfo.ClearSuccessError(); AutoUpdaterInfo.Save(); } }
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.EnableLazySSL(); //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; }