Skip to content

Commit

Permalink
Copy data to 'user://'-folder on Android, iOS and Web
Browse files Browse the repository at this point in the history
  • Loading branch information
2shady4u committed Jan 31, 2024
1 parent f31d1ff commit ebb0c5e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions demo/database.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ signal output_received(text)
signal texture_received(texture)

func _ready():
if OS.get_name() in ["Android", "iOS", "Web"]:
copy_data_to_user()
db_name = "user://data/test"
json_name = "user://data/test_backup"

# Enable/disable examples here:
example_of_basic_database_querying()
example_of_in_memory_and_foreign_key_support()
Expand All @@ -39,6 +44,25 @@ func cprint(text : String) -> void:
print(text)
emit_signal("output_received", text)

func copy_data_to_user() -> void:
var data_path := "res://data"
var copy_path := "user://data"

DirAccess.make_dir_absolute(copy_path)
var dir = DirAccess.open(data_path)
if dir:
dir.list_dir_begin();
var file_name = dir.get_next()
while (file_name != ""):
if dir.current_is_dir():
pass
else:
cprint("Copying " + file_name + " to /user-folder")
dir.copy(data_path + "/" + file_name, copy_path + "/" + file_name)
file_name = dir.get_next()
else:
cprint("An error occurred when trying to access the path.")

# Basic example that goes over all the basic features available in the addon, such
# as creating and dropping tables, inserting and deleting rows and doing more elementary
# PRAGMA queries.
Expand Down

0 comments on commit ebb0c5e

Please sign in to comment.