delete_dir

This commit is contained in:
Adrien Ufferte
2025-07-08 15:53:41 +02:00
parent 01083b5404
commit a5e50e3206
3 changed files with 22 additions and 23 deletions
@@ -89,7 +89,7 @@ func _ready() -> void:
# Delete the files from old language pack
if DirAccess.dir_exists_absolute(current_language_path):
_delete_dir(current_language_path)
Utils.delete_dir(current_language_path)
# Download the pack
http_request.set_download_file(USER_LANGUAGE_RESOURCES_PATH.path_join(device_language + ".zip"))
@@ -196,7 +196,7 @@ func delete_directory_recursive(path: String) -> void:
dir.list_dir_end()
# Supprime le dossier lui-même
# Delete the folder itself
err = DirAccess.remove_absolute(path)
if err != OK:
Logger.error("PackageDownloader: Error " + error_string(err) + " while deleting folder: %s" % path)
@@ -204,20 +204,12 @@ func delete_directory_recursive(path: String) -> void:
Logger.info("PackageDownloader: ✅ Folder deleted: %s" % path)
func _delete_dir(path: String) -> void:
var dir: DirAccess = DirAccess.open(path)
for file: String in dir.get_files():
dir.remove(file)
for subfolder: String in dir.get_directories():
_delete_dir(path.path_join(subfolder))
dir.remove(subfolder)
func _show_error(error: int) -> void:
error_popup.content_text = ERROR_MESSAGES[error]
error_popup.show()
func _go_to_main_menu() -> void:
get_tree().change_scene_to_file(MAIN_MENU_SCENE_PATH)
+4 -12
View File
@@ -52,7 +52,7 @@ func purge_user_folders_if_needed() -> void:
while file_name != "":
if dir.current_is_dir() and file_name != "." and file_name != "..":
var full_path: String = "user://".path_join(file_name)
_delete_dir(full_path)
Utils.delete_dir(full_path)
var err: Error = DirAccess.remove_absolute(full_path)
if err != OK:
Logger.error("UserDataManager: Failed to delete folder %s. Error %s" % [full_path, error_string(err)])
@@ -222,7 +222,7 @@ func logout() -> void:
func delete_teacher_data() -> void:
if DirAccess.dir_exists_absolute(get_teacher_folder()):
_delete_dir(get_teacher_folder())
Utils.delete_dir(get_teacher_folder())
func student_exists(code: String) -> bool:
if not _device_settings:
@@ -408,7 +408,7 @@ func _delete_inexistants_students_saves() -> void:
for device: String in directories:
# If the device does not exists, delete it
if int(device) not in teacher_settings.students.keys():
_delete_dir(path.path_join(device))
Utils.delete_dir(path.path_join(device))
dirc.remove(device)
continue
@@ -426,7 +426,7 @@ func _delete_inexistants_students_saves() -> void:
break
# If the code doesn't exists in the configuration, delete the folder
if not exists:
_delete_dir(path.path_join(device).path_join(language).path_join(p_student))
Utils.delete_dir(path.path_join(device).path_join(language).path_join(p_student))
language_dir.remove(p_student)
func update_configuration(configuration: Dictionary) -> bool:
@@ -720,14 +720,6 @@ func is_speech_played(speech: String) -> bool:
#region utils
func _delete_dir(path: String) -> void:
var dir: DirAccess = DirAccess.open(path)
for file: String in dir.get_files():
dir.remove(file)
for subfolder: String in dir.get_directories():
_delete_dir(path.path_join(subfolder))
dir.remove(subfolder)
func move_user_device_folder(old_device: String, new_device: String, student_code: int) -> void:
var parent_dir_path: String = "user://".path_join(_device_settings.teacher)
var parent_dir: DirAccess = DirAccess.open(parent_dir_path)
+15
View File
@@ -14,3 +14,18 @@ func sort_by_property(node_a: Node, node_b: Node, property_name: String) -> bool
func disconnect_all(signals: Signal) -> void:
for connection: Dictionary in signals.get_connections():
(connection["signal"] as Signal).disconnect(connection["callable"] as Callable)
func delete_dir(path: String) -> void:
var dir: DirAccess = DirAccess.open(path)
var error: Error = DirAccess.get_open_error()
if error != OK:
Logger.warn("Utils: delete_dir error while opening path %s: %s" % [path, error_string(error)])
return
if dir == null:
Logger.warn("Utils: delete_dir called on missing path %s" % path)
return
for file: String in dir.get_files():
dir.remove(file)
for subfolder: String in dir.get_directories():
delete_dir(path.path_join(subfolder))
dir.remove(subfolder)