private void DoUnpack(PackEngine.Engine engine, Common.CommandLine cmdLine) { string pathIn = cmdLine.GetValue <string>("/pathIn"); if (string.IsNullOrEmpty(pathIn)) { throw new ApplicationException("Input path is required"); } string pathOut = cmdLine.GetValue <string>("/pathOut"); if (string.IsNullOrEmpty(pathOut)) { throw new ApplicationException("Output path is required"); } PackEngine.PackageReader reader = engine.CreatePackageReader(pathIn); PackEngine.PackageInfo info = reader.GetInfo(); if (info == null) { throw new ApplicationException("The package metadata is invalid"); } pathOut = ReplacePackageInfoWildcards(pathOut, info); Console.WriteLine($"== Extracting package \"{info.Name}\".\r\n"); reader.Extract(pathOut); }
public PackEngine.PackageInfo WritePackage(Stream stream, out string storeFileName) { string tempStoreName = Path.Combine(TempDirName, Guid.NewGuid().ToString()); using (Stream tempStream = WritePackage(tempStoreName)) stream.CopyTo(tempStream); string tempStorePath = Path.Combine(_storeRoot, tempStoreName); string finalStorePath = null; try { PackEngine.Engine packEngine = new PackEngine.Engine(); PackEngine.PackageReader reader = packEngine.CreatePackageReader(tempStorePath); PackEngine.PackageInfo info = reader.GetInfo(); if (info == null || !info.IsValid()) { throw new ApplicationException("Invalid package"); } storeFileName = MakeStoreFileName(info.Name, info.Version); finalStorePath = Path.Combine(_storeRoot, storeFileName); if (File.Exists(finalStorePath)) { File.Delete(finalStorePath); } (new FileInfo(finalStorePath)).Directory.Create(); File.Move(tempStorePath, finalStorePath); return(info); } catch { if (finalStorePath != null && File.Exists(finalStorePath)) { File.Delete(finalStorePath); } storeFileName = null; return(null); } finally { if (File.Exists(tempStorePath)) { File.Delete(tempStorePath); } } }