/// <summary>Returns a non-null string filename of the Client in the tempbase if the Running Client will be overwritten by the Temp Client</summary> static string ClientInTempBase(string actualBase, string tempBase) { //relative path from origFolder to client location StringBuilder strBuild = new StringBuilder(SystemFolders.MAX_PATH); string tempStr = VersionTools.SelfLocation; //find the relativity of the actualBase and this running client bool bRet = SystemFolders.PathRelativePathTo( strBuild, actualBase, SystemFolders.FILE_ATTRIBUTE_DIRECTORY, tempStr, SystemFolders.FILE_ATTRIBUTE_FILE ); if (bRet && strBuild.Length >= 2) { //get the first two characters tempStr = strBuild.ToString().Substring(0, 2); if (tempStr == @".\") //if client is in the destPath { tempStr = Path.Combine(tempBase, strBuild.ToString()); if (File.Exists(tempStr)) { return(tempStr); } } } return(null); }
protected override bool IsValid(PropertyValidatorContext context) { var folder = context.PropertyValue.ToString(); foreach (var systemFolder in SystemFolders.GetSystemFolders()) { context.MessageFormatter.AppendArgument("systemFolder", systemFolder); if (systemFolder.PathEquals(folder)) { context.MessageFormatter.AppendArgument("relationship", "set to"); return(false); } if (systemFolder.IsParentPath(folder)) { context.MessageFormatter.AppendArgument("relationship", "child of"); return(false); } } return(true); }
//TODO: Expand this function to allow for artificially elevated limited users. // For example, a limited user given the permission to write to HKLM // (something that is normally forbidden). bool OnlyUpdatingLocalUser() { // if installing // - system folders // - non-user registry // - Windows Services // - COM files // then return false // Also note how we're excluding the "BaseDir". // This is because the base directory may or may not be in the userprofile // directory (or otherwise writable by the user), thus it needs a separate check. // Ditto for the "client.wyc" file. if (((updateFrom.InstallingTo | InstallingTo.BaseDir) ^ InstallingTo.BaseDir) != 0) { return(false); } string userProfileFolder = SystemFolders.GetUserProfile(); // if the basedir isn't in the userprofile folder (C:\Users\UserName) // OR // if the folder isn't in the full control of the current user // THEN // we're not "only updating the local user if ((updateFrom.InstallingTo & InstallingTo.BaseDir) != 0 && !(SystemFolders.IsDirInDir(userProfileFolder, baseDirectory) || HaveFolderPermissions(baseDirectory))) { return(false); } return(true); }
/// <summary>Convert the relative path name to the absolute path name on disk.</summary> /// <param name="relPath">The relative path to the file (using wyBuild lingo).</param> /// <returns>The absolute path name.</returns> string FixUpdateDetailsPaths(string relPath) { if (relPath.Length < 4) { return(null); } switch (relPath.Substring(0, 4)) { case "base": return(Path.Combine(ProgramDirectory, relPath.Substring(5))); case "syst": //system (32-bit) return(Path.Combine(SystemFolders.GetSystem32x86(), relPath.Substring(7))); case "64sy": //64system (64-bit) return(Path.Combine(SystemFolders.GetSystem32x64(), relPath.Substring(9))); case "temp": return(Path.Combine(TempDirectory, relPath)); case "appd": //appdata return(Path.Combine(SystemFolders.GetCurrentUserAppData(), relPath.Substring(8))); case "lapp": //lappdata return(Path.Combine(SystemFolders.GetCurrentUserLocalAppData(), relPath.Substring(9))); case "coma": //comappdata return(Path.Combine(SystemFolders.GetCommonAppData(), relPath.Substring(11))); case "comd": //comdesktop return(Path.Combine(SystemFolders.GetCommonDesktop(), relPath.Substring(11))); case "coms": //comstartmenu return(Path.Combine(SystemFolders.GetCommonProgramsStartMenu(), relPath.Substring(13))); case "root": //root windows (e.g. C:\) return(Path.Combine(SystemFolders.GetRootDrive(), relPath.Substring(5))); case "cp86": //cp86 == common program files (x86) return(Path.Combine(SystemFolders.GetCommonProgramFilesx86(), relPath.Substring(5))); case "cp64": //cp64 == common program files (x64) return(Path.Combine(SystemFolders.GetCommonProgramFilesx64(), relPath.Substring(5))); case "curd": // curdesk = current user's desktop return(Path.Combine(SystemFolders.GetCurrentUserDesktop(), relPath.Substring(8))); case "curs": // curstart = current user's start menu return(Path.Combine(SystemFolders.GetCurrentUserProgramsStartMenu(), relPath.Substring(9))); } return(null); }
//TODO: Expand this function to allow for artificially elevated limited users. // For example, a limited user given the permission to write to HKLM // (something that is normally forbidden). bool OnlyUpdatingLocalUser() { // if installing // - system folders // - non-user registry // - Windows Services // - COM files // then return false // Also note how we're excluding the "BaseDir". // This is because the base directory may or may not be in the userprofile // directory (or otherwise writable by the user), thus it needs a separate check. // Ditto for the "client.wyc" file. if (((updateFrom.InstallingTo | InstallingTo.BaseDir) ^ InstallingTo.BaseDir) != 0) { return(false); } string userProfileFolder = SystemFolders.GetUserProfile(); // if the basedir isn't in the userprofile folder (C:\Users\UserName) // OR // if the folder isn't in the full control of the current user // THEN // we're not "only updating the local user if ((updateFrom.InstallingTo & InstallingTo.BaseDir) != 0 && !(SystemFolders.IsDirInDir(userProfileFolder, baseDirectory) || HaveFolderPermissions(baseDirectory))) { return(false); } // if the client data file isn't in the userprofile folder (or otherwise writable) // then bail out. if (!(SystemFolders.IsFileInDirectory(userProfileFolder, clientFileLoc) || HaveFolderPermissions(Path.GetDirectoryName(clientFileLoc)))) { return(false); } // when self-updating, if this client isn't in the userprofile folder if ((SelfUpdateState == SelfUpdateState.WillUpdate || SelfUpdateState == SelfUpdateState.FullUpdate || SelfUpdateState == SelfUpdateState.Extracted) && !(SystemFolders.IsFileInDirectory(userProfileFolder, VersionTools.SelfLocation) || HaveFolderPermissions(Path.GetDirectoryName(VersionTools.SelfLocation)))) { return(false); } return(true); }
public override ValidationResult Test() { var failures = new List <ValidationFailure>(); if (!_diskProvider.FileExists(Settings.Path)) { failures.Add(new NzbDroneValidationFailure("Path", "File does not exist")); } foreach (var systemFolder in SystemFolders.GetSystemFolders()) { if (systemFolder.IsParentPath(Settings.Path)) { failures.Add(new NzbDroneValidationFailure("Path", $"Must not be a descendant of '{systemFolder}'")); } } if (failures.Empty()) { try { var environmentVariables = new StringDictionary(); environmentVariables.Add("Sonarr_EventType", "Test"); var processOutput = ExecuteScript(environmentVariables); if (processOutput.ExitCode != 0) { failures.Add(new NzbDroneValidationFailure(string.Empty, $"Script exited with code: {processOutput.ExitCode}")); } } catch (Exception ex) { _logger.Error(ex); failures.Add(new NzbDroneValidationFailure(string.Empty, ex.Message)); } } return(new ValidationResult(failures)); }
/// <summary>Gets or creates the cache folder for a GUID.</summary> /// <param name="guid">The GUID.</param> /// <returns>The directory to the cache folder</returns> static string GetCacheFolder(string guid) { string userprofile = SystemFolders.GetUserProfile(); // if getting the userprofile folder fails, then try the app data folder if (string.IsNullOrEmpty(userprofile)) { userprofile = SystemFolders.GetCurrentUserAppData(); } if (string.IsNullOrEmpty(userprofile)) { throw new Exception("Failed to retrieve the user profile folder."); } // C:\Users\USERNAME\wc string temp = Path.Combine(userprofile, "wc"); // if the folder temp folder doesn't exist, create the folder with hidden attributes if (!Directory.Exists(temp)) { Directory.CreateDirectory(temp); File.SetAttributes(temp, FileAttributes.System | FileAttributes.Hidden); } string fullGuidFolder = Path.Combine(temp, guid); // Workaround for the "pyramid of death" bug. // Note: This still doesn't address the root cause of the "pyramid of death" // namely, why aren't the folders being cleaned up on the failure of wyUpdate? // Perhaps it's a crashing bug. Further investigation is needed. We need to look into // possible causes for cached files being left around. This problem was first spotted // when a user's app crashed when they were debugging. It was crashing over and over again if (Directory.Exists(fullGuidFolder)) { string guidFile = Path.Combine(fullGuidFolder, guid); // if the GUID file doesn't already exist then the cache is busted. if (!File.Exists(guidFile)) { // delete every file and folder in the directory because it's an invalid cache string[] obs = Directory.GetDirectories(fullGuidFolder); // remove all directories foreach (var dir in obs) { Directory.Delete(dir, true); } obs = Directory.GetFiles(fullGuidFolder); // remove all the files foreach (var file in obs) { File.Delete(file); } // create the blank GUID file using (File.Create(guidFile)); } return(fullGuidFolder); } // try to create the smallest possible folder name (using the GUID) string closestMatch = null; string[] dirs = Directory.GetDirectories(temp); // loop through the directories - stop at the first partial match this GUID for (int i = 0; i < dirs.Length; i++) { string name = Path.GetFileName(dirs[i]); if (string.IsNullOrEmpty(name) || guid.IndexOf(name) != 0) { continue; } // see if the partial-matching folder contains an empty GUID file if (File.Exists(Path.Combine(dirs[i], guid))) { return(dirs[i]); } closestMatch = name; } // the folder doesn't exist, so we'll create it string guidCacheFolder = Path.Combine(temp, guid.Substring(0, closestMatch == null ? 1 : closestMatch.Length + 1)); Directory.CreateDirectory(guidCacheFolder); // create the blank GUID file using (File.Create(Path.Combine(guidCacheFolder, guid))); return(guidCacheFolder); }
void bw_DoWorkUpdateFiles(object sender, DoWorkEventArgs e) { //check if folders exist, and count files to be moved string backupFolder = Path.Combine(TempDirectory, "backup"); string[] backupFolders = new string[13]; //Note: InstallShortcuts() requires the position in array to remain constant string[] origFolders = { "base", "system", "64system", "root", "appdata", "lappdata", "comappdata", "comdesktop", "comstartmenu", "cp86", "cp64", "curdesk", "curstart" }; string[] destFolders = { ProgramDirectory, SystemFolders.GetSystem32x86(), SystemFolders.GetSystem32x64(), SystemFolders.GetRootDrive(), SystemFolders.GetCurrentUserAppData(), SystemFolders.GetCurrentUserLocalAppData(), SystemFolders.GetCommonAppData(), SystemFolders.GetCommonDesktop(), SystemFolders.GetCommonProgramsStartMenu(), SystemFolders.GetCommonProgramFilesx86(), SystemFolders.GetCommonProgramFilesx64(), SystemFolders.GetCurrentUserDesktop(), SystemFolders.GetCurrentUserProgramsStartMenu() }; List <FileFolder> rollbackList = new List <FileFolder>(); int totalDone = 0; Exception except = null; try { int totalFiles = 0; // count the files and create backup folders for (int i = 0; i < origFolders.Length; i++) { // does orig folder exist? if (!Directory.Exists(Path.Combine(TempDirectory, origFolders[i]))) { continue; } //orig folder exists, set backup & orig folder locations backupFolders[i] = Path.Combine(backupFolder, origFolders[i]); origFolders[i] = Path.Combine(TempDirectory, origFolders[i]); Directory.CreateDirectory(backupFolders[i]); // delete "newer" client, if it will overwrite this client DeleteClientInPath(destFolders[i], origFolders[i]); // count the total files totalFiles += new DirectoryInfo(origFolders[i]).GetFiles("*", SearchOption.AllDirectories).Length; } //run the backup & replace for (int i = 0; i < origFolders.Length; i++) { if (IsCancelled()) { break; } if (backupFolders[i] != null) //if the backup folder exists { UpdateFiles(origFolders[i], destFolders[i], backupFolders[i], rollbackList, ref totalDone, ref totalFiles); } } DeleteFiles(backupFolder, rollbackList); InstallShortcuts(destFolders, backupFolder, rollbackList); } catch (Exception ex) { except = ex; } // write the list of newly created files and folders RollbackUpdate.WriteRollbackFiles(Path.Combine(backupFolder, "fileList.bak"), rollbackList); if (IsCancelled() || except != null) { // rollback files bw.ReportProgress(1, false); RollbackUpdate.RollbackFiles(TempDirectory, ProgramDirectory); // rollback unregged COM RollbackUpdate.RollbackUnregedCOM(TempDirectory); // rollback stopped services RollbackUpdate.RollbackStoppedServices(TempDirectory); bw.ReportProgress(0, new object[] { -1, -1, string.Empty, ProgressStatus.Failure, except }); } else { // backup & replace was successful bw.ReportProgress(0, new object[] { -1, -1, string.Empty, ProgressStatus.Success, null }); } }
public static void RollbackFiles(string m_TempDirectory, string m_ProgramDirectory) { string backupFolder = Path.Combine(m_TempDirectory, "backup"); // read in the list of files to delete List <string> fileList = new List <string>(), foldersToDelete = new List <string>(), foldersToCreate = new List <string>(); try { ReadRollbackFiles(Path.Combine(backupFolder, "fileList.bak"), fileList, foldersToDelete, foldersToCreate); } catch { return; } //delete the files foreach (string file in fileList) { try { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } catch { } } //delete the folders foreach (string folder in foldersToDelete) { //TODO: test rolling back read-only / hidden folders try { Directory.Delete(folder, true); } catch { } } //create the folders foreach (string folder in foldersToCreate) { try { Directory.CreateDirectory(folder); } catch { } } //restore old versions string[] backupFolders = { Path.Combine(backupFolder, "base"), Path.Combine(backupFolder, "system"), Path.Combine(backupFolder, "64system"), Path.Combine(backupFolder, "root"), Path.Combine(backupFolder, "appdata"), Path.Combine(backupFolder, "lappdata"), Path.Combine(backupFolder, "comappdata"), Path.Combine(backupFolder, "comdesktop"), Path.Combine(backupFolder, "comstartmenu"), Path.Combine(backupFolder, "cp86"), Path.Combine(backupFolder, "cp64"), Path.Combine(backupFolder, "curdesk"), Path.Combine(backupFolder, "curstart") }; string[] destFolders = { m_ProgramDirectory, SystemFolders.GetSystem32x86(), SystemFolders.GetSystem32x64(), SystemFolders.GetRootDrive(), SystemFolders.GetCurrentUserAppData(), SystemFolders.GetCurrentUserLocalAppData(), SystemFolders.GetCommonAppData(), SystemFolders.GetCommonDesktop(), SystemFolders.GetCommonProgramsStartMenu(), SystemFolders.GetCommonProgramFilesx86(), SystemFolders.GetCommonProgramFilesx64(), SystemFolders.GetCurrentUserDesktop(), SystemFolders.GetCurrentUserProgramsStartMenu() }; for (int i = 0; i < backupFolders.Length; i++) { // only backup if the back-folder & dest-folder exists (i.e. the 64-bit system32 folder) if (Directory.Exists(backupFolders[i]) && destFolders[i] != null) { RestoreFiles(destFolders[i], backupFolders[i]); } } }
//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 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; } }
/// <summary> /// Gets the path to a system folder /// </summary> /// <param name="Folder"></param> /// <returns></returns> public string GetDeviceSystemFolderPath(SystemFolders Folder) { CheckConnection(); StringBuilder path = new StringBuilder(260); if(! Convert.ToBoolean(CeGetSpecialFolderPath((int)Folder, 260, path))) { throw new RAPIException("Cannot get folder path!"); } return path.ToString(); }
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 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; } }
public static void RollbackFiles(string m_TempDirectory, string m_ProgramDirectory) { string path = Path.Combine(m_TempDirectory, "backup"); List <string> list = new List <string>(); List <string> list2 = new List <string>(); List <string> list3 = new List <string>(); try { ReadRollbackFiles(Path.Combine(path, "fileList.bak"), list, list2, list3); } catch { return; } foreach (string item in list) { try { File.SetAttributes(item, FileAttributes.Normal); File.Delete(item); } catch { } } foreach (string item2 in list2) { try { Directory.Delete(item2, recursive: true); } catch { } } foreach (string item3 in list3) { try { Directory.CreateDirectory(item3); } catch { } } string[] array = new string[13] { Path.Combine(path, "base"), Path.Combine(path, "system"), Path.Combine(path, "64system"), Path.Combine(path, "root"), Path.Combine(path, "appdata"), Path.Combine(path, "lappdata"), Path.Combine(path, "comappdata"), Path.Combine(path, "comdesktop"), Path.Combine(path, "comstartmenu"), Path.Combine(path, "cp86"), Path.Combine(path, "cp64"), Path.Combine(path, "curdesk"), Path.Combine(path, "curstart") }; string[] array2 = new string[13] { m_ProgramDirectory, SystemFolders.GetSystem32x86(), SystemFolders.GetSystem32x64(), SystemFolders.GetRootDrive(), SystemFolders.GetCurrentUserAppData(), SystemFolders.GetCurrentUserLocalAppData(), SystemFolders.GetCommonAppData(), SystemFolders.GetCommonDesktop(), SystemFolders.GetCommonProgramsStartMenu(), SystemFolders.GetCommonProgramFilesx86(), SystemFolders.GetCommonProgramFilesx64(), SystemFolders.GetCurrentUserDesktop(), SystemFolders.GetCurrentUserProgramsStartMenu() }; for (int i = 0; i < array.Length; i++) { if (Directory.Exists(array[i]) && array2[i] != null) { RestoreFiles(array2[i], array[i]); } } }
//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); } } } } }