@@ -30,22 +30,33 @@ public MemoryStream Get(string[] groups)
30
30
foreach ( var group in groups . Where ( g => g . Trim ( ) != "" ) )
31
31
{
32
32
var dir = Path . Combine ( _configFolder , group ) ;
33
- if ( Directory . Exists ( dir ) )
34
- {
35
- foreach ( var file in Directory . EnumerateFiles ( dir ) . Where ( file => file . EndsWith ( ".loli" ) ) )
36
- {
37
- var zipArchiveEntry = archive . CreateEntry ( Path . GetFileName ( file ) , CompressionLevel . Fastest ) ;
38
- var fileContent = File . ReadAllBytes ( file ) ;
39
- using ( var zipStream = zipArchiveEntry . Open ( ) ) zipStream . Write ( fileContent , 0 , fileContent . Length ) ;
40
- }
41
- }
33
+
34
+ ZipFolderRecursively ( archive , dir , _configFolder ) ;
42
35
}
43
36
}
44
37
45
38
return ms ;
46
39
}
47
40
}
48
41
42
+ private void ZipFolderRecursively ( ZipArchive archive , string currentDir , string baseDir )
43
+ {
44
+ // Add all the files
45
+ foreach ( var file in Directory . EnumerateFiles ( currentDir ) . Where ( file => file . EndsWith ( ".loli" ) ) )
46
+ {
47
+ // Create the file entry and write the file content
48
+ var zipArchiveEntry = archive . CreateEntry ( $ "{ file . Substring ( baseDir . Length + 1 ) } ", CompressionLevel . Fastest ) ;
49
+ var fileContent = File . ReadAllBytes ( file ) ;
50
+ using ( var zipStream = zipArchiveEntry . Open ( ) ) zipStream . Write ( fileContent , 0 , fileContent . Length ) ;
51
+ }
52
+
53
+ // Add subfolders recursively
54
+ foreach ( var dir in Directory . EnumerateDirectories ( currentDir ) )
55
+ {
56
+ ZipFolderRecursively ( archive , dir , baseDir ) ;
57
+ }
58
+ }
59
+
49
60
public async Task < bool > Upload ( Stream file , string group , string name )
50
61
{
51
62
if ( group != "" && name . EndsWith ( ".loli" ) )
0 commit comments