public static void PatchFolder(string folder, string patchFile, string folderManifestVersion) { Console.WriteLine($"Patching Folder {patchFile} => {folder}"); using (ZipArchive zip1 = ZipFile.OpenRead(patchFile)) { for (int i = 0; i < zip1.Entries.Count; i++) { Console.WriteLine($"Patching File {zip1.Entries[i].FullName}"); zip1.Entries[i].ExtractToFile(folder + "/" + zip1.Entries[i].FullName, true); // here, we extract every entry, but we could extract conditionally // based on entry name, size, date, checkbox status, etc. } } IPackageManifest pm = ReadManifest(patchFile); if (pm != null) //New Package File included { if (_packageVersions[pm.PackageVersion].ManifestPath != _packageVersions[folderManifestVersion].ManifestPath) { string oldFile = Path.Combine(folder, _packageVersions[folderManifestVersion].ManifestPath); File.Delete(oldFile); } } }
/// <summary> /// Initializes a new instance of the <see cref="Package"/> class. /// </summary> /// <param name="directoryInfo">The <see cref="DirectoryInfo"/> instance of the directory in which the Package resides.</param> /// <param name="manifest">The manifest contained within the archive.</param> public Package(DirectoryInfo directoryInfo, IPackageManifest manifest) { DirectoryInfo = directoryInfo; Manifest = manifest; Files = DirectoryInfo.EnumerateFiles("*", SearchOption.AllDirectories).Select(f => f.FullName).ToList(); }
/// <summary> /// Updates the specified Package, replacing the existing Manifest with the specified Manifest. /// </summary> /// <param name="packageFile">The filename of the Package file to update.</param> /// <param name="manifest">The Manifest with which the Package file will be updated.</param> /// <param name="tempDirectory">The path to the temporary directory to use for file operations.</param> private void UpdatePackageManifest(string packageFile, IPackageManifest manifest, string tempDirectory) { Verbose($"Updating Manifest in Package '{Path.GetFileName(packageFile)}'..."); string tempPackageDirectory = Path.Combine(tempDirectory, "package"); string tempManifest = Path.Combine(tempPackageDirectory, PackagingConstants.ManifestFilename); string tempPackage = Path.Combine(tempDirectory, Path.GetFileName(packageFile)); Verbose($"Extracting Package to '{tempPackageDirectory}'..."); ZipFile.ExtractToDirectory(packageFile, tempPackageDirectory); Verbose("Package extracted successfully."); Verbose($"Replacing Manifest file..."); File.Delete(tempManifest); File.WriteAllText(tempManifest, manifest.ToJson()); Verbose("Manifest file replaced successfully."); Verbose($"Compressing Package..."); ZipFile.CreateFromDirectory(tempPackageDirectory, tempPackage); Verbose("Package compressed successfully."); Verbose($"Overwriting original Package..."); File.Copy(tempPackage, packageFile, true); Verbose("Package overwritten successfully."); }
public void ExtractManifest() { IPackageManifest manifest = Extractor.ExtractManifest(Path.Combine(DataDirectory, "Package", "package.zip")); Assert.NotNull(manifest); Assert.Equal("DefaultPlugin", manifest.Name); Assert.Equal(3, manifest.Files.Count); }
public void ExtractManifestToFile() { string inputFile = Path.Combine(DataDirectory, "Package", "package.zip"); string outputFile = Path.Combine(TempDirectory, "manifest.json"); IPackageManifest manifest = Extractor.ExtractManifest(inputFile, outputFile); Assert.True(File.Exists(outputFile)); }
/// <summary> /// Initializes a new instance of the <see cref="PackageManifestSummaryData"/> class with the specified <paramref name="packageManifest"/>. /// </summary> /// <param name="packageManifest">The <see cref="IPackageManifest"/> instance from which to copy values.</param> public PackageManifestSummaryData(IPackageManifest packageManifest) { this.CopyPropertyValuesFrom(packageManifest); if (packageManifest.Signature != default(PackageManifestSignature)) { Signature = new PackageManifestSummarySignatureData(packageManifest.Signature); } }
public static void PatchPackagePermanent(string mainFile, string patchFile) { Console.WriteLine($"Permanently Applying {patchFile} to {mainFile}"); string dirPath = UnpackForPatching(mainFile); IPackageManifest pm = ReadManifest(mainFile); PatchFolder(dirPath, Path.GetFullPath(patchFile), pm.PackageVersion); File.Delete(Path.GetFullPath(mainFile)); Console.WriteLine($"Repackaging {mainFile}"); ZipFile.CreateFromDirectory(dirPath, Path.GetFullPath(mainFile)); }
private static void ListInfo(string[] args) { if (args.Length == 0 || !File.Exists(args[0]) || !args[0].EndsWith(".game") && !args[0].EndsWith(".engine")) { System.Console.WriteLine("Could not find file"); return; } IPackageManifest pm = Creator.ReadManifest(args[0]); System.Console.WriteLine(pm); }
public void GenerateManifestWithChecksums() { File.WriteAllText(Path.Combine(TempDirectory, "index.html"), " "); File.WriteAllText(Path.Combine(TempDirectory, "binary.dll"), " "); File.WriteAllText(Path.Combine(TempDirectory, "resource.bmp"), " "); IPackageManifest manifest = Generator.GenerateManifest(TempDirectory, true); Assert.NotEmpty(manifest.Files); Assert.Equal(3, manifest.Files.Count); Assert.NotNull(manifest.Files.Select(f => f.Source == "index.html")); Assert.NotNull(manifest.Files.Select(f => f.Source == "binary.dll")); Assert.NotNull(manifest.Files.Select(f => f.Source == "resource.bmp")); Assert.True(manifest.Files.All(f => f.Checksum != null)); }
public void GenerateManifestWithUpdate() { Generator.Updated += Generator_Updated; File.WriteAllText(Path.Combine(TempDirectory, "index.html"), " "); File.WriteAllText(Path.Combine(TempDirectory, "binary.dll"), " "); File.WriteAllText(Path.Combine(TempDirectory, "resource.bmp"), " "); IPackageManifest manifest = Generator.GenerateManifest(TempDirectory); Assert.NotEmpty(manifest.Files); Assert.Equal(3, manifest.Files.Count); Assert.NotNull(manifest.Files.Select(f => f.Source == "index.html")); Assert.NotNull(manifest.Files.Select(f => f.Source == "binary.dll")); Assert.NotNull(manifest.Files.Select(f => f.Source == "resource.bmp")); }
private static void LoadGame(string gamePath, IPackageManifest pm) { //Load Game Creator.UnpackPackage(gamePath, EnginePlayerConsole.GameTempDir); string[] files = Directory.GetFiles(EnginePlayerConsole.GameTempDir, "*", SearchOption.AllDirectories); foreach (string file in files) { bool over = File.Exists(file.Replace(EnginePlayerConsole.GameTempDir, EnginePlayerConsole.GameDir)); CreateFolder(file.Replace(EnginePlayerConsole.GameTempDir, EnginePlayerConsole.GameDir)); File.Copy(file, file.Replace(EnginePlayerConsole.GameTempDir, EnginePlayerConsole.GameDir), over); } Directory.Delete(EnginePlayerConsole.GameTempDir, true); }
/// <summary> /// Compares the specified manifest to the contents of the specified directory and hashes any files that had been /// deferred for hashing in the manifest. /// </summary> /// <param name="manifest">The manifest for which validation and hash generation is to be performed.</param> /// <param name="directory">The directory containing payload files.</param> internal void ValidateManifestAndGenerateHashes(IPackageManifest manifest, string directory) { foreach (PackageManifestFile file in manifest.Files) { // determine the absolute path for the file we need to examine string fileToCheck = Path.Combine(directory, file.Source); if (!File.Exists(fileToCheck)) { throw new FileNotFoundException($"The file '{file.Source}' is listed in the manifest but is not found on disk."); } if (file.Checksum != default(string)) { file.Checksum = Common.Utility.ComputeFileSHA512Hash(fileToCheck); } } }
private static void AddEngine(string path) { try { IPackageManifest pm = Creator.ReadManifest(path); if (!EnginePlayerConsole.EngineVersions.Contains(pm.Version)) { Console.WriteLine("Adding Engine: " + pm); EnginePlayerConsole.EngineVersions.Add(pm.Version); File.Copy(path, EnginePlayerConsole.EngineDir + "/" + pm.Version + ".engine"); } } catch (Exception e) { Console.WriteLine("Could not add Engine to Player."); Console.WriteLine(e); throw; } }
public void CreateAndReadPackage() { Directory.CreateDirectory("content"); Directory.CreateDirectory("content/assets"); Random rnd = new Random(); byte[] buffer = new byte[1024 * 1024]; for (int i = 0; i < 100; i++) { rnd.NextBytes(buffer); File.WriteAllBytes("content/assets/" + i + ".blob", buffer); } File.WriteAllBytes("content/TestPackage.dll", buffer); File.WriteAllBytes("content/TestPackage.runtimeconfig.json", buffer); File.WriteAllBytes("content/TestPackage.deps.json", buffer); Directory.CreateDirectory("output"); Builder.RunCommand( "--create-package ./content TestPackage ./output/TestPackage.game False False --packager-version legacy --packer-override-engine-version 9.9.9.9"); Builder.RunCommand( "--create-package ./content TestPackage ./output/v1Test.game False False --packager-version v1 --packer-override-engine-version 9.9.9.9"); Builder.RunCommand( "--create-package ./content TestPackage ./output/v2Test.game False False --packager-version v2 --packer-override-engine-version 9.9.9.9"); IPackageManifest manifestL = Creator.ReadManifest("./output/TestPackage.game"); IPackageManifest manifestV1 = Creator.ReadManifest("./output/v1Test.game"); IPackageManifest manifestV2 = Creator.ReadManifest("./output/v2Test.game"); Assert.True(manifestL.PackageVersion == "legacy"); Assert.True(manifestV1.PackageVersion == "v1"); Assert.True(manifestV2.PackageVersion == "v2"); Assert.True(manifestV2.Version == manifestL.Version && manifestV2.Version == manifestV1.Version); Assert.True(manifestV2.Title == manifestL.Title && manifestV2.Title == manifestV1.Title); Assert.True(manifestV2.StartCommand == manifestL.StartCommand && manifestV2.StartCommand == manifestV1.StartCommand); Directory.Delete("content", true); Directory.Delete("output", true); }
public static void WriteManifest(Stream s, IPackageManifest o) { _packageVersions[o.PackageVersion].WriteManifest(s, o); }
public static void Run(string[] args) { if (args.Length == 0 || !args[0].EndsWith(".game") || !File.Exists(args[0])) { Console.WriteLine("Could not load Game File: " + (args.Length == 0 ? "" : Path.GetFullPath(args[0]))); return; } SetUpDirectoryStructure(); IPackageManifest pm = null; try { pm = Creator.ReadManifest(args[0]); Console.Title = pm.Title; string path = pm.Version; if (EnginePlayerConsole.EngineVersion != null) { path = EnginePlayerConsole.EngineVersion; } LoadEngine(path); //Load Game LoadGame(args[0], pm); } catch (Exception e) { Directory.Delete(EnginePlayerConsole.GameTempDir, true); Directory.Delete(EnginePlayerConsole.GameDir, true); Console.WriteLine("Error Unpacking File."); Console.WriteLine(e); } string startCommand = "-c \"" + pm.StartCommand + "\""; string cli = "/bin/bash"; if (Type.GetType("Mono.Runtime") == null) //Not Running Mono = Windows, Running Mono = Linux { startCommand = "/C " + pm.StartCommand; cli = "cmd.exe"; } _p = new Process(); ProcessStartInfo psi = new ProcessStartInfo { FileName = cli, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, Arguments = startCommand, WorkingDirectory = EnginePlayerConsole.GameDir }; _p.StartInfo = psi; _p.Start(); ConsoleRedirector crd = ConsoleRedirector.CreateRedirector(_p.StandardOutput, _p.StandardError, _p, Console.WriteLine); crd.StartThreads(); while (!_p.HasExited) { Thread.Sleep(150); } crd.StopThreads(); Console.WriteLine(crd.GetRemainingLogs()); Directory.Delete(EnginePlayerConsole.GameDir, true); }
public void WriteManifest(Stream s, IPackageManifest manifest) { XmlSerializer xs = new XmlSerializer(typeof(PackageManifest)); xs.Serialize(s, manifest); }
/// <summary> /// Initializes a new instance of the <see cref="PackageArchive"/> class. /// </summary> /// <param name="fileInfo">The <see cref="FileInfo"/> instance of the Archive file.</param> /// <param name="manifest">The manifest contained within the Archive.</param> public PackageArchive(FileInfo fileInfo, IPackageManifest manifest) { Manifest = manifest; FileInfo = fileInfo; }