1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-30 23:19:49 +00:00

Made pxo saving a bit safer

It now first attempts to serialize the project data and turn them to JSON, and then opens the file. This is a lto safer because, if a crash happens in the serialization, the file is not already open, and therefore it does not get corrupt. Earlier, if a crash happened, the file would be empty. This meant that if that file existed previously, all of the data would be lost.
This commit is contained in:
OverloadedOrama 2020-10-20 03:27:38 +03:00
parent 852365c38f
commit e94bcf50e0
5 changed files with 58 additions and 50 deletions

View file

@ -113,7 +113,7 @@ boot_splash/bg_color=Color( 0.145098, 0.145098, 0.164706, 1 )
config/icon="res://assets/graphics/icons/icon.png"
config/macos_native_icon="res://assets/graphics/icons/icon.icns"
config/windows_native_icon="res://assets/graphics/icons/icon.ico"
config/Version="v0.8.1-stable"
config/Version="v0.8.2-dev"
[audio]

View file

@ -265,6 +265,15 @@ func open_old_pxo_file(file : File, new_project : Project, first_line : String)
func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true, project : Project = Global.current_project) -> void:
var serialized_data = project.serialize()
if !serialized_data:
Global.notification_label(tr("File failed to save. Serialization to dictionary failed."))
return
var to_save = JSON.print(serialized_data)
if !to_save:
Global.notification_label(tr("File failed to save. Dictionary to JSON failed."))
return
var file : File = File.new()
var err
if use_zstd_compression:
@ -272,12 +281,15 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
else:
err = file.open(path, File.WRITE)
if err == OK:
if err != OK:
Global.notification_label(tr("File failed to save. Error code %s") % err)
file.close()
return
if !autosave:
project.name = path.get_file()
current_save_paths[Global.current_project_index] = path
var to_save = JSON.print(project.serialize())
file.store_line(to_save)
for frame in project.frames:
for cel in frame.cels:
@ -316,10 +328,6 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
Export.was_exported = false
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
else:
Global.notification_label(tr("File failed to save. Error code %s") % err)
file.close()
func open_image_as_new_tab(path : String, image : Image) -> void:
var project = Project.new([], path.get_file(), image.get_size())