Skip to content

Commit

Permalink
Fix current directory change logic in hybrid directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
blueskythlikesclouds committed Jun 12, 2024
1 parent 228dba0 commit a8e518d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
55 changes: 39 additions & 16 deletions core/io/dir_access_hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Error DirAccessHybrid::list_dir_begin() {
dir_access_pack->list_dir_end();
}

cdir = !list_dirs.empty();

return OK;
}

Expand Down Expand Up @@ -91,28 +93,44 @@ String DirAccessHybrid::get_drive(int p_drive) {

Error DirAccessHybrid::change_dir(String p_dir) {

dir_access_os->set_access_type(get_access_type());
dir_access_pack->set_access_type(get_access_type());

err_pack = dir_access_pack->change_dir(p_dir);
String old_dir = cur_dir;

if (err_pack == OK) {
err_os = dir_access_os->change_dir(dir_access_pack->get_current_dir());
} else {
if (p_dir.begins_with("res://") || p_dir.begins_with("/")) {
err_os = dir_access_os->change_dir(p_dir);
err_pack = dir_access_pack->change_dir(p_dir);
cur_dir = p_dir;
} else {
if (err_os == OK) {
err_os = dir_access_os->change_dir(p_dir);
}
if (err_os == OK) {
err_pack = dir_access_pack->change_dir(dir_access_os->get_current_dir());
cur_dir = dir_access_os->get_current_dir();
err_pack = dir_access_pack->change_dir(cur_dir);
} else if (err_pack == OK) {
err_pack = dir_access_pack->change_dir(p_dir);
if (err_pack == OK) {
cur_dir = dir_access_pack->get_current_dir();
err_os = dir_access_os->change_dir(cur_dir);
}
}
}

return err_os == OK || err_pack == OK ? OK : ERR_INVALID_PARAMETER;
if (err_os == OK || err_pack == OK) {
return OK;
}

err_os = dir_access_os->change_dir(old_dir);
err_pack = dir_access_pack->change_dir(old_dir);
cur_dir = old_dir;

return ERR_INVALID_PARAMETER;
}

String DirAccessHybrid::get_current_dir() {

return err_os == OK ? dir_access_os->get_current_dir() :
err_pack == OK ? dir_access_pack->get_current_dir() :
"";
cur_dir;
}

Error DirAccessHybrid::make_dir(String p_dir) {
Expand Down Expand Up @@ -166,12 +184,17 @@ String DirAccessHybrid::get_filesystem_type() const {
return dir_access_os->get_filesystem_type();
}

DirAccessHybrid::DirAccessHybrid(){
dir_access_os = DirAccess::create(AccessType::ACCESS_FILESYSTEM);
dir_access_pack = memnew(DirAccessPack);
err_os = OK;
err_pack = OK;
cdir = false;
DirAccessHybrid::DirAccessHybrid() {

dir_access_os = DirAccess::create(AccessType::ACCESS_FILESYSTEM);
dir_access_os->set_access_type(AccessType::ACCESS_RESOURCES);

dir_access_pack = memnew(DirAccessPack);
dir_access_pack->set_access_type(AccessType::ACCESS_RESOURCES);

err_os = OK;
err_pack = OK;
cdir = false;
}

DirAccessHybrid::~DirAccessHybrid() {
Expand Down
2 changes: 2 additions & 0 deletions core/io/dir_access_hybrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class DirAccessHybrid : public DirAccess {
Error err_os;
Error err_pack;

String cur_dir;

List<String> list_dirs;
List<String> list_files;

Expand Down
14 changes: 7 additions & 7 deletions core/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,17 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b

ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN);

String currentFile = dir->get_next();
String current_file = dir->get_next();

while (currentFile != "") {
if (!currentFile.ends_with(".pck") || dir->current_is_dir()) {
currentFile = dir->get_next();
while (current_file != "") {
if (dir->current_is_dir() || (!current_file.ends_with(".zip") && !current_file.ends_with(".pck"))) {
current_file = dir->get_next();
continue;
}

printf("Add pack: %ls\n", currentFile.c_str());
PackedData::get_singleton()->add_pack(currentFile);
currentFile = dir->get_next();
printf("Add pack: %ls\n", current_file.c_str());
PackedData::get_singleton()->add_pack(current_file);
current_file = dir->get_next();
}

using_datapack = true;
Expand Down

0 comments on commit a8e518d

Please sign in to comment.