/// <summary> /// Writes a storage file to disk /// </summary> /// <param name="newStorage">Storage to write to disk</param> /// <param name="oldStorage">Old storage to overwrite or update</param> /// <param name="fileName">Name of the storage on disk</param> public void Write(JStorageSource newStorage, JStorageSource oldStorage, string fileName) { FileStream file; // Create a temporal file _tempFile = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileName(Path.GetTempFileName())); file = new FileStream(_tempFile, FileMode.Create, FileAccess.ReadWrite); writer = new BinaryWriter(file); _newStorage = newStorage; _oldStorage = oldStorage; WriteHeader(); WriteFilters(); WriteDirectories(); // Write the files, the list of offsets is needed to be able to jump around writting files headers and files data _fileOffsets = new List <long>(); WriteFilesHeader(); WriteFiles(newStorage.Root); writer.Flush(); writer.Close(); // If the file exits, delete it if (File.Exists(fileName)) { File.Delete(fileName); } // Rename the temporal file File.Copy(_tempFile, fileName); File.Delete(_tempFile); }
/// <summary> /// Reads a storage file /// </summary> /// <param name="storageFile">Storage object where to read the data</param> /// <param name="br">Reader to read the file</param> public void Read(JStorageSource storageFile, BinaryReader br) { int numberOfFilters, numberOfDirectories, numberOfFiles; _newStorage = storageFile; _newStorage.Name = br.ReadString(); // Read the number of things in the storage numberOfFilters = br.ReadInt32(); numberOfDirectories = br.ReadInt32(); numberOfFiles = br.ReadInt32(); // Load data LoadFilters(br, numberOfFilters); LoadDirectories(br, numberOfDirectories); LoadFiles(br, numberOfFiles); // Change the root directory _newStorage.Root = _newStorage.Root.GetDirectory("Root"); _newStorage.Root.Parent = null; }
/// <summary> /// Creates a <see cref="JFileInfo"/> for a storage file /// </summary> /// <param name="storage">Storage where the file is located</param> public JFileInfo(JStorageSource storage) { _storage = storage; _type = JFileType.Storage; }
/// <summary> /// Writes a storage file to disk /// </summary> /// <param name="newStorage">Storage to write to disk</param> /// <param name="oldStorage">Old storage to overwrite or update</param> /// <param name="fileName">Name of the storage on disk</param> public void Write(JStorageSource newStorage, JStorageSource oldStorage, string fileName) { FileStream file; // Create a temporal file _tempFile = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileName(Path.GetTempFileName())); file = new FileStream(_tempFile, FileMode.Create, FileAccess.ReadWrite); writer = new BinaryWriter(file); _newStorage = newStorage; _oldStorage = oldStorage; WriteHeader(); WriteFilters(); WriteDirectories(); // Write the files, the list of offsets is needed to be able to jump around writting files headers and files data _fileOffsets = new List<long>(); WriteFilesHeader(); WriteFiles(newStorage.Root); writer.Flush(); writer.Close(); // If the file exits, delete it if (File.Exists(fileName)) File.Delete(fileName); // Rename the temporal file File.Copy(_tempFile, fileName); File.Delete(_tempFile); }