public void SetPercent(float per) { this.percent = per; if (per >= 1.0f) { this.percent = 1.0f; this.status = UPDATE_STATUS.FINISH; } }
public ResourcesUpdateData(UPDATE_STATUS status, float percent) { this.status = status; this.percent = percent; }
public void Reset() { this.status = UPDATE_STATUS.NONE; this.percent = 0; this.speed = 0; }
/// <summary> /// Finds an update for target. This is a bootstrapper, meaning that cupdt.exe is started before targetclient is started. /// In a Nutshell: /// - If a new local version is found in the parent folder i.e. EXECUTABLE_DIRECTORY_PARENT/x.y.z.w/targetclient.exe then cupdt.exe of that folder is started /// - If a new online version (x.y.z.w) exists it is downloaded and extracted in EXECUTABLE_DIRECTORY_PARENT/x.y.z.w/ /// - If a new config version (client_check_x.y.z.w) exists it is downloaded to the currenct folder, i.e. EXECUTABLE_DIRECTORY /// /// .. the rest of the code are various checks to prevent infinite update loops etc. /// </summary> /// <param name="args">None</param> static void Main(string[] args) { // Determine whether we are in the correct folder, and set static vars Init(); EnactMutex(); int updateTimer = UPDATE_TIMER; string newVersionPath; while (true) { bool exit = false; if (updateTimer >= (RETRIES * COOL_DOWN_FACTOR * UPDATE_TIMER)) { exit = true; } UPDATE_STATUS retUpdate = CheckUpdate(out newVersionPath); switch (retUpdate) { // If we were not able to download the file (server or access rights) case UPDATE_STATUS.ONLINE_ERROR: Util.PrintInformation(Configuration.InformationStrings.NONE, "Update was not successful, (probably) server error, incrementing cooldown", Util.PrintMode.ERROR, exit); updateTimer *= COOL_DOWN_FACTOR; break; case UPDATE_STATUS.OFFLINE_ERROR: Util.PrintInformation(Configuration.InformationStrings.NONE, "Update was not successful, (probably) client error, incrementing cooldown", Util.PrintMode.ERROR, exit); updateTimer *= COOL_DOWN_FACTOR; break; case UPDATE_STATUS.START_UPDT: Util.PrintInformation(Configuration.InformationStrings.NONE, "Update was successful: " + newVersionPath, Util.PrintMode.NORMAL, false); if (!StartNewUpdtProc(newVersionPath)) { Util.PrintInformation(Configuration.InformationStrings.NONE, "Could not start new updater", Util.PrintMode.ERROR, exit); updateTimer *= COOL_DOWN_FACTOR; break; } #if __DEBUG Console.ReadKey(); #endif Util.PrintInformation(Configuration.InformationStrings.NONE, "Successfully started new updater", Util.PrintMode.NORMAL, true); break; case UPDATE_STATUS.START_TARGET: // If no more updates were conducted set current cupdt.exe as starting point in registry Util.CreateAutostartEntry(TARGET_REGISTRY_NAME, Path.Combine(EXECUTABLE_DIRECTORY, TARGET_UPDT_NAME)); // Start current (which is the newest) target if (!StartNewTargetProc(EXECUTABLE_DIRECTORY)) { Util.PrintInformation(Configuration.InformationStrings.NONE, "Could not start new target", Util.PrintMode.ERROR, exit); updateTimer *= COOL_DOWN_FACTOR; break; } Util.PrintInformation(Configuration.InformationStrings.NONE, "Successfully started new target version", Util.PrintMode.NORMAL, false); break; case UPDATE_STATUS.KILLSWITCH: if (!Util.RemoveAutostartEntry(TARGET_REGISTRY_NAME, Path.Combine(EXECUTABLE_DIRECTORY, TARGET_UPDT_NAME))) { Util.PrintInformation(Configuration.InformationStrings.NONE, "Target killswitch did not succeed", Util.PrintMode.ERROR, false); } Util.KillswitchEngage(); break; // Some unknown error occurred and we immediately leave the update application default: Util.PrintInformation(Configuration.InformationStrings.NONE, "Unknown error occurred", Util.PrintMode.ERROR, true); break; } // Wait until updateTimer was completed (usually an hour) Thread.Sleep(updateTimer); } }