Skip to content

Copy of PR #682 from Public CNE #5

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 1 commit 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
30 changes: 17 additions & 13 deletions source/funkin/backend/utils/ZipUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import sys.thread.Thread;

using StringTools;

// import ZipUtils; ZipUtils.uncompressZip(ZipUtils.openZip("E:\\Desktop\\test\\termination lua.ycemod"), "E:\\Desktop\\test\\uncompressed\\");
// import ZipUtils; var e = ZipUtils.createZipFile("file.ycemod"); ZipUtils.writeFolderToZip(e, "./mods/Friday Night Funkin'/", "Friday Night Funkin'/"); e.flush(); e.close();

class ZipUtil {
public static var bannedNames:Array<String> = [".git", ".gitignore", ".github", ".vscode", ".gitattributes", "readme.txt"];

Expand Down Expand Up @@ -129,12 +126,16 @@ class ZipUtil {
@param zip ZIP file to write to
@param path Folder path
@param prefix (Additional) allows you to set a prefix in the zip itself.
@param list (Additional) allows you to specify a list of folders to whitelist..
@param useWhitelist (Additional) allows you to specify if the list should be treated as a whitelist or blacklist.
**/
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 @@ -147,16 +148,19 @@ class ZipUtil {

var files:Array<StrNameLabel> = [];

var doFolder:Void->Void = null;
(doFolder = function() {
var doFolder:Int->Void = null;
(doFolder = function(depth:Int) {
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 @@ -165,7 +169,7 @@ class ZipUtil {
files.push(new StrNameLabel('$path/$e', zipPath));
}
}
})();
})(0);

prog.fileCount = files.length;
for(k=>file in files) {
Expand Down Expand Up @@ -193,10 +197,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