/// <summary> /// Loads the encoded header information. /// </summary> internal override PFile Load(CodeReader reader) { PFileComet result = new PFileComet(); result._name = reader.ReadString(); result._size = reader.ReadInt64(); result._lastModified = new DateTime(reader.ReadInt64()); result._attributes = (FileAttributes) reader.ReadInt32(); return result; }
/// <summary> /// Loads all items in the given folder. /// </summary> private static void LoadItems(Protocol protocol, PFolder folderToProcess, CodeReader reader, PPackage package) { // Declare iteration variable int i; PFolder subFolder; PFile file; // Load sub folders folderToProcess._folders = new List<PFolder>(); for (i = 0; i < folderToProcess._folderCount; i++) { subFolder = PFolder.Load(protocol, reader, package); subFolder.ParentFolder = folderToProcess; folderToProcess._folders.Add(subFolder); } // Load files folderToProcess._files = new List<PFile>(); for (i = 0; i < folderToProcess._fileCount; i++) { file = PFile.Load(protocol, reader); file.ParentFolder = folderToProcess; folderToProcess._files.Add(file); } }
/// <summary> /// Loads the header information. /// </summary> internal abstract PFolder Load(CodeReader reader);
/// <summary> /// Extracts the folder to the given location. /// </summary> internal void Extract(CodeReader reader, string destinationPath) { // Get path of the folder string thisFolder = destinationPath; if (this._parentFolder != null) thisFolder = PPackage.CreateValidPath(destinationPath, this._name) + @"\"; // Create folder and set attributes Directory.CreateDirectory(thisFolder); new DirectoryInfo(thisFolder).Attributes = this._attributes; // Extract sub folders foreach (PFolder folder in this._folders) folder.Extract(reader, thisFolder); // Extract files foreach (PFile file in this._files) file.Extract(reader, thisFolder); }
/// <summary> /// Returns a new folder, using the provided protocol and reader. /// </summary> internal static PFolder Load(Protocol protocol, CodeReader reader, PPackage package) { // Create new folder using the provided protocol PFolder result = protocol.FolderProtocol.Load(reader); result._package = package; // Load all items in the folder LoadItems(protocol, result, reader, package); // Return the folder return result; }
/// <summary> /// Returns a new package, using the provided reader. /// </summary> private static PPackage LoadInternal(CodeReader reader) { // Get protocol Protocol protocol = reader.Protocol; // Create new folder using the provided protocol PPackage result = protocol.PackageProtocol.Load(reader); // Load root result._root = PFolder.Load(protocol, reader, result); // Return the folder return result; }
/// <summary> /// Loads the header information. /// </summary> internal abstract PPackage Load(CodeReader reader);
/// <summary> /// Returns a new package, using the provided keyPath and codeFilePath. /// </summary> public static PPackage Load(string keyPath, string codeFilePath) { using (CodeReader reader = new CodeReader(keyPath, codeFilePath)) return LoadInternal(reader); }
/// <summary> /// Extracts the package to the given location. /// </summary> public static PPackage Extract(string keyPath, string codeFilePath, string destinationPath) { using (CodeReader reader = new CodeReader(keyPath, codeFilePath)) { // Get protocol Protocol protocol = reader.Protocol; // Reload the package to ensure we have the latest version PPackage result = LoadInternal(reader); // Extract the contents result._root.Extract(reader, destinationPath + @"\"); // Return the latest package return result; } }
/// <summary> /// Extracts the file to the given location. /// </summary> internal override byte[] Extract(CodeReader reader, int bytesToRead) { return reader.Read(bytesToRead); }