private static void ExtractPackageResource(string file = "", string folder = "") { if (string.IsNullOrEmpty(file)) { file = CommandLineActions.SourcePath; CommandLineLogger.LogDebug($"Using source path: {file}"); } try { Packager packager = new Packager(); string extractionPath = GetExtractionPath(folder, CommandLineActions.DestinationPath); CommandLineLogger.LogDebug($"Using extraction path: {extractionPath}"); packager.UncompressPackage(file, extractionPath); CommandLineLogger.LogInfo($"Extracted package to: {extractionPath}"); } catch (NotAPackageException) { CommandLineLogger.LogFatal("Failed to extract package because the package is not an Original Sin package or savegame archive", 1); } catch (Exception e) { CommandLineLogger.LogFatal($"Failed to extract package: {e.Message}", 2); CommandLineLogger.LogTrace($"{e.StackTrace}"); } }
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 BatchConvertResource(string sourcePath, string destinationPath, ResourceFormat inputFormat, ResourceFormat outputFormat, FileVersion fileVersion) { try { CommandLineLogger.LogDebug($"Using destination extension: {outputFormat}"); ResourceUtils resourceUtils = new ResourceUtils(); resourceUtils.ConvertResources(sourcePath, destinationPath, inputFormat, outputFormat, fileVersion); CommandLineLogger.LogInfo($"Wrote resources to: {destinationPath}"); } catch (Exception e) { CommandLineLogger.LogFatal($"Failed to batch convert resources: {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}"); } }
private static void ConvertResource(string sourcePath, string destinationPath, FileVersion fileVersion) { try { ResourceFormat resourceFormat = ResourceUtils.ExtensionToResourceFormat(destinationPath); CommandLineLogger.LogDebug($"Using destination extension: {resourceFormat}"); Resource resource = ResourceUtils.LoadResource(sourcePath); ResourceUtils.SaveResource(resource, destinationPath, resourceFormat, fileVersion); CommandLineLogger.LogInfo($"Wrote resource to: {destinationPath}"); } catch (Exception e) { CommandLineLogger.LogFatal($"Failed to convert resource: {e.Message}", 2); CommandLineLogger.LogTrace($"{e.StackTrace}"); } }
private static void ConvertResource(string file) { Exporter exporter = new Exporter { Options = UpdateExporterSettings() }; if (!string.IsNullOrEmpty(file)) { exporter.Options.InputPath = file; } try { exporter.Export(); CommandLineLogger.LogInfo("Export completed successfully."); } catch (Exception e) { CommandLineLogger.LogFatal($"Export failed: {e.Message}", 2); CommandLineLogger.LogTrace($"{e.StackTrace}"); } }