Rename the game to Emberwild (data copied from the old folder)
This commit is contained in:
52
scripts/core/boot.gd
Normal file
52
scripts/core/boot.gd
Normal file
@@ -0,0 +1,52 @@
|
||||
extends Node
|
||||
## Autoload "Boot", first in the list: one-off start-up housekeeping that has
|
||||
## to happen before anything reads user://.
|
||||
##
|
||||
## The game was called "Valheimlike" until it became "Emberwild". Godot names
|
||||
## the user-data folder after the project, so the rename moved it from
|
||||
## .../app_userdata/Valheimlike to .../app_userdata/Emberwild. The first time
|
||||
## Emberwild starts, this copies saved worlds, your identity (key, name, look)
|
||||
## and server settings across. It copies rather than moves, so the old folder
|
||||
## stays as a backup, and it never overwrites anything already in the new
|
||||
## folder. Test folders (test_*) and logs are skipped.
|
||||
|
||||
const OLD_NAME := "Valheimlike"
|
||||
const MARKER := "migrated_from_valheimlike.txt"
|
||||
const SKIP := ["logs", "shader_cache", "vulkan", "test_worlds", "test_net"]
|
||||
|
||||
var copied := 0
|
||||
|
||||
func _enter_tree() -> void:
|
||||
migrate_user_data()
|
||||
|
||||
## Returns the number of files copied (0 if there was nothing to do).
|
||||
func migrate_user_data() -> int:
|
||||
var new_dir := OS.get_user_data_dir()
|
||||
var old_dir := new_dir.get_base_dir().path_join(OLD_NAME)
|
||||
if new_dir == old_dir or not DirAccess.dir_exists_absolute(old_dir):
|
||||
return 0
|
||||
if FileAccess.file_exists(new_dir.path_join(MARKER)):
|
||||
return 0
|
||||
copied = 0
|
||||
_copy_tree(old_dir, new_dir)
|
||||
var f := FileAccess.open(new_dir.path_join(MARKER), FileAccess.WRITE)
|
||||
if f != null:
|
||||
f.store_string("Copied %d files from %s on %s. The old folder was left as it was.\n" % [
|
||||
copied, old_dir, Time.get_datetime_string_from_system()])
|
||||
if copied > 0:
|
||||
print("[boot] moved to the new name: copied %d files from %s" % [copied, old_dir])
|
||||
return copied
|
||||
|
||||
func _copy_tree(from: String, to: String) -> void:
|
||||
DirAccess.make_dir_recursive_absolute(to)
|
||||
var da := DirAccess.open(from)
|
||||
if da == null:
|
||||
return
|
||||
for f in da.get_files():
|
||||
var dst := to.path_join(f)
|
||||
if not FileAccess.file_exists(dst) and DirAccess.copy_absolute(from.path_join(f), dst) == OK:
|
||||
copied += 1
|
||||
for d in da.get_directories():
|
||||
if d in SKIP or d.begins_with("test_"):
|
||||
continue
|
||||
_copy_tree(from.path_join(d), to.path_join(d))
|
||||
Reference in New Issue
Block a user