summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-04-01 00:18:19 +0200
committerGitHub <noreply@github.com>2021-04-01 00:18:19 +0200
commit36c11a5b9362a12af7a96ddcd773dadb9479b08e (patch)
tree6ff287ace46dab9c32e77ed6ff3e281e20440a06 /editor
parent54a690ead1529728cc6662f9a49988363da3a60c (diff)
parent9b1db715fd51e0efa5e79bdaec5239e79b23061d (diff)
Merge pull request #42890 from Ev1lbl0w/bugfix-import-zip
Allow Godot to import .ZIP files with non-regular structure
Diffstat (limited to 'editor')
-rw-r--r--editor/project_manager.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 26ff8e1551..eda9499783 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -100,6 +100,7 @@ private:
FileDialog *fdialog_install;
String zip_path;
String zip_title;
+ String zip_root;
AcceptDialog *dialog_error;
String fav_dir;
@@ -200,7 +201,9 @@ private:
char fname[16384];
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 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;
}
@@ -533,44 +536,34 @@ private:
String path = fname;
- int depth = 1; //stuff from github comes with tag
- 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()) {
+ if (path == String() || path == zip_root || !zip_root.is_subsequence_of(path)) {
//
} else if (path.ends_with("/")) { // a dir
path = path.substr(0, path.length() - 1);
+ String rel_path = path.substr(zip_root.length());
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- da->make_dir(dir.plus_file(path));
+ da->make_dir(dir.plus_file(rel_path));
memdelete(da);
} else {
Vector<uint8_t> data;
data.resize(info.uncompressed_size);
+ String rel_path = path.substr(zip_root.length());
//read
unzOpenCurrentFile(pkg);
unzReadCurrentFile(pkg, data.ptrw(), data.size());
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) {
f->store_buffer(data.ptr(), data.size());
memdelete(f);
} else {
- failed_files.push_back(path);
+ failed_files.push_back(rel_path);
}
}