Allow Godot to import .ZIP files with non-regular structure
(cherry picked from commit 9b1db715fd
)
This commit is contained in:
parent
1001bea7ac
commit
c2b85ed865
1 changed files with 10 additions and 17 deletions
|
@ -104,6 +104,7 @@ private:
|
||||||
FileDialog *fdialog_install;
|
FileDialog *fdialog_install;
|
||||||
String zip_path;
|
String zip_path;
|
||||||
String zip_title;
|
String zip_title;
|
||||||
|
String zip_root;
|
||||||
AcceptDialog *dialog_error;
|
AcceptDialog *dialog_error;
|
||||||
String fav_dir;
|
String fav_dir;
|
||||||
|
|
||||||
|
@ -213,7 +214,9 @@ private:
|
||||||
char fname[16384];
|
char fname[16384];
|
||||||
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
|
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
|
||||||
|
|
||||||
if (String(fname).ends_with("project.godot")) {
|
String fname_str = String(fname);
|
||||||
|
if (fname_str.ends_with("project.godot")) {
|
||||||
|
zip_root = fname_str.substr(0, fname_str.rfind("project.godot"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,45 +551,35 @@ private:
|
||||||
|
|
||||||
String path = fname;
|
String path = fname;
|
||||||
|
|
||||||
int depth = 1; //stuff from github comes with tag
|
if (path == String() || path == zip_root || !zip_root.is_subsequence_of(path)) {
|
||||||
bool skip = false;
|
|
||||||
while (depth > 0) {
|
|
||||||
int pp = path.find("/");
|
|
||||||
if (pp == -1) {
|
|
||||||
skip = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
path = path.substr(pp + 1, path.length());
|
|
||||||
depth--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skip || path == String()) {
|
|
||||||
//
|
//
|
||||||
} else if (path.ends_with("/")) { // a dir
|
} else if (path.ends_with("/")) { // a dir
|
||||||
|
|
||||||
path = path.substr(0, path.length() - 1);
|
path = path.substr(0, path.length() - 1);
|
||||||
|
String rel_path = path.substr(zip_root.length());
|
||||||
|
|
||||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||||
da->make_dir(dir.plus_file(path));
|
da->make_dir(dir.plus_file(rel_path));
|
||||||
memdelete(da);
|
memdelete(da);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Vector<uint8_t> data;
|
Vector<uint8_t> data;
|
||||||
data.resize(info.uncompressed_size);
|
data.resize(info.uncompressed_size);
|
||||||
|
String rel_path = path.substr(zip_root.length());
|
||||||
|
|
||||||
//read
|
//read
|
||||||
unzOpenCurrentFile(pkg);
|
unzOpenCurrentFile(pkg);
|
||||||
unzReadCurrentFile(pkg, data.ptrw(), data.size());
|
unzReadCurrentFile(pkg, data.ptrw(), data.size());
|
||||||
unzCloseCurrentFile(pkg);
|
unzCloseCurrentFile(pkg);
|
||||||
|
|
||||||
FileAccess *f = FileAccess::open(dir.plus_file(path), FileAccess::WRITE);
|
FileAccess *f = FileAccess::open(dir.plus_file(rel_path), FileAccess::WRITE);
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
f->store_buffer(data.ptr(), data.size());
|
f->store_buffer(data.ptr(), data.size());
|
||||||
memdelete(f);
|
memdelete(f);
|
||||||
} else {
|
} else {
|
||||||
failed_files.push_back(path);
|
failed_files.push_back(rel_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue