private static void ListPackageFiles(string packagePath, Func <AbstractFileInfo, bool> filter = null) { try { using (var reader = new PackageReader(packagePath)) { Package package = reader.Read(); List <AbstractFileInfo> files = package.Files; if (filter != null) { files = files.FindAll(obj => filter(obj)); } foreach (AbstractFileInfo fileInfo in files.OrderBy(obj => obj.Name)) { Console.WriteLine($"{fileInfo.Name}\t{fileInfo.Size()}\t{fileInfo.CRC()}"); } } } catch (NotAPackageException) { CommandLineLogger.LogError("Failed to list package contents because the package is not an Original Sin package or savegame archive"); } catch (Exception e) { CommandLineLogger.LogFatal($"Failed to list package: {e.Message}", 2); CommandLineLogger.LogTrace($"{e.StackTrace}"); } }
private static void ExtractPackageResource(string file = "", string folder = "", Func <AbstractFileInfo, bool> filter = null) { if (string.IsNullOrEmpty(file)) { file = CommandLineActions.SourcePath; CommandLineLogger.LogDebug($"Using source path: {file}"); } try { var packager = new Packager(); string extractionPath = GetExtractionPath(folder, CommandLineActions.DestinationPath); CommandLineLogger.LogDebug($"Using extraction path: {extractionPath}"); packager.UncompressPackage(file, extractionPath, filter); CommandLineLogger.LogInfo($"Extracted package to: {extractionPath}"); } catch (NotAPackageException) { CommandLineLogger.LogError("Failed to extract package because the package is not an Original Sin package or savegame archive"); } catch (Exception e) { CommandLineLogger.LogFatal($"Failed to extract package: {e.Message}", 2); CommandLineLogger.LogTrace($"{e.StackTrace}"); } }
private static void ExtractSingleFile(string packagePath, string destinationPath, string packagedPath) { try { using (var reader = new PackageReader(packagePath)) { Package package = reader.Read(); // Try to match by full path AbstractFileInfo file = package.Files.Find(fileInfo => string.Compare(fileInfo.Name, packagedPath, StringComparison.OrdinalIgnoreCase) == 0); if (file == null) { // Try to match by filename only file = package.Files.Find(fileInfo => string.Compare(Path.GetFileName(fileInfo.Name), packagedPath, StringComparison.OrdinalIgnoreCase) == 0); if (file == null) { CommandLineLogger.LogError($"Package doesn't contain file named '{packagedPath}'"); return; } } using (var fs = new FileStream(destinationPath, FileMode.Create, FileAccess.Write)) { try { Stream stream = file.MakeStream(); stream.CopyTo(fs); } finally { file.ReleaseStream(); } } } } catch (NotAPackageException) { CommandLineLogger.LogError("Failed to list package contents because the package is not an Original Sin package or savegame archive"); } catch (Exception e) { CommandLineLogger.LogFatal($"Failed to list package: {e.Message}", 2); CommandLineLogger.LogTrace($"{e.StackTrace}"); } }