public static PatchingEnvironment FromExisting(string path) { var patchingEnvironment = new PatchingEnvironment(path); patchingEnvironment.Version = patchingEnvironment.ReadVersion() ?? DefaultVersion; return patchingEnvironment; }
public static PatchingEnvironment Create(PatchingEnvironment baseEnvironment) { string newApplicationRoot = FileSystem.GetTempDirectory(); Computer.FileSystem.CopyDirectory(baseEnvironment.ApplicationRoot, newApplicationRoot); return FromExisting(newApplicationRoot); }
private void CreateNewPatchingEnvironment() { this.patchingEnvironment = PatchingEnvironment.Create(PatchingEnvironment.GetCurrent()); }
public void ReplaceWith(PatchingEnvironment other) { // TODO Sanity checks, etc. string source = other.ApplicationRoot; string destination = ApplicationRoot; // Rename the destination, // move source to (old) destination, // delete renamed destination string tempRoot = Path.Combine(Path.GetDirectoryName(destination), string.Format("NoCap-{0}", Path.GetRandomFileName())); bool success; success = false; try { MoveDirectory(destination, tempRoot); success = true; } finally { if (!success) { if (Directory.Exists(tempRoot)) { MoveDirectory(tempRoot, destination); } } } success = false; try { MoveDirectory(source, destination); success = true; } finally { if (!success) { if (Directory.Exists(destination)) { Directory.Delete(destination, true); } MoveDirectory(tempRoot, destination); } } Directory.Delete(tempRoot, true); }