-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate data from executable #90
base: master
Are you sure you want to change the base?
Changes from 12 commits
eb0f6b9
49aa2f9
e6756df
ef8282b
c4677f1
0b44e19
01d7e2d
0736cca
e484a6d
6df9644
6a9f711
d16fc59
ba74a8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ extends Node | |
|
||
signal status_message | ||
|
||
var own_dir: String setget , _get_own_dir | ||
var catapult_dir: String setget _set_catapult_dir , _get_catapult_dir | ||
var settings_dir: String setget _set_settings_dir , _get_settings_dir | ||
var installs_summary: Dictionary setget , _get_installs_summary | ||
var game_dir: String setget , _get_game_dir | ||
var next_install_dir: String setget , _get_next_install_dir | ||
var next_data_dir: String setget , _get_next_data_dir | ||
var userdata: String setget , _get_userdata_dir | ||
var config: String setget , _get_config_dir | ||
var savegames: String setget , _get_savegame_dir | ||
|
@@ -30,19 +31,101 @@ var _last_active_install_name := "" | |
var _last_active_install_dir := "" | ||
|
||
|
||
func _get_own_dir() -> String: | ||
func _init() -> void: | ||
|
||
catapult_dir = _determine_catapult_dir() | ||
settings_dir = _determine_settings_dir() | ||
|
||
Settings.load_settings(settings_dir) | ||
var inst_dir_setting = Settings.read("installation_dir") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be a hard-coded default value for |
||
inst_dir_setting = inst_dir_setting.replace("~", OS.get_environment("HOME")) | ||
|
||
if inst_dir_setting != null: | ||
var d = Directory.new() | ||
|
||
var error = 0 | ||
if not d.dir_exists(inst_dir_setting): | ||
error = d.make_dir_recursive(inst_dir_setting) | ||
|
||
if not error: | ||
catapult_dir = inst_dir_setting | ||
|
||
|
||
func _determine_catapult_dir() -> String: | ||
|
||
for arg in OS.get_cmdline_args(): | ||
if arg.find("=") > -1: # if arg is a key-value pair | ||
var arg_pair = arg.split("=") | ||
if arg_pair[0] == "--catapult_dir_abs": | ||
var dirname = arg_pair[1] | ||
|
||
if not dirname.is_abs_path(): | ||
# relative paths are not supported, fallback to executable path | ||
Status.post(tr("msg_path_not_absolute") % dirname, Enums.MSG_ERROR) | ||
break | ||
|
||
# Ensure that catapult_dir_abs exists | ||
var d = Directory.new() | ||
if not d.dir_exists(dirname): | ||
var error = d.make_dir_recursive(dirname) | ||
if error: | ||
# something went wrong, fallback to executable path | ||
Status.post(tr("msg_cannot_create_target_dir") % [dirname, error], Enums.MSG_ERROR) | ||
break | ||
|
||
return dirname | ||
|
||
return OS.get_executable_path().get_base_dir() | ||
|
||
|
||
func _determine_settings_dir() -> String: | ||
|
||
var global_settings_dir: String | ||
|
||
match OS.get_name(): | ||
"X11": | ||
var xdg_config_home = OS.get_environment("XDG_CONFIG_HOME") | ||
var config_home = xdg_config_home if not xdg_config_home.empty() else OS.get_environment("HOME").plus_file(".config") | ||
global_settings_dir = config_home.plus_file("catapult/") | ||
"Windows": | ||
global_settings_dir = OS.get_environment("USERPROFILE").plus_file("AppData/Local/Catapult/") | ||
_: | ||
return catapult_dir | ||
|
||
if Settings.dir_contains_settings(global_settings_dir): | ||
return global_settings_dir | ||
else: | ||
return catapult_dir | ||
|
||
|
||
func _set_catapult_dir(path: String) -> void: | ||
|
||
catapult_dir = path | ||
|
||
|
||
func _get_catapult_dir() -> String: | ||
|
||
return catapult_dir | ||
|
||
|
||
func _set_settings_dir(path: String) -> void: | ||
|
||
settings_dir = path | ||
|
||
|
||
func _get_settings_dir() -> String: | ||
|
||
return settings_dir | ||
|
||
|
||
func _get_installs_summary() -> Dictionary: | ||
|
||
var result = {} | ||
var d = Directory.new() | ||
|
||
for game in ["dda", "bn"]: | ||
var installs = {} | ||
var base_dir = Paths.own_dir.plus_file(game) | ||
var base_dir = Paths.catapult_dir.plus_file(game) | ||
for subdir in FS.list_dir(base_dir): | ||
var info_file = base_dir.plus_file(subdir).plus_file(Helpers.INFO_FILENAME) | ||
if d.file_exists(info_file): | ||
|
@@ -66,7 +149,7 @@ func _get_game_dir() -> String: | |
var active_name = Settings.read("active_install_" + Settings.read("game")) | ||
|
||
if active_name == "": | ||
return _get_next_install_dir() | ||
return _get_next_data_dir() | ||
elif active_name == _last_active_install_name: | ||
return _last_active_install_dir | ||
else: | ||
|
@@ -76,7 +159,7 @@ func _get_game_dir() -> String: | |
func _find_active_game_dir() -> String: | ||
|
||
var d = Directory.new() | ||
var base_dir = _get_own_dir().plus_file(Settings.read("game")) | ||
var base_dir = _get_catapult_dir().plus_file(Settings.read("game")) | ||
for subdir in FS.list_dir(base_dir): | ||
var curr_dir = base_dir.plus_file(subdir) | ||
var info_file = curr_dir.plus_file("catapult_install_info.json") | ||
|
@@ -89,11 +172,11 @@ func _find_active_game_dir() -> String: | |
return "" | ||
|
||
|
||
func _get_next_install_dir() -> String: | ||
func _get_next_data_dir() -> String: | ||
# Finds a suitable directory name for a new game installation in the | ||
# multi-install system. The names follow the pattern "game0, game1, ..." | ||
|
||
var base_dir := _get_own_dir().plus_file(Settings.read("game")) | ||
var base_dir := _get_catapult_dir().plus_file(Settings.read("game")) | ||
var dir_number := 0 | ||
var d := Directory.new() | ||
while d.dir_exists(base_dir.plus_file("game" + str(dir_number))): | ||
|
@@ -103,7 +186,7 @@ func _get_next_install_dir() -> String: | |
|
||
func _get_userdata_dir() -> String: | ||
|
||
return _get_own_dir().plus_file(Settings.read("game")).plus_file("userdata") | ||
return _get_catapult_dir().plus_file(Settings.read("game")).plus_file("userdata") | ||
|
||
|
||
func _get_config_dir() -> String: | ||
|
@@ -168,19 +251,19 @@ func _get_graveyard_dir() -> String: | |
|
||
func _get_modrepo_dir() -> String: | ||
|
||
return _get_own_dir().plus_file(Settings.read("game")).plus_file("mod_repo") | ||
return _get_catapult_dir().plus_file(Settings.read("game")).plus_file("mod_repo") | ||
|
||
|
||
func _get_tmp_dir() -> String: | ||
|
||
return _get_own_dir().plus_file(Settings.read("game")).plus_file("tmp") | ||
return _get_catapult_dir().plus_file(Settings.read("game")).plus_file("tmp") | ||
|
||
|
||
func _get_utils_dir() -> String: | ||
|
||
return _get_own_dir().plus_file("utils") | ||
return _get_catapult_dir().plus_file("utils") | ||
|
||
|
||
func _get_save_backups_dir() -> String: | ||
|
||
return _get_own_dir().plus_file(Settings.read("game")).plus_file("save_backups") | ||
return _get_catapult_dir().plus_file(Settings.read("game")).plus_file("save_backups") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"keys","en" | ||
, | ||
"msg_path_not_absolute","%s is not an absolute path. Falling back to executable path" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[remap] | ||
|
||
importer="csv_translation" | ||
type="Translation" | ||
|
||
[deps] | ||
|
||
files=[ "res://text/cs/path_helper.en.translation" ] | ||
|
||
source_file="res://text/cs/path_helper.csv" | ||
dest_files=[ "res://text/cs/path_helper.en.translation" ] | ||
|
||
[params] | ||
|
||
compress=true | ||
delimiter=0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"keys","en" | ||
, | ||
"msg_path_not_absolute","%s is not an absolute path. Falling back to executable path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed, it is called automatically when
Settings.read
is called for the first time.