forked from gordon-matt/elFinder.NetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseDriver.cs
More file actions
47 lines (38 loc) · 1.28 KB
/
Copy pathBaseDriver.cs
File metadata and controls
47 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.IO.Compression;
namespace elFinder.NetCore.Drivers;
/// <summary>
/// Represents a Base elFinder Driver
/// </summary>
public abstract class BaseDriver
{
public ICollection<RootVolume> Roots { get; protected set; }
public string VolumePrefix { get; protected set; }
/// <summary>
/// Adds an object to the end of the roots.
/// </summary>
/// <param name="item"></param>
public void AddRoot(RootVolume item)
{
Roots.Add(item);
item.VolumeId = $"{VolumePrefix}{Roots.Count}_";
}
protected virtual async Task AddDirectoryToArchiveAsync(ZipArchive zipFile, IDirectory directoryInfo, string root)
{
string entryName = $"{root}{directoryInfo.Name}/";
zipFile.CreateEntry(entryName);
var dirs = await directoryInfo.GetDirectoriesAsync();
foreach (var dir in dirs)
{
await AddDirectoryToArchiveAsync(zipFile, dir, entryName);
}
var files = await directoryInfo.GetFilesAsync(null);
foreach (var file in files)
{
zipFile.CreateEntryFromFile(file.FullName, entryName + file.Name);
}
}
protected Task<JsonResult> Json(object data)
{
return Task.FromResult(new JsonResult(data) { ContentType = "text/html" });
}
}