/// <summary> /// Performs a 'Factory Reset' on the test server. /// </summary> public void FactoryReset() { Common.Log($"Factory reset executing on '{_address}'"); IISCommand("Stop"); DeleteEnvironmentVariable("COR_ENABLE_PROFILING"); var configPath = @"C:\\ProgramData\\New Relic\\.NET Agent\\newrelic.config"; if (FileOperations.FileOrDirectoryExists(_mgmtScope, configPath)) { FileOperations.DeleteFileOrDirectory(_mgmtScope, configPath); } var source = $@"{TestContext.CurrentContext.TestDirectory}\\..\\..\\default_newrelic.config"; var destination = $@"{_dataPath}\\newrelic.config"; FileOperations.CopyFile(source, destination); PurgeAgentLogs(); ModifyOrCreateXmlAttribute("//x:service", "host", "staging-collector.newrelic.com", _configPath); ModifyOrCreateXmlAttribute("//x:service", "licenseKey", Settings.LicenseKey, _configPath); ModifyOrCreateXmlAttribute("//x:configuration/x:log", "level", "debug", _configPath); ModifyOrCreateXmlAttribute("//x:configuration/x:log", "auditLog", "true", _configPath); IISCommand("Start"); EventLog_Clear("Application"); }
private static Task <bool> UploadToStore(string SID) { return(Task.Run(async() => { Logger.Information("Uploading user state to the Store..."); string Destination = Path.Combine(Config.Settings["MigrationStorePath"], Guid.NewGuid().ToString()); try { Directory.CreateDirectory(Destination); File.WriteAllText(Path.Combine(Destination, "sid"), SID); File.WriteAllText(Path.Combine(Destination, "source"), await Misc.GetHostNameFromHost(CurrentTarget)); File.WriteAllText(Path.Combine(Destination, "ntaccount"), Misc.GetUserByIdentity(SID)); File.WriteAllText(Path.Combine(Destination, "importedon"), DateTime.Now.ToFileTime().ToString()); File.WriteAllText(Path.Combine(Destination, "importedby"), Environment.UserDomainName + "\\" + Environment.UserName); FileOperations.CopyFile( Path.Combine(Path.Combine(PayloadPathTarget, @"USMT\USMT.MIG")), Path.Combine(Destination, "data") ); Logger.Success("User state successfully uploaded."); return true; } catch (Exception e) { if (Directory.Exists(Destination)) { Directory.Delete(Destination, true); } Logger.Exception(e, "Failed to upload user state to the Store."); return false; } })); }
private void RestoreFilesFromBackup(String backup, bool recurse = false) { Log.Info("copy game files from backup " + backup); Log.Detail("save game path to restore is '" + pathSaveGame + "'"); // DeleteSaveGameFiles(); // // create save game Folder if not existent if (!FileOperations.DirectoryExists(pathSaveGame)) { Log.Info("creating save game folder " + pathSaveGame); FileOperations.CreateDirectoryRetry(pathSaveGame); } // foreach (String file in FileOperations.GetFiles(backup)) { try { String name = FileOperations.GetFileName(file); Log.Detail("restoring file " + name + " from " + file); if (!name.Equals(OK_FILE) && !name.Equals(RESTORED_FILE)) { Log.Info("copy file " + name); FileOperations.CopyFile(file, pathSaveGame + "/" + name); } } catch (Exception e) { Log.Exception(e); Log.Error("failed to copy file '" + file + "'"); throw e; } } // copy recurse? if (recurse) { Log.Info("recurse restore"); foreach (String folder in FileOperations.GetDirectories(backup)) { String name = FileOperations.GetFileName(folder); String target = pathSaveGame + "/" + name; FileOperations.CopyDirectory(folder, target); } } }
private static Task <bool> DownloadFromStore(string ID) { return(Task.Run(() => { Logger.Information("Downloading user state to: " + Main.DestinationComputer + "..."); string Destination = Path.Combine(PayloadPathTarget, "USMT"); try { Directory.CreateDirectory(Destination); FileOperations.CopyFile( Path.Combine(Config.Settings["MigrationStorePath"], ID, "data"), Path.Combine(Destination, "USMT.MIG") ); Logger.Success("User state successfully transferred."); return true; } catch (Exception e) { Logger.Exception(e, "Failed to download state data to: " + Main.DestinationComputer + "."); return false; } })); }
public String CreateBackup(bool preRestore = false) { String backupRootFolder = SAVE.configuration.backupPath + "/" + name; Log.Info("creating backup of save game '" + name + "' in '" + backupRootFolder + "'"); if (!FileOperations.DirectoryExists(backupRootFolder)) { Log.Info("creating root backup folder " + backupRootFolder); FileOperations.CreateDirectory(backupRootFolder); } // files to backup String[] gameFiles = FileOperations.GetFiles(pathSaveGame); if (gameFiles == null | gameFiles.Length == 0) { Log.Info("no files to backup for backup set " + name); status = STATUS.NONE; return(null); } DateTime time = DateTime.Now; String timestamp = time.Hour.ToString("00") + time.Minute.ToString("00") + time.Second.ToString("00"); String datestamp = time.Year.ToString("0000") + time.Month.ToString("00") + time.Day.ToString("00"); String backupFolder = backupRootFolder + "/" + datestamp + "-" + timestamp; String backupName = FileOperations.GetFileName(backupFolder); if (!FileOperations.DirectoryExists(backupFolder)) { FileOperations.CreateDirectory(backupFolder); if (preRestore) { FileOperations.CreateFile(backupFolder + "/" + RESTORED_FILE); } } else { Log.Warning("backup folder '" + backupFolder + "' already existing"); return(backupFolder); } // backup files foreach (String sourceFile in gameFiles) { Log.Info("creating backup of file " + sourceFile); // do not copy the restore marker if (sourceFile.Equals(RESTORED_FILE)) { continue; } String filename = FileOperations.GetFileName(sourceFile); try { FileOperations.CopyFile(sourceFile, backupFolder + "/" + filename); } catch (Exception e) { Log.Exception(e); Log.Error("failed to create backup of file " + sourceFile + " in " + backupFolder + ": " + e.Message); status = STATUS.FAILED; return(backupFolder); } } // backup subfolders if enabled if (SAVE.configuration.recurseBackup) { foreach (String sourceFolder in FileOperations.GetDirectories(pathSaveGame)) { Log.Info("creating backup of folder " + sourceFolder); String foldername = FileOperations.GetFileName(sourceFolder); try { FileOperations.CopyDirectory(sourceFolder, backupFolder + "/" + foldername); } catch (Exception e) { Log.Exception(e); Log.Error("failed to create backup of folder " + sourceFolder + " in " + backupFolder + ": " + e.Message); status = STATUS.FAILED; return(backupFolder); } } } try { FileOperations.CreateFile(backupFolder + "/" + OK_FILE); status = STATUS.OK; this.time = time; backups.Add(backupName); SortBackupsByName(); CreateBackupArray(); // compress backup if enabled if (SAVE.configuration.compressBackups) { CompressBackup(backupFolder); } else { Log.Detail("backup compression disabled"); } Log.Info("backup successful in " + backupFolder); } catch { Log.Error("failed to finish backup in " + backupFolder); status = STATUS.FAILED; return(backupFolder); } return(backupFolder); }
public static void DragDropTarget(RollingStoneFile stone, DragEventArgs e, bool existingStone) { //Warning !!! //The order of the format check is very important if (e.Data.GetDataPresent(DataFormats.FileDrop) || e.Data.GetDataPresent(ShellClipboardFormats.CFSTR_FILENAMEA) || e.Data.GetDataPresent(ShellClipboardFormats.CFSTR_FILENAMEW)) #region FileDrop { string[] strArray = (string[])e.Data.GetData(DataFormats.FileDrop); if (strArray == null) { return; } if (strArray.Length < 1) { return; } string str2 = FileOperations.RemoveURI(strArray[0]); if (((e.KeyState & 4) == 4) && existingStone) { if (stone.TargetName != null) { string execName = FileOperations.StripFileName(str2); string fullName = FileOperations.StripFileName(stone.TargetName); stone.programName = fullName; if (stone.TargetName.Contains("##")) { stone.programName = stone.programName.Replace("##", execName); stone.PerformExecution(); return; } else { stone.dynamicParameters = "\"" + execName + "\""; stone.PerformDynamicExecution(); return; } } } else { string fileName = str2; string fullName; if (FileOperations.FileIsLink(fileName)) { fullName = Path.Combine(GlobalConfig.AppShortcuts, Path.GetFileName(fileName)); FileOperations.CopyFile(fileName, fullName); } else { fullName = fileName; } fullName = FileOperations.UnExpandPath(fullName); stone.UpdateTarget(fullName); } } #endregion else if (e.Data.GetDataPresent(ShellClipboardFormats.CFSTR_INETURLW)) #region InetW { try { string hyperLinkUrl = null; string hyperLinkText = null; hyperLinkUrl = e.Data.GetData(typeof(string)) as string; System.IO.Stream ioStream = (System.IO.Stream)e.Data.GetData("FileGroupDescriptorW"); byte[] contents = new Byte[512]; ioStream.Read(contents, 0, 512); ioStream.Close(); hyperLinkText = Encoding.Unicode.GetString(contents, 76, 436).Trim(new char[1] { '\0' }); if (!string.IsNullOrEmpty(hyperLinkText)) { if (hyperLinkText.Length >= 4) { if (hyperLinkText.Substring(hyperLinkText.Length - 4, 4).ToLower().Equals(".url")) { hyperLinkText = hyperLinkText.Substring(0, hyperLinkText.Length - 4); if (!string.IsNullOrEmpty(hyperLinkText)) { hyperLinkText = hyperLinkText.Trim(new char[1] { '\0' }); } } } } if (!FileOperations.IsURL(hyperLinkUrl)) { hyperLinkUrl = FileOperations.RemoveURI(hyperLinkUrl); } if (!string.IsNullOrEmpty(hyperLinkText)) { stone.UpdateTargetURL(hyperLinkUrl, hyperLinkText); } else { stone.UpdateTarget(hyperLinkUrl); } stone.TargetParameters = null; } catch (UnauthorizedAccessException) { } } #endregion else if (e.Data.GetDataPresent(ShellClipboardFormats.CFSTR_SHELLURL)) #region Inet Ansi { try { string hyperLinkUrl = null; hyperLinkUrl = e.Data.GetData(typeof(string)) as string; if (!FileOperations.IsURL(hyperLinkUrl)) { hyperLinkUrl = FileOperations.RemoveURI(hyperLinkUrl); } stone.UpdateTarget(hyperLinkUrl); stone.TargetParameters = null; } catch (UnauthorizedAccessException) { } } #endregion else if (e.Data.GetDataPresent(ShellClipboardFormats.CFSTR_SHELLIDLIST)) #region Shell { try { // Copy clipboard data into unmanaged memory. MemoryStream data = (MemoryStream)e.Data.GetData(ShellClipboardFormats.CFSTR_SHELLIDLIST); byte[] b = data.ToArray(); IntPtr p = Marshal.AllocHGlobal(b.Length); Marshal.Copy(b, 0, p, b.Length); // Get parent folder. int offset = sizeof(UInt32); IntPtr parentpidl = (IntPtr)((int)p + (UInt32)Marshal.ReadInt32(p, offset)); offset = sizeof(UInt32) * 2; IntPtr myPidl = (IntPtr)((int)p + (UInt32)Marshal.ReadInt32(p, offset)); IntPtr full = NativeMethods.ILCombine(parentpidl, myPidl); string linkName = FileOperations.FileNameFromPidl(full); string linkFile = null; if (!string.IsNullOrEmpty(linkName)) { linkFile = Path.Combine(GlobalConfig.AppShortcuts, linkName + ".lnk"); NativeMethods.CreateShellLink(full, linkFile); linkFile = FileOperations.UnExpandPath(linkFile); stone.UpdateTarget(linkFile); stone.TargetParameters = null; } NativeMethods.ILFree(full); Marshal.FreeHGlobal(p); } catch { } } #endregion else if (e.Data.GetDataPresent(DataFormats.Text)) #region Text { string str2 = (string)e.Data.GetData(DataFormats.Text); if ((stone.TargetName != null) && existingStone) { string execName = str2; string fullName = FileOperations.StripFileName(stone.TargetName); stone.programName = fullName; if (stone.TargetName.Contains("##")) { stone.programName = stone.programName.Replace("##", execName); stone.PerformExecution(); return; } else { stone.dynamicParameters = execName; stone.PerformDynamicExecution(); return; } } } #endregion }
internal void InstallKrentoPart(string fileName) { string destination = null; bool compressed = false; bool loadNewToy = false; bool loadNewDocklet = false; bool reloadStones = false; string mainFolderName = null; string ext = Path.GetExtension(fileName); if (TextHelper.SameText(ext, ".toy")) { destination = GlobalConfig.ToysFolder; compressed = true; loadNewToy = true; } else if (TextHelper.SameText(ext, ".kmenu")) { destination = GlobalConfig.MenusFolder; compressed = true; } else if (TextHelper.SameText(ext, ".kskin")) { destination = GlobalConfig.SkinsFolder; compressed = true; } else if (TextHelper.SameText(ext, ".stone")) { destination = GlobalConfig.StoneClasses; compressed = true; reloadStones = true; } else if (TextHelper.SameText(ext, ".lng")) { destination = GlobalConfig.LanguagesFolder; compressed = false; } else if (TextHelper.SameText(ext, ".kadd")) { destination = GlobalConfig.AddInRootFolder; compressed = true; } else if (TextHelper.SameText(ext, ".docklet")) { destination = GlobalConfig.DockletsFolder; compressed = true; loadNewDocklet = true; } else if (TextHelper.SameText(ext, ".circle")) { destination = GlobalConfig.RollingStonesFolder; compressed = false; } if (string.IsNullOrEmpty(destination)) { return; } if (!compressed) { string destinationName = Path.Combine(destination, Path.GetFileName(fileName)); try { FileOperations.CopyFile(fileName, destinationName); if (TextHelper.SameText(destination, GlobalConfig.RollingStonesFolder)) { if (FileOperations.FileExists(destinationName)) { Manager.HistoryAdd(destinationName); } } } catch (Exception ex) { TraceDebug.Trace(ex); } } else { try { destination = Path.Combine(destination, Path.GetFileNameWithoutExtension(fileName)); if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } } catch (Exception ex) { TraceDebug.Trace(ex); } NativeMethods.ExtractArchive(fileName, destination); FileOperations.CopyFile(fileName, Path.Combine(GlobalConfig.DownloadsFolder, Path.GetFileName(fileName))); if (reloadStones) { try { string newStonePath; if (!string.IsNullOrEmpty(mainFolderName)) { newStonePath = Path.Combine(destination, mainFolderName); } else { newStonePath = destination; } Language.Merge(Path.Combine(newStonePath, GlobalSettings.Language + ".lng")); } catch (Exception ex) { //Toy load error happens TraceDebug.Trace(ex); } //Loading of the new stone must be AFTER merging of the language Manager.LoadStoneClasses(); } else if (loadNewToy) { try { string newToyPath; if (!string.IsNullOrEmpty(mainFolderName)) { newToyPath = Path.Combine(destination, mainFolderName); } else { newToyPath = destination; } context.LoadKrentoToys(newToyPath); } catch (Exception ex) { //Toy load error happens TraceDebug.Trace(ex); } } else if (loadNewDocklet) { try { string newDockletPath; if (!string.IsNullOrEmpty(mainFolderName)) { newDockletPath = Path.Combine(destination, mainFolderName); } else { newDockletPath = destination; } context.LoadKrentoDocklets(newDockletPath); } catch (Exception ex) { //Toy load error happens TraceDebug.Trace(ex); } } } }
internal static void InstallKrentoPart(string fileName) { string destination = null; bool compressed = false; string ext = Path.GetExtension(fileName); if (TextHelper.SameText(ext, ".toy")) { destination = GlobalConfig.ToysFolder; compressed = true; } else if (TextHelper.SameText(ext, ".kmenu")) { destination = GlobalConfig.MenusFolder; compressed = true; } else if (TextHelper.SameText(ext, ".kskin")) { destination = GlobalConfig.SkinsFolder; compressed = true; } else if (TextHelper.SameText(ext, ".stone")) { destination = GlobalConfig.StoneClasses; compressed = true; } else if (TextHelper.SameText(ext, ".lng")) { destination = GlobalConfig.LanguagesFolder; compressed = false; } else if (TextHelper.SameText(ext, ".kadd")) { destination = GlobalConfig.AddInRootFolder; compressed = true; } else if (TextHelper.SameText(ext, ".docklet")) { destination = GlobalConfig.DockletsFolder; compressed = true; } else if (TextHelper.SameText(ext, ".circle")) { destination = GlobalConfig.RollingStonesFolder; compressed = false; } if (string.IsNullOrEmpty(destination)) { return; } if (!compressed) { string destinationName = Path.Combine(destination, Path.GetFileName(fileName)); try { FileOperations.CopyFile(fileName, destinationName); } catch { //continue... } } else { try { FileOperations.CopyFile(fileName, Path.Combine(GlobalConfig.DownloadsFolder, Path.GetFileName(fileName))); destination = Path.Combine(destination, Path.GetFileNameWithoutExtension(fileName)); ExtractArchive(fileName, destination); } catch { //continue... } } }