private static void Pack(PackOptions options) { var directories = Directory.GetDirectories(options.Source); var writer = new ArchiveWriter(); foreach (var dir in directories) { var directoryName = Path.GetFileNameWithoutExtension(dir).Split(GroupIdSeparator); var groupNo = Convert.ToByte(directoryName[0]); var id = Convert.ToUInt16(directoryName[1]); var filesInside = Directory.GetFiles(dir); var group = new ManagedGroup() { Id = id, Files = new List <ManagedFile>(filesInside.Length) }; foreach (var file in filesInside) { group.Files.Add(new ManagedFile() { Data = File.ReadAllBytes(file) }); } writer.AddGroup(groupNo, group); } // Write file to new location. Directory.CreateDirectory(Path.GetDirectoryName(options.SavePath)); using var fileStream = new FileStream(options.SavePath, FileMode.Create, FileAccess.Write, FileShare.None); writer.Write(fileStream, options.BigEndian); }
/// <summary> /// Gets all files in all groups in a convenient representation. /// </summary> /// <returns>A mapping between group id to all of the group's files.</returns> public ManagedGroup[] GetAllGroups() { var result = new ManagedGroup[Groups.Length]; for (var x = 0; x < Groups.Length; x++) { result[x] = new ManagedGroup(Groups[x], GetFiles(Groups[x])); } return(result); }
/// <summary> /// Adds a group to be written to the archive. /// </summary> /// <param name="groupNo">Id of the group to add.</param> /// <param name="group">The group to add to the list of groups.</param> public void AddGroup(byte groupNo, ManagedGroup group) => Groups[groupNo] = (group);