public static List <PackageDef> TestNonConflicting() { var B = new PackageDef { Name = "B", RawVersion = "2.0.0" }; var file = new PackageFile { FileName = "Package/A/test" }; file.CustomData.Add(new FileHashPackageAction.Hash { Value = "TEST1234" }); // same hash B.Files.Add(file); var C = new PackageDef { Name = "C", RawVersion = "2.0.0" }; var file2 = new PackageFile { FileName = "Package/B/test" }; file2.CustomData.Add(new FileHashPackageAction.Hash { Value = "TEST1234" }); B.Files.Add(file2); return(new List <PackageDef> { B, C }); }
bool ValidateStaticConfig(PackageFile pkg) { var cfg = pkg.Config as StaticResourceConfig; if (cfg == null) { return(false); } if (cfg.Uri == null) { return(false); } if (cfg.FilePath == null) { return(false); } if (!File.Exists(cfg.FilePath)) { pkg.Status = PackageFileStatus.AnalyzedConfigurationError; var relativePath = System.IO.Path.Combine(pkg.FileInfo.DirectoryName, cfg.FilePath); if (File.Exists(relativePath)) { cfg.FilePath = relativePath; pkg.Status = PackageFileStatus.AnalyzedReady; } } return(true); }
public static List <PackageDef> GetInstallation() { var opentap = new PackageDef { Name = "OpenTAP", RawVersion = "1.0.0" }; var A = new PackageDef() { Name = "A", RawVersion = "1.0.0" }; A.Dependencies.Add(new PackageDependency("OpenTAP", VersionSpecifier.Any)); var file = new PackageFile(); file.FileName = "Package/A/test"; file.CustomData.Add(new FileHashPackageAction.Hash { Value = "TEST1234" }); A.Files.Add(file); var file2 = new PackageFile(); file2.FileName = "Dependencies/A/test"; file2.CustomData.Add(new FileHashPackageAction.Hash { Value = "TEST1234" }); A.Files.Add(file2); return(new List <PackageDef> { opentap, A }); }
public BuiltInClassV1StitchAdaptor(PackageFile packageFile, StitchInstance instance, IStitchEventObserver observer, IModuleLog log) { Observer = observer; _instance = instance; _log = log; _parameters = new BuiltInClassV1Parameters(packageFile.Adaptor.Parameters); }
public async Task Add(PackageName item) { var file = new PackageFile(GetPackagePath(item), deleteDepth); file.EnsureParent(); file.OpenWrite().Dispose(); }
public IEnumerable <IPackage> FindPackages(IReadOnlyList <string> names, string version = null) { var cache = new PackageCache(); var list = new List <LocalPackage>(); var namesUpper = new HashSet <string>(names.Select(x => x.ToUpperInvariant())); var versionUpper = string.IsNullOrEmpty(version) ? null : version.ToUpperInvariant(); foreach (var directory in cache.SearchPaths) { foreach (var package in cache.GetPackageDirectories(directory).Keys) { if (namesUpper.Count == 0 || namesUpper.Contains(package.ToUpperInvariant())) { foreach (var versionDir in cache.GetVersionDirectories(package)) { if ((versionUpper == null || versionUpper == versionDir.Name.ToUpperInvariant()) && PackageFile.Exists(versionDir.FullName)) { list.Add(new LocalPackage(package, versionDir.Name, versionDir.FullName)); } } } } } list.Sort(); return(list); }
public void should_remove_an_unchanged_file() { Context(); var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); var fileSystemFiles = new List <string>() { filePath }; fileSystem.Setup(x => x.get_files(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny <string>())).Returns(packageFile); because(); fileSystem.Verify(x => x.delete_file(filePath)); }
public void should_backup_a_changed_file() { Context(); var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; packageFiles.Files.Add(packageFile); packageInfo.FilesSnapshot = packageFiles; var packageFileWithUpdatedChecksum = new PackageFile { Path = filePath, Checksum = "4321" }; var fileSystemFiles = new List <string>() { filePath }; fileSystem.Setup(x => x.get_files(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(fileSystemFiles); var updatedPackageFiles = new PackageFiles(); updatedPackageFiles.Files = new List <PackageFile> { packageFileWithUpdatedChecksum }; filesService.Setup(x => x.capture_package_files(It.IsAny <string>(), config)).Returns(updatedPackageFiles); because(); fileSystem.Verify(x => x.copy_file(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Once); }
void LoadDescriptor() { using (Stream zipStream = PackageFile.OpenRead()) using (var zip = new ZipFile(zipStream)) { var entries = zip.Cast <ZipEntry>(); ZipEntry descriptorFile = entries.FirstOrDefault(x => x.Name.EndsWith(".wrapdesc")); if (descriptorFile == null) { throw new InvalidOperationException(String.Format("The package '{0}' doesn't contain a valid .wrapdesc file.", PackageFile.Name)); } ZipEntry versionFile = entries.SingleOrDefault(x => x.Name.EqualsNoCase("version")); Version versionFromVersionFile = versionFile != null?zip.Read(versionFile, x => x.ReadString().ToVersion()) : null; var descriptor = zip.Read(descriptorFile, x => new PackageDescriptorReader().Read(x)); _descriptor = new DefaultPackageInfo(PackageFile.Name, versionFromVersionFile, descriptor); if (Descriptor.Version == null) { throw new InvalidOperationException("The package '{0}' doesn't have a valid version, looked in the 'wrapdesc' file, in 'version' and in the package file-name."); } } }
public ActionResult Upload(HttpPostedFileBase file, string passcode) { //check for passcode if (passcode != System.Configuration.ConfigurationManager.AppSettings["passcode"]) { return(View("Message", new MessageModel(string.Format("Sorry, that passcode is incorrect.")))); } //first, create some space by clearing cache DataStore.ClearCache(); //create instance of packagefile and attach to session PackageFile packagefile = new PackageFile(file); //get result if (!packagefile.IsAppVPackage) { return(View("Message", new MessageModel(string.Format("There was an error inspecting this package: {0}", packagefile.Status)))); } //store session info Session["name"] = Path.GetFileName(file.FileName); Session["id"] = packagefile.ID; //return results return(View("Properties", new PropertiesModel(packagefile.ID))); }
public void should_not_delete_an_unfound_file() { Context(); var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; var packageFileNotInOriginal = new PackageFile { Path = "c:\\files", Checksum = "4321" }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); var fileSystemFiles = new List <string>() { filePath }; fileSystem.Setup(x => x.get_files(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny <string>())).Returns(packageFileNotInOriginal); because(); fileSystem.Verify(x => x.delete_file(filePath), Times.Never); }
public void Generate() { var package = new PackageFile(_upk, _env.OutputDirectory); new SourceReader(_log, _upk, _env) .ExportCache( package.CacheDirectory, package.ExtensionsBackends, package.Namespaces); if (_env.Debug) { // DEBUG: Reuse source files from project directory package.SourceDirectory = _upk.SourceDirectory; } else { // RELEASE: Copy source files into package foreach (var f in _upk.AllFiles) { var source = Path.Combine(_upk.SourceDirectory, f.NativePath); var destination = Path.Combine(package.RootDirectory, f.NativePath); _disk.CopyFile(source, destination); } } package.Save(); File.WriteAllText( Path.Combine(package.CacheDirectory, "config"), _env.GetString("Configuration")); }
public bool TryAccessFile(string path, bool create, out IPackageFile file) { var uri = PackUriHelper.CreatePartUri(new Uri(".\\" + path, UriKind.Relative)); if (create) { if (_package.PartExists(uri)) { _package.DeletePart(uri); } var part = _package.CreatePart(uri, "", CompressionOption.Normal); file = new PackageFile(part); return(true); } else if (_package.PartExists(uri)) { file = new PackageFile(_package.GetPart(uri)); return(true); } else { file = null; return(false); } }
public void should_ignore_an_unchanged_file() { Context(); var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; packageFiles.Files.Add(packageFile); packageInfo.FilesSnapshot = packageFiles; var fileSystemFiles = new List <string>() { filePath }; fileSystem.Setup(x => x.get_files(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.capture_package_files(It.IsAny <string>(), config)).Returns(packageFiles); because(); fileSystem.Verify(x => x.copy_file(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Never); }
private StitchInstance CreateSingleNewInstanceInternal(PackageFile packageFile, LocalCreateInstanceRequest request) { // Insert the new instance to the data module var instance = new StitchInstanceMapper(_core.NodeId, _core.Name).Map(request); instance = _data.Insert(instance); if (instance == null) { _log.LogError("Could not save new stitch instance"); return(null); } if (packageFile.Adaptor.RequiresPackageUnzip) { // Unzip a copy of the version from the library into the running base var result = _fileSystem.UnzipLibraryPackageToRunningBase(instance.GroupName, instance.Id); if (!result.Success) { _log.LogError("Could not unzip library package for new stitch {0}", instance.GroupName); return(null); } // TODO: We should move this into a class specific to ProcessV1 types. _data.Update <PackageFile>(packageFile.Id, pf => pf.Adaptor.Parameters[Parameters.RunningDirectory] = result.Path); } _data.Save(instance); _log.LogInformation("Created stitch instance Id={0} GroupName={1}", instance.Id, request.GroupName); _notifier.StitchCreated(instance); // StitchInstanceManager auto-creates the necessary adaptor on Start. We don't need to do anything for it here. return(instance); }
public void should_not_delete_a_changed_file() { Context(); var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; var packageFileWithUpdatedChecksum = new PackageFile { Path = filePath, Checksum = "4321" }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); var fileSystemFiles = new List <string>() { filePath }; fileSystem.Setup(x => x.get_files(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny <string>())).Returns(packageFileWithUpdatedChecksum); fileSystem.Setup(x => x.file_exists(filePath)).Returns(true); because(); fileSystem.Verify(x => x.delete_file(filePath), Times.Never); }
private ObservableCollection <PackageItem> buildPackageTree(XElement phntCurrentDirectory) { var items = new ObservableCollection <PackageItem>(); // For each directory node foreach (var directory in phntCurrentDirectory.Elements("directory")) { // Create a new PackageDirectory object and assign properties var item = new PackageDirectory { ItemName = directory.Element("name").Value, // Pass the current directory for recursion PackageItems = buildPackageTree(directory) }; // Add PackageItems to collection items.Add(item); } foreach (var file in phntCurrentDirectory.Elements("file")) { var item = new PackageFile { ItemName = file.Element("name").Value, WindowsPath = file.Element("path").Value, }; // Pass the settings node for this file to the setPackageFileSettings function setPackageFileSettings(item, file.Element("settings")); items.Add(item); } return(items); }
public Task <byte[]> LoadPackageContentAsync(string packageHash, PackageFile packageFile, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); Directory.CreateDirectory(_options.Value.PackageLocation); var packagePath = Path.Combine(_options.Value.PackageLocation, $"mono-wasm-{packageHash}"); if (!Directory.Exists(packagePath)) { return(Task.FromResult(NoContent)); } switch (packageFile) { case PackageFile.MonoConfig: { var fileName = Path.Combine(packagePath, "mono-config.js"); var file = Task.FromResult(!File.Exists(fileName) ? NoContent : File.ReadAllBytes(fileName)); return(file); } case PackageFile.RuntimeJs: { var fileName = Path.Combine(packagePath, "runtime.js"); var file = Task.FromResult(!File.Exists(fileName) ? NoContent : File.ReadAllBytes(fileName)); return(file); } default: throw new ArgumentOutOfRangeException(nameof(packageFile), packageFile, null); } }
public PackageFileUploadResponse UploadStitchPackageFileFromRemote(PackageFileUploadRequest request) { if (!request.IsValidRemoteRequest()) { return(new PackageFileUploadResponse(false, null, null)); } // Save the file and generate a unique Version name var result = _fileSystem.SavePackageToLibrary(request.GroupName.Application, request.GroupName.Component, request.GroupName.Version, request.Contents); var packageFile = new PackageFile { Id = request.GroupName.ToString(), Adaptor = request.Adaptor, FileName = request.FileName, GroupName = request.GroupName }; bool ok = _data.Save(packageFile, true); if (!ok) { _log.LogError("Could not save PackageFile Id={0} from remote", request.GroupName.ToString()); } _log.LogDebug("Uploaded package file {0}", request.GroupName); return(new PackageFileUploadResponse(ok, request.GroupName, result.FilePath)); }
public void should_do_nothing_if_the_directory_no_longer_exists() { Context(); fileSystem.ResetCalls(); fileSystem.Setup(x => x.directory_exists(It.IsAny <string>())).Returns(false); var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); var fileSystemFiles = new List <string>() { filePath }; fileSystem.Setup(x => x.get_files(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny <string>())).Returns(packageFile); because(); filesService.Verify(x => x.get_package_file(It.IsAny <string>()), Times.Never); fileSystem.Verify(x => x.delete_file(filePath), Times.Never); }
public async Task <IActionResult> Post([FromBody] UploadPackageRequestDto uploadPackageRequestDto) { IList <PackageFile> files = uploadPackageRequestDto.PackageFiles .Select(file => new PackageFile(file.FileName, file.FileContent)) .ToList(); // put a hard limit on the amount of files per package for now if (files.Count > 99) { return(this.BadRequest("can not have more then 100 items in a package")); } PackageFile ethereumPm = files.FirstOrDefault(f => f.FileName == Constants.EthereumPmJson); if (ethereumPm == null) { return(this.BadRequest("To upload a package you need a `ethereum-pm.json` file")); } JObject ethereumPmJson; try { ethereumPmJson = JObject.Parse(ethereumPm.FileContent); } catch (Exception) { return(this.BadRequest("Invalid JSON - `ethereum-pm.json`")); } EthereumPmMetaData metaData = new EthereumPmMetaData() { Description = (string)ethereumPmJson["description"], GitHub = (string)ethereumPmJson["github"], Private = (bool?)ethereumPmJson["private"] ?? false, Team = (string)ethereumPmJson["team"], Keywords = (IList <string>)ethereumPmJson["keywords"] }; PackageFiles packageFiles = new PackageFiles ( uploadPackageRequestDto.PackageVersion, uploadPackageRequestDto.PackageName, (IReadOnlyCollection <PackageFile>)files ); try { UnpackedJwt unpackedJwt = this._jwtService.UnpackJwtClaimsToProfile(User.Claims.ToList()); await this._packageService.UploadPackageAsync(packageFiles, metaData, unpackedJwt.Username); } catch (Exception ex) { return(this.BadRequest(ex)); } return(this.Ok()); }
public void PackageFileConstructorNullPath() { IPackage ownerPackage = new MockPackage("someLocation"); string path = string.Empty; PackageFile target = new PackageFile(ownerPackage, path); Assert.Fail("A ArgumentNullException exception should have been thrown"); }
private static void UpdateFile(string newFilePath, PackageFile file) { EnsureDirectory(newFilePath); using (Stream fromStream = file.GetStream(), toStream = File.Create(newFilePath)) { fromStream.CopyTo(toStream); } }
private void setPackageFileSettings(PackageFile item, XElement phntFileSettingsNode) { item.IsBackup = (phntFileSettingsNode.Element("fg_donotbackup").Value == "0"); item.IsIgnoreValidation = (phntFileSettingsNode.Element("fg_ignorevalidation").Value == "1"); item.IsIgnoreValidationForBackup = (phntFileSettingsNode.Element("fg_ignorevalidation").Value == "1"); // TODO: Donotpush // TODO: Donotwatch }
public void PackageFileConstructorNullPackage() { IPackage ownerPackage = null; string path = "sfjahsd/dsfe.data"; PackageFile target = new PackageFile(ownerPackage, path); Assert.Fail("A ArgumentNullException exception should have been thrown"); }
public void PackageFileConstructorFileDoesNotExist() { IPackage ownerPackage = TempPackage; // TODO: Initialize to an appropriate value string path = "fdsjhfsadjk.fdf"; // TODO: Initialize to an appropriate value PackageFile target = new PackageFile(ownerPackage, path); Assert.Fail("A FileNotFound exception should have been thrown"); }
public FileContentInfo(PackageFile file, string name, object content, bool isTextFile, long size) { File = file; Name = name; Content = content; IsTextFile = isTextFile; Size = size; }
private async Task <IActionResult> TryServePackageFileAsync(string package, PackageFile packageFile, string version = null) { if (string.IsNullOrWhiteSpace(package)) { return(BadRequest(new { Message = "Package name required." })); } // FIXME: duplicate code if (Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var etag)) { var resources = await _packages.GetAvailablePackagesAsync(CancellationToken); foreach (var hash in etag) { if (resources.Contains(hash)) { return(StatusCode((int)HttpStatusCode.NotModified)); } } } var(error, buildHash) = await TryGetBuildHash(version); if (error != null) { return(error); } var assembly = await _packages.FindAssemblyByNameAsync(package, CancellationToken); if (assembly == null) { return(NotFound(new { Message = $"No package assemblies found matching name '{package}." })); } var packageHash = assembly.ComputePackageHash(buildHash); var packages = await _packages.GetAvailablePackagesAsync(CancellationToken); if (packages.Contains(packageHash)) { var file = await ServePackageFileAsync(packageHash, packageFile, CancellationToken); if (!(file is NotFoundObjectResult)) { return(file); // try to re-compile if we ran into an issue earlier } } var result = await _packages.CompilePackageAsync(assembly, buildHash, CancellationToken); if (!result.Successful) { return(StatusCode((int)HttpStatusCode.InternalServerError, new { Message = "Package compile error." })); } return(await ServePackageFileAsync(packageHash, packageFile, CancellationToken)); }
public FileContentInfo(PackageFile file, string name, string content, bool isTextFile, long size, SourceLanguageType language) { File = file; Name = name; Content = content; IsTextFile = isTextFile; Size = size; Language = language; }
private void AssertFilesAreTheSame(PackageFile expected, object actual) { Assert.IsInstanceOf <PackageFile>(actual); var actualFile = actual as PackageFile; Assert.AreEqual(expected.SourceFile, actualFile.SourceFile); Assert.AreEqual(expected.TargetFileName, actualFile.TargetFileName); Assert.AreEqual(expected.TargetFolder, actualFile.TargetFolder); }
public static void Main(string[] args) { bool showHelp = false; bool verbose = false; OptionSet options = new OptionSet() { { "v|verbose", "be verbose", v => verbose = v != null }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; List<string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (extras.Count < 1 || extras.Count > 2 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+ [output_dzip] input_dir+", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } var inputPaths = new List<string>(); string outputPath; if (extras.Count == 1) { inputPaths.Add(extras[0]); outputPath = Path.ChangeExtension(extras[0], ".dzip"); } else { outputPath = extras[0]; inputPaths.AddRange(extras.Skip(1)); } var paths = new SortedDictionary<string, string>(); if (verbose == true) { Console.WriteLine("Finding files..."); } foreach (var relPath in inputPaths) { string inputPath = Path.GetFullPath(relPath); if (inputPath.EndsWith(Path.DirectorySeparatorChar.ToString()) == true) { inputPath = inputPath.Substring(0, inputPath.Length - 1); } foreach (string path in Directory.GetFiles(inputPath, "*", SearchOption.AllDirectories)) { bool hasName; string fullPath = Path.GetFullPath(path); string partPath = fullPath.Substring(inputPath.Length + 1).ToLowerInvariant(); if (paths.ContainsKey(partPath) == true) { Console.WriteLine("Ignoring {0} duplicate.", partPath); continue; } paths[partPath] = fullPath; } } using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { var pkg = new PackageFile(); output.Seek(PackageFile.HeaderSize, SeekOrigin.Begin); if (verbose == true) { Console.WriteLine("Writing files to package..."); } foreach (var kvp in paths) { if (verbose == true) { Console.WriteLine(kvp.Key); } using (var input = File.OpenRead(kvp.Value)) { var entry = new Package.Entry(); entry.Name = kvp.Key; entry.TimeStamp = File.GetLastWriteTime(kvp.Value); entry.UncompressedSize = input.Length; entry.Offset = output.Position; int blockCount = (int)((entry.UncompressedSize + 0xFFFF) >> 16); // .Align(0x10000) / 0x10000; var compressedBlocks = new byte[blockCount][]; var compressedSizes = new int[blockCount]; var uncompressedBlock = new byte[0x10000]; long left = input.Length; for (int i = 0; i < blockCount; i++) { int uncompressedSize = input.Read( uncompressedBlock, 0, uncompressedBlock.Length); var lzf = new LZF(); compressedBlocks[i] = new byte[0x20000]; int compressedSize = lzf.Compress( uncompressedBlock, uncompressedSize, compressedBlocks[i], compressedBlocks[i].Length); if (compressedSize == 0) { throw new InvalidOperationException(); } compressedSizes[i] = compressedSize; } int offset = blockCount * 4; for (int i = 0; i < blockCount; i++) { output.WriteValueS32(offset); offset += compressedSizes[i]; } for (int i = 0; i < blockCount; i++) { output.Write(compressedBlocks[i], 0, compressedSizes[i]); } entry.CompressedSize = offset; pkg.Entries.Add(entry); } } if (verbose == true) { Console.WriteLine("Writing package header..."); } pkg.Serialize(output, output.Length); } }
public static void Main(string[] args) { bool showHelp = false; bool overwriteFiles = false; bool list = false; string cdkey = null; string extensionFilter = null; OptionSet options = new OptionSet() { { "o|overwrite", "overwrite existing files", v => overwriteFiles = v != null }, { "cdkey=", "cdkey for use with DLC archives\n(in format #####-#####-#####-#####)", v => cdkey = v }, { "e|extension=", "only extract files of this extension", v => extensionFilter = v }, { "h|help", "show this message and exit", v => showHelp = v != null }, { "l|list", "print a list of archive contents, don't unpack anything", v => list = v != null } }; List<string> extras; try { extras = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (extras.Count < 1 || extras.Count > 2 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+ input_dzip [output_dir]", GetExecutableName()); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } string inputPath = extras[0]; string outputPath = extras.Count > 1 ? extras[1] : Path.ChangeExtension(inputPath, null); var uncompressed = new byte[0x10000]; bool filtering = string.IsNullOrEmpty(extensionFilter) == false; using (var input = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var pkg = new PackageFile(); pkg.DeserializeWithCDKey(input, cdkey); long current = 0; long total = pkg.Entries.Count; foreach (var entry in pkg.Entries) { current++; var entryPath = Path.Combine(outputPath, entry.Name); if (overwriteFiles == false && File.Exists(entryPath) == true) { continue; } if (filtering == true && Path.GetExtension(entryPath) != extensionFilter) { continue; } Console.WriteLine("[{0}/{1}] {2}", current, total, entry.Name); if (list) continue; Directory.CreateDirectory(Path.GetDirectoryName(entryPath)); input.Seek(entry.Offset, SeekOrigin.Begin); int blocks = (int)((entry.UncompressedSize + 0xFFFF) >> 16); // .Align(0x10000) / 0x10000; var offsets = new long[blocks + 1]; for (int i = 0; i < offsets.Length; i++) { offsets[i] = entry.Offset + input.ReadValueU32(); } offsets[blocks] = entry.Offset + entry.CompressedSize; using (var output = File.Create(entryPath)) { long left = entry.UncompressedSize; for (int i = 0; i < blocks; i++) { var compressed = new byte[offsets[i + 1] - offsets[i + 0]]; input.Seek(offsets[i], SeekOrigin.Begin); input.Read(compressed, 0, compressed.Length); int read = LZF.Decompress(compressed, uncompressed); if (i + 1 < blocks && read != uncompressed.Length) { throw new InvalidOperationException(); } output.Write(uncompressed, 0, (int)Math.Min(left, read)); left -= read; } } File.SetLastWriteTime(entryPath, entry.TimeStamp); } } }