delete_dir
This commit is contained in:
@@ -89,7 +89,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
# Delete the files from old language pack
|
# Delete the files from old language pack
|
||||||
if DirAccess.dir_exists_absolute(current_language_path):
|
if DirAccess.dir_exists_absolute(current_language_path):
|
||||||
_delete_dir(current_language_path)
|
Utils.delete_dir(current_language_path)
|
||||||
|
|
||||||
# Download the pack
|
# Download the pack
|
||||||
http_request.set_download_file(USER_LANGUAGE_RESOURCES_PATH.path_join(device_language + ".zip"))
|
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()
|
dir.list_dir_end()
|
||||||
|
|
||||||
# Supprime le dossier lui-même
|
# Delete the folder itself
|
||||||
err = DirAccess.remove_absolute(path)
|
err = DirAccess.remove_absolute(path)
|
||||||
if err != OK:
|
if err != OK:
|
||||||
Logger.error("PackageDownloader: Error " + error_string(err) + " while deleting folder: %s" % path)
|
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)
|
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:
|
func _show_error(error: int) -> void:
|
||||||
error_popup.content_text = ERROR_MESSAGES[error]
|
error_popup.content_text = ERROR_MESSAGES[error]
|
||||||
error_popup.show()
|
error_popup.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _go_to_main_menu() -> void:
|
func _go_to_main_menu() -> void:
|
||||||
get_tree().change_scene_to_file(MAIN_MENU_SCENE_PATH)
|
get_tree().change_scene_to_file(MAIN_MENU_SCENE_PATH)
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func purge_user_folders_if_needed() -> void:
|
|||||||
while file_name != "":
|
while file_name != "":
|
||||||
if dir.current_is_dir() and file_name != "." and file_name != "..":
|
if dir.current_is_dir() and file_name != "." and file_name != "..":
|
||||||
var full_path: String = "user://".path_join(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)
|
var err: Error = DirAccess.remove_absolute(full_path)
|
||||||
if err != OK:
|
if err != OK:
|
||||||
Logger.error("UserDataManager: Failed to delete folder %s. Error %s" % [full_path, error_string(err)])
|
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:
|
func delete_teacher_data() -> void:
|
||||||
if DirAccess.dir_exists_absolute(get_teacher_folder()):
|
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:
|
func student_exists(code: String) -> bool:
|
||||||
if not _device_settings:
|
if not _device_settings:
|
||||||
@@ -408,7 +408,7 @@ func _delete_inexistants_students_saves() -> void:
|
|||||||
for device: String in directories:
|
for device: String in directories:
|
||||||
# If the device does not exists, delete it
|
# If the device does not exists, delete it
|
||||||
if int(device) not in teacher_settings.students.keys():
|
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)
|
dirc.remove(device)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -426,7 +426,7 @@ func _delete_inexistants_students_saves() -> void:
|
|||||||
break
|
break
|
||||||
# If the code doesn't exists in the configuration, delete the folder
|
# If the code doesn't exists in the configuration, delete the folder
|
||||||
if not exists:
|
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)
|
language_dir.remove(p_student)
|
||||||
|
|
||||||
func update_configuration(configuration: Dictionary) -> bool:
|
func update_configuration(configuration: Dictionary) -> bool:
|
||||||
@@ -720,14 +720,6 @@ func is_speech_played(speech: String) -> bool:
|
|||||||
|
|
||||||
#region utils
|
#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:
|
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_path: String = "user://".path_join(_device_settings.teacher)
|
||||||
var parent_dir: DirAccess = DirAccess.open(parent_dir_path)
|
var parent_dir: DirAccess = DirAccess.open(parent_dir_path)
|
||||||
|
|||||||
@@ -14,3 +14,18 @@ func sort_by_property(node_a: Node, node_b: Node, property_name: String) -> bool
|
|||||||
func disconnect_all(signals: Signal) -> void:
|
func disconnect_all(signals: Signal) -> void:
|
||||||
for connection: Dictionary in signals.get_connections():
|
for connection: Dictionary in signals.get_connections():
|
||||||
(connection["signal"] as Signal).disconnect(connection["callable"] as Callable)
|
(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)
|
||||||
|
|||||||
Reference in New Issue
Block a user