I would say brilliant, you are a kind of genius.
There were still a couple of errors:
If setting.ini
deleted:

if setting.ini
blanked:

I fixed these errors by adding two nests:
if settings_file.file_exists(SETTINGS_FILE_PATH):
This that detect the file settings.ini
at beginning of load_settings
, and if not exist return else
an .write
auto-save settings.in
i newfile with default valutes and return
again up.
if settings_file.get_len() != 0:
And this for detecting a blank setting.ini
with else
that do save_settings
(File exist, so can save it default values).
func load_settings() -> void:
#read the settings file bytes
if settings_file.file_exists(SETTINGS_FILE_PATH):
settings_file.open(SETTINGS_FILE_PATH, File.READ)
if settings_file.get_len() != 0:
var bytes = settings_file.get_buffer (settings_file.get_len())
settings_file.close()
#compute the hash of file bytes
var ctx = HashingContext.new()
ctx.start(HashingContext.HASH_SHA256)
ctx.update(bytes)
var actualHash = ctx.finish()
if hash_file.file_exists(HASH_FILE_PATH):
#open and read the expected hash
hash_file.open(HASH_FILE_PATH, File.READ)
var expectedHash = hash_file.get_buffer(hash_file.get_len())
hash_file.close()
if compareHashes(actualHash,expectedHash):
print("The file hasn't been altered")
settings_file.open(SETTINGS_FILE_PATH, File.READ)
game_version = settings_file.get_var()
screen_resolution = settings_file.get_var()
max_resolution = settings_file.get_var()
settings_file.close()
else:
print("The file has changed since we last saved it")
#Hash.ini changed
#Settings.ini changed/deleted
else:
print("The file has changed since we last saved it (missing hash file)")
#hash file is missing, so consider this a change to seetings
else:
#Setting.ini blank
save_settings()
else:
settings_file.open(SETTINGS_FILE_PATH, File.WRITE)
settings_file.store_var(game_version)
settings_file.store_var(screen_resolution)
settings_file.store_var(max_resolution)
settings_file.close()
return