private async Task CreateZipFile_WriteDir(ZipArchive za, ArchivedDirectory dir, List <string> failedFiles) { //Add all files here foreach (var f in dir.subFiles) { //Create path string filePath = f.path.Substring(path.Length); //Check if this is remote if (f.metadata.is_remote) { failedFiles.Add($"{filePath} - Download at {f.metadata.remote_url} ({f.metadata.remote_size} bytes)"); } //Write var entry = za.CreateEntry(filePath, CompressionLevel.Optimal); entry.LastWriteTime = f.GetDate(); using (Stream entryStream = entry.Open()) using (Stream fileStream = f.OpenFile()) await fileStream.CopyToAsync(entryStream); } //Add all files in subdirs foreach (var f in dir.subDirs) { await CreateZipFile_WriteDir(za, f, failedFiles); } }
public static ArchivedDirectory GetRootDirectory(ArchiveSite site, string dirPathname) { ArchivedDirectory d = new ArchivedDirectory(site, new DirectoryInfo(dirPathname)); d.path = "/"; d.SeekSubObjects(); d.isRoot = true; site.AddStoredObject(d); return(d); }
public static ArchivedDirectory GetSubDirectory(ArchivedDirectory parent, string dirPathname) { ArchivedDirectory d = new ArchivedDirectory(parent.site, new DirectoryInfo(dirPathname)); d.parent = parent; d.path = parent.path + d.GetName() + "/"; d.SeekSubObjects(); d.isRoot = false; d.site.AddStoredObject(d); return(d); }
private void SeekSubObjects() { string[] dirs = Directory.GetDirectories(info.FullName); string[] files = Directory.GetFiles(info.FullName); foreach (var d in dirs) { subDirs.Add(ArchivedDirectory.GetSubDirectory(this, d)); } foreach (var f in files) { if (f.EndsWith(".meta")) { subFiles.Add(new ArchivedFile(this.site, this, f)); } } }
public ArchivedFile(ArchiveSite site, ArchivedDirectory dir, string metadataFilePath) : base(site) { //Set this.parent = dir; this.metadataFilePath = metadataFilePath; //Load metadata metadata = JsonConvert.DeserializeObject <ArchivedFileMetadata>(File.ReadAllText(metadataFilePath)); //Get uploaded date if (metadata.uploaded_date.HasValue) { uploadedDate = metadata.uploaded_date.Value; } else { uploadedDate = new FileInfo(metadataFilePath).LastWriteTimeUtc; metadata.uploaded_date = uploadedDate; } //Get file if it's not remote if (!metadata.is_remote) { file = new FileInfo(metadataFilePath.Substring(0, metadataFilePath.Length - 5)); //trim off .meta } //Create path path = dir.path + GetName(); //Check if we have rich metadata if (metadata.rich_metadata == null) { rich_metadata_status = MetadataStatus.NOT_GENERATED; } else { rich_metadata_status = MetadataStatus.OK; } //Add this.site.AddStoredObject(this); }