feat: added FileManager object

pull/2/head
Евгений Сугоняко 2024-05-03 20:17:12 +03:00
parent 64edcc950e
commit d5844ae54b
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
class_name File_Manager extends Object
"""
File manager
"""
var base_dir = OS.get_executable_path().get_base_dir()
var LOG_FILE = base_dir.path_join("server.log")
#--------------------------------------------------------------------------------------------------#
# Methods
func set_base_dir(dir) -> void:
base_dir = dir
LOG_FILE = base_dir.path_join("server.log")
func add_to_log(_text : String) -> void:
if Server.settings.MakeLogs:
__create_file_is_not_exist(LOG_FILE)
var file = FileAccess.open(LOG_FILE, FileAccess.READ_WRITE)
file.store_line(
file.get_as_text() +
'[ %s %s ] %s' % [
Time.get_date_string_from_system(),
Time.get_time_string_from_system(),
_text
]
)
file.close()
#--------------------------------------------------------------------------------------------------#
# Functions
func __create_file_is_not_exist(_file) -> void:
if !FileAccess.file_exists(_file):
var file := FileAccess.open(_file, FileAccess.WRITE)
file.close()