Add error checks for DirAccess creation.

This commit is contained in:
Saracen 2023-09-26 03:07:43 +01:00
parent 43b9e89a07
commit 3f4513d4de
10 changed files with 26 additions and 0 deletions

View File

@ -962,6 +962,7 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par
#ifdef TOOLS_ENABLED
bool _csproj_exists(String p_root_dir) {
Ref<DirAccess> dir = DirAccess::open(p_root_dir);
ERR_FAIL_COND_V(dir.is_null(), false);
dir->list_dir_begin();
String file_name = dir->_get_next();

View File

@ -5954,6 +5954,7 @@ void EditorNode::_dropped_files(const Vector<String> &p_files) {
void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, String to_path) {
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND(dir.is_null());
for (int i = 0; i < p_files.size(); i++) {
String from = p_files[i];
@ -5963,6 +5964,8 @@ void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, Str
Vector<String> sub_files;
Ref<DirAccess> sub_dir = DirAccess::open(from);
ERR_FAIL_COND(sub_dir.is_null());
sub_dir->list_dir_begin();
String next_file = sub_dir->get_next();

View File

@ -914,6 +914,8 @@ void EditorSettings::create() {
if (EditorPaths::get_singleton()->are_paths_valid()) {
// Validate editor config file.
Ref<DirAccess> dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir());
ERR_FAIL_COND(dir.is_null());
String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
if (!dir->file_exists(config_file_name)) {

View File

@ -1383,6 +1383,8 @@ void EditorExportPlatform::zip_folder_recursive(zipFile &p_zip, const String &p_
String dir = p_folder.is_empty() ? p_root_path : p_root_path.path_join(p_folder);
Ref<DirAccess> da = DirAccess::open(dir);
ERR_FAIL_COND(da.is_null());
da->list_dir_begin();
String f = da->get_next();
while (!f.is_empty()) {

View File

@ -1516,6 +1516,8 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin
} else {
// Recursively duplicate all files inside the folder.
Ref<DirAccess> old_dir = DirAccess::open(old_path);
ERR_FAIL_COND(old_dir.is_null());
Ref<FileAccess> file_access = FileAccess::create(FileAccess::ACCESS_RESOURCES);
old_dir->set_include_navigational(false);
old_dir->list_dir_begin();
@ -3308,6 +3310,8 @@ bool FileSystemDock::_get_imported_files(const String &p_path, String &r_extensi
}
Ref<DirAccess> da = DirAccess::open(p_path);
ERR_FAIL_COND_V(da.is_null(), false);
da->list_dir_begin();
String n = da->get_next();
while (!n.is_empty()) {

View File

@ -2224,6 +2224,8 @@ Error Main::setup2() {
// Editor setting class is not available, load config directly.
if (!init_use_custom_screen && (editor || project_manager) && EditorPaths::get_singleton()->are_paths_valid()) {
Ref<DirAccess> dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir());
ERR_FAIL_COND_V(dir.is_null(), FAILED);
String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
String config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
if (dir->file_exists(config_file_name)) {
@ -3295,6 +3297,8 @@ bool Main::start() {
if (sep == -1) {
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND_V(da.is_null(), false);
local_game_path = da->get_current_dir().path_join(local_game_path);
} else {
Ref<DirAccess> da = DirAccess::open(local_game_path.substr(0, sep));

View File

@ -3051,6 +3051,8 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> p_state) {
String relative_texture_dir = "textures";
String full_texture_dir = p_state->base_path.path_join(relative_texture_dir);
Ref<DirAccess> da = DirAccess::open(p_state->base_path);
ERR_FAIL_COND_V(da.is_null(), FAILED);
if (!da->dir_exists(full_texture_dir)) {
da->make_dir(full_texture_dir);
}

View File

@ -2635,6 +2635,8 @@ void EditorExportPlatformAndroid::_clear_assets_directory() {
if (da_res->dir_exists(APK_ASSETS_DIRECTORY)) {
print_verbose("Clearing APK assets directory...");
Ref<DirAccess> da_assets = DirAccess::open(APK_ASSETS_DIRECTORY);
ERR_FAIL_COND(da_assets.is_null());
da_assets->erase_contents_recursive();
da_res->remove(APK_ASSETS_DIRECTORY);
}
@ -2643,6 +2645,8 @@ void EditorExportPlatformAndroid::_clear_assets_directory() {
if (da_res->dir_exists(AAB_ASSETS_DIRECTORY)) {
print_verbose("Clearing AAB assets directory...");
Ref<DirAccess> da_assets = DirAccess::open(AAB_ASSETS_DIRECTORY);
ERR_FAIL_COND(da_assets.is_null());
da_assets->erase_contents_recursive();
da_res->remove(AAB_ASSETS_DIRECTORY);
}

View File

@ -1389,6 +1389,8 @@ Error ResourceLoaderText::save_as_binary(const String &p_path) {
wf->store_buffer(data.ptr(), data.size());
{
Ref<DirAccess> dar = DirAccess::open(temp_file.get_base_dir());
ERR_FAIL_COND_V(dar.is_null(), FAILED);
dar->remove(temp_file);
}

View File

@ -70,6 +70,8 @@ Error MovieWriterPNGWAV::write_begin(const Size2i &p_movie_size, uint32_t p_fps,
//Remove existing files before writing anew
uint32_t idx = 0;
Ref<DirAccess> d = DirAccess::open(base_path.get_base_dir());
ERR_FAIL_COND_V(d.is_null(), FAILED);
String file = base_path.get_file();
while (true) {
String path = file + zeros_str(idx) + ".png";