Skip to content

Fixes minor mistake in calculating whitelisted and blacklisted items to be zipped. #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions source/funkin/backend/utils/ZipUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ZipUtil {

if (prog == null)
prog = new ZipProgress();

prog.fileCount = fields.length;
for(k=>field in fields) {
prog.curFile = k;
Expand Down Expand Up @@ -129,11 +130,13 @@ class ZipUtil {
@param path Folder path
@param prefix (Additional) allows you to set a prefix in the zip itself.
**/
public static function writeFolderToZip(zip:ZipWriter, path:String, ?prefix:String, ?prog:ZipProgress, ?whitelist:Array<String>):ZipProgress {
if (prefix == null) prefix = "";
if (whitelist == null) whitelist = [];
public static function writeFolderToZip(zip:ZipWriter, path:String, prefix:String = "", ?prog:ZipProgress, ?list:Array<String>, ?useWhitelist:Bool):ZipProgress {
if (list == null) list = [];
if (useWhitelist == null) useWhitelist = true;
if (prog == null) prog = new ZipProgress();

trace('whitelst: $useWhitelist | list: ${list}');

try {
var curPath:Array<String> = [path];
var destPath:Array<String> = [];
Expand All @@ -146,16 +149,19 @@ class ZipUtil {

var files:Array<StrNameLabel> = [];

var doFolder:Void->Void = null;
(doFolder = function() {
var doFolder:Int->Void = null;
(doFolder = function(depth:Int) { // adding depth search to check top folder
var path = curPath.join("/");
var zipPath = destPath.join("/");
for(e in FileSystem.readDirectory(path)) {
if (bannedNames.contains(e.toLowerCase()) && !whitelist.contains(e.toLowerCase())) continue;

if (bannedNames.contains(e.toLowerCase())) continue;
if (depth == 0 && list.contains(e.toLowerCase()) != useWhitelist) continue;

if (FileSystem.isDirectory('$path/$e')) {
// is directory, so loop into that function again
for(p in [curPath, destPath]) p.push(e);
doFolder();
doFolder(depth + 1);
for(p in [curPath, destPath]) p.pop();
} else {
// is file, put it in the list
Expand All @@ -164,7 +170,7 @@ class ZipUtil {
files.push(new StrNameLabel('$path/$e', zipPath));
}
}
})();
})(0);

prog.fileCount = files.length;
for(k=>file in files) {
Expand Down Expand Up @@ -192,10 +198,10 @@ class ZipUtil {
return prog;
}

public static function writeFolderToZipAsync(zip:ZipWriter, path:String, ?prefix:String):ZipProgress {
public static function writeFolderToZipAsync(zip:ZipWriter, path:String, ?prefix:String, ?list:Array<String>, ?useWhitelist:Bool = true):ZipProgress {
var zipProg = new ZipProgress();
Thread.create(function() {
writeFolderToZip(zip, path, prefix, zipProg);
writeFolderToZip(zip, path, prefix, zipProg, list, useWhitelist);
});
return zipProg;
}
Expand Down Expand Up @@ -265,4 +271,4 @@ class StrNameLabel {
this.label = label;
}
}
#end
#end