Skip to content
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

Add proxy support and cache options; Refine chinese locales. #157

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 63 additions & 7 deletions scenes/Catapult.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -1113,17 +1113,31 @@ margin_bottom = 290.0
hint_tooltip = "tooltip_install_archived_mods"
text = "cbtn_install_archived_mods"

[node name="ShowDebug" type="CheckButton" parent="Main/Tabs/Settings"]
[node name="KeepCache" type="CheckButton" parent="Main/Tabs/Settings"]
margin_top = 292.0
margin_right = 577.0
margin_bottom = 320.0
hint_tooltip = "tooltip_keep_cache"
text = "cbtn_keep_cache"

[node name="IgnoreCache" type="CheckButton" parent="Main/Tabs/Settings"]
margin_top = 322.0
margin_right = 577.0
margin_bottom = 350.0
hint_tooltip = "tooltip_ignore_cache"
text = "cbtn_ignore_cache"

[node name="ShowDebug" type="CheckButton" parent="Main/Tabs/Settings"]
margin_top = 352.0
margin_right = 577.0
margin_bottom = 380.0
hint_tooltip = "tooltip_debug_mode"
text = "cbtn_debug_mode"

[node name="NumReleases" type="HBoxContainer" parent="Main/Tabs/Settings"]
margin_top = 322.0
margin_top = 382.0
margin_right = 577.0
margin_bottom = 346.0
margin_bottom = 406.0
hint_tooltip = "tooltip_num_releases_to_request"

[node name="Label" type="Label" parent="Main/Tabs/Settings/NumReleases"]
Expand All @@ -1141,9 +1155,9 @@ value = 30.0
rounded = true

[node name="NumPrs" type="HBoxContainer" parent="Main/Tabs/Settings"]
margin_top = 348.0
margin_top = 408.0
margin_right = 577.0
margin_bottom = 372.0
margin_bottom = 432.0
hint_tooltip = "tooltip_num_prs_to_request"

[node name="Label" type="Label" parent="Main/Tabs/Settings/NumPrs"]
Expand All @@ -1161,10 +1175,47 @@ step = 10.0
value = 100.0
rounded = true

[node name="ProxySettings" type="HBoxContainer" parent="Main/Tabs/Settings"]
margin_top = 434.0
margin_right = 577.0
margin_bottom = 458.0
hint_tooltip = "tooltip_proxy_settings"

[node name="Label" type="Label" parent="Main/Tabs/Settings/ProxySettings"]
margin_right = 120.0
margin_bottom = 24.0
text = "lbl_proxy_settings"

[node name="obtnProxyOption" type="OptionButton" parent="Main/Tabs/Settings/ProxySettings"]
margin_left = 127.0
margin_right = 295.0
margin_bottom = 24.0
hint_tooltip = "tooltip_proxy_options"
size_flags_horizontal = 10
size_flags_stretch_ratio = 20.0
text = "obtn_proxy_option_off"
items = [ "obtn_proxy_option_off", null, false, 0, null, "obtn_proxy_option_on", null, false, 1, null, "obtn_proxy_option_download", null, false, 2, null ]
selected = 0

[node name="leProxyHost" type="LineEdit" parent="Main/Tabs/Settings/ProxySettings"]
margin_left = 301.0
margin_right = 471.0
margin_bottom = 24.0
rect_min_size = Vector2( 170, 0 )
size_flags_horizontal = 10
placeholder_text = "localhost"

[node name="sbProxyPort" type="SpinBox" parent="Main/Tabs/Settings/ProxySettings"]
margin_left = 477.0
margin_right = 577.0
margin_bottom = 24.0
size_flags_horizontal = 10
max_value = 65535.0

[node name="ScaleOverride" type="HBoxContainer" parent="Main/Tabs/Settings"]
margin_top = 374.0
margin_top = 460.0
margin_right = 577.0
margin_bottom = 402.0
margin_bottom = 488.0
hint_tooltip = "tooltip_ui_scale_override"
__meta__ = {
"_edit_use_anchors_": false
Expand Down Expand Up @@ -1401,9 +1452,14 @@ __meta__ = {
[connection signal="toggled" from="Main/Tabs/Settings/AlwaysShowInstalls" to="Main/Tabs/Settings" method="_on_AlwaysShowInstalls_toggled"]
[connection signal="toggled" from="Main/Tabs/Settings/ShowObsoleteMods" to="Main/Tabs/Settings" method="_on_ShowObsoleteMods_toggled"]
[connection signal="toggled" from="Main/Tabs/Settings/InstallArchivedMods" to="Main/Tabs/Settings" method="_on_InstallArchivedMods_toggled"]
[connection signal="toggled" from="Main/Tabs/Settings/KeepCache" to="Main/Tabs/Settings" method="_on_KeepCache_toggled"]
[connection signal="toggled" from="Main/Tabs/Settings/IgnoreCache" to="Main/Tabs/Settings" method="_on_IgnoreCache_toggled"]
[connection signal="toggled" from="Main/Tabs/Settings/ShowDebug" to="Main/Tabs/Settings" method="_on_ShowDebug_toggled"]
[connection signal="value_changed" from="Main/Tabs/Settings/NumReleases/sbNumReleases" to="Main/Tabs/Settings" method="_on_sbNumReleases_value_changed"]
[connection signal="value_changed" from="Main/Tabs/Settings/NumPrs/sbNumPRs" to="Main/Tabs/Settings" method="_on_sbNumPRs_value_changed"]
[connection signal="item_selected" from="Main/Tabs/Settings/ProxySettings/obtnProxyOption" to="Main/Tabs/Settings" method="_on_obtnProxyOption_item_selected"]
[connection signal="text_changed" from="Main/Tabs/Settings/ProxySettings/leProxyHost" to="Main/Tabs/Settings" method="_on_leProxyHost_text_changed"]
[connection signal="value_changed" from="Main/Tabs/Settings/ProxySettings/sbProxyPort" to="Main/Tabs/Settings" method="_on_sbProxyPort_value_changed"]
[connection signal="toggled" from="Main/Tabs/Settings/ScaleOverride/cbScaleOverrideEnable" to="Main/Tabs/Settings" method="_on_cbScaleOverrideEnable_toggled"]
[connection signal="value_changed" from="Main/Tabs/Settings/ScaleOverride/sbScaleOverride" to="Main/Tabs/Settings" method="_on_sbScaleOverride_value_changed"]
[connection signal="pressed" from="Main/Tabs/Debug/Button" to="Main/Tabs/Debug" method="_on_Button_pressed"]
Expand Down
12 changes: 12 additions & 0 deletions scripts/ChangelogDialod.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@ func open() -> void:
popup_centered_ratio(0.9)


func _update_proxy(http: HTTPRequest) -> void:
if Settings.read("proxy_option") == "on":
var host = Settings.read("proxy_host")
var port = Settings.read("proxy_port") as int
http.set_http_proxy(host, port)
http.set_https_proxy(host, port)
else:
http.set_http_proxy("", -1)
http.set_https_proxy("", -1)


func download_pull_requests():
var game_selected = Settings.read("game")
var prs = Settings.read("num_prs_to_request")
var url = _PR_URL[Settings.read("game")]
url += "+is%3Apr+is%3Amerged&per_page=" + prs
var headers = ["user-agent: CatapultGodotApp"]
_pr_data = tr("str_fetching_changes")
_update_proxy(_pullRequests)
_pullRequests.request(url, headers)
_changelogTextBox.clear()
_changelogTextBox.append_bbcode(_pr_data)
Expand Down
11 changes: 7 additions & 4 deletions scripts/ModManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,17 @@ func retrieve_kenan_pack() -> void:
emit_signal("modpack_retrieval_started")
Status.post(tr("msg_getting_kenan_pack") % game.to_upper())

Downloader.download_file(pack["url"], Paths.own_dir, pack["filename"])
yield(Downloader, "download_finished")
var archive = Paths.cache_dir.plus_file(pack["filename"])

if Settings.read("ignore_cache") or not Directory.new().file_exists(archive):
Downloader.download_file(pack["url"], Paths.cache_dir, pack["filename"])
yield(Downloader, "download_finished")

var archive = Paths.own_dir.plus_file(pack["filename"])
if Directory.new().file_exists(archive):
FS.extract(archive, Paths.tmp_dir)
yield(FS, "extract_done")
Directory.new().remove(archive)
if not Settings.read("keep_cache"):
Directory.new().remove(archive)

Status.post(tr("msg_wiping_mod_repo"))
if (Directory.new().dir_exists(Paths.mod_repo)):
Expand Down
11 changes: 7 additions & 4 deletions scripts/ReleaseInstaller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ func install_release(release_info: Dictionary, game: String, update_in: String =
else:
Status.post(tr("msg_installing_game") % release_info["name"])

Downloader.download_file(release_info["url"], Paths.own_dir, release_info["filename"])
yield(Downloader, "download_finished")
var archive: String = Paths.cache_dir.plus_file(release_info["filename"])

if Settings.read("ignore_cache") or not Directory.new().file_exists(archive):
Downloader.download_file(release_info["url"], Paths.cache_dir, release_info["filename"])
yield(Downloader, "download_finished")

var archive: String = Paths.own_dir.plus_file(release_info["filename"])
if Directory.new().file_exists(archive):

FS.extract(archive, Paths.tmp_dir)
yield(FS, "extract_done")
Directory.new().remove(archive)
if not Settings.read("keep_cache"):
Directory.new().remove(archive)

if FS.last_extract_result == 0:

Expand Down
36 changes: 16 additions & 20 deletions scripts/ReleaseManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,20 @@ func _get_query_string() -> String:
return "?per_page=%s" % num_per_page


func _request_dda() -> void:
emit_signal("started_fetching_releases")
$HTTPRequest_DDA.request(_RELEASE_URLS["dda-experimental"] + _get_query_string())


func _request_bn() -> void:
emit_signal("started_fetching_releases")
$HTTPRequest_BN.request(_RELEASE_URLS["bn-experimental"] + _get_query_string())


func _request_eod() -> void:
emit_signal("started_fetching_releases")
$HTTPRequest_EOD.request(_RELEASE_URLS["eod-experimental"] + _get_query_string())

func _update_proxy(http: HTTPRequest) -> void:
if Settings.read("proxy_option") == "on":
var host = Settings.read("proxy_host")
var port = Settings.read("proxy_port") as int
http.set_http_proxy(host, port)
http.set_https_proxy(host, port)
else:
http.set_http_proxy("", -1)
http.set_https_proxy("", -1)

func _request_tish() -> void:
func _request_releases(http: HTTPRequest, release: String) -> void:
emit_signal("started_fetching_releases")
$HTTPRequest_TISH.request(_RELEASE_URLS["tish-experimental"] + _get_query_string())
_update_proxy(http)
http.request(_RELEASE_URLS[release] + _get_query_string())


func _on_request_completed_dda(result: int, response_code: int,
Expand Down Expand Up @@ -387,7 +383,7 @@ func fetch(release_key: String) -> void:
emit_signal("done_fetching_releases")
"dda-experimental":
Status.post(tr("msg_fetching_releases_dda"))
_request_dda()
_request_releases($HTTPRequest_DDA, "dda-experimental")
"bn-stable":
match _platform:
"linux":
Expand All @@ -397,13 +393,13 @@ func fetch(release_key: String) -> void:
emit_signal("done_fetching_releases")
"bn-experimental":
Status.post(tr("msg_fetching_releases_bn"))
_request_bn()
_request_releases($HTTPRequest_BN, "bn-experimental")
"eod-experimental":
Status.post(tr("msg_fetching_releases_eod"))
_request_eod()
_request_releases($HTTPRequest_EOD, "eod-experimental")
"tish-experimental":
Status.post(tr("msg_fetching_releases_tish"))
_request_tish()
_request_releases($HTTPRequest_TISH, "tish-experimental")
_:
Status.post(tr("msg_invalid_fetch_func_param") % release_key, Enums.MSG_ERROR)

32 changes: 32 additions & 0 deletions scripts/SettingsUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var _themes := [
"Solarized_Light.res",
]

var _proxy_options := ["off", "on", "download"]

onready var _root = $"/root/Catapult"
onready var _tabs = $"/root/Catapult/Main/Tabs"
onready var _debug_ui = $"/root/Catapult/Main/Tabs/Debug"
Expand Down Expand Up @@ -41,10 +43,20 @@ func _ready() -> void:
$AlwaysShowInstalls.pressed = Settings.read("always_show_installs")
$ShowObsoleteMods.pressed = Settings.read("show_obsolete_mods")
$InstallArchivedMods.pressed = Settings.read("install_archived_mods")
$KeepCache.pressed = Settings.read("keep_cache")
$IgnoreCache.pressed = Settings.read("ignore_cache")
$ShowDebug.pressed = Settings.read("debug_mode")
$NumReleases/sbNumReleases.value = Settings.read("num_releases_to_request") as int
$NumPrs/sbNumPRs.value = Settings.read("num_prs_to_request") as int

var proxy_option_idx := _proxy_options.find(Settings.read("proxy_option"))
if proxy_option_idx >= 0:
$ProxySettings/obtnProxyOption.selected = proxy_option_idx
else:
$ProxySettings/obtnProxyOption.selected = 0
$ProxySettings/leProxyHost.text = Settings.read("proxy_host")
$ProxySettings/sbProxyPort.value = Settings.read("proxy_port") as int

$ScaleOverride/cbScaleOverrideEnable.pressed = Settings.read("ui_scale_override_enabled")
$ScaleOverride/sbScaleOverride.editable = Settings.read("ui_scale_override_enabled")
$ScaleOverride/sbScaleOverride.value = (Settings.read("ui_scale_override") as float) * 100.0
Expand Down Expand Up @@ -103,6 +115,14 @@ func _on_InstallArchivedMods_toggled(button_pressed: bool) -> void:

Settings.store("install_archived_mods", button_pressed)

func _on_KeepCache_toggled(button_pressed: bool) -> void:

Settings.store("keep_cache", button_pressed)

func _on_IgnoreCache_toggled(button_pressed: bool) -> void:

Settings.store("ignore_cache", button_pressed)

func _on_ShowDebug_toggled(button_pressed: bool) -> void:

Settings.store("debug_mode", button_pressed)
Expand All @@ -123,6 +143,16 @@ func _on_sbNumPRs_value_changed(value: float) -> void:
Settings.store("num_prs_to_request", str(value))


func _on_obtnProxyOption_item_selected(index):
Settings.store("proxy_option", _proxy_options[index])

func _on_leProxyHost_text_changed(new_text):
Settings.store("proxy_host", new_text)

func _on_sbProxyPort_value_changed(value):
Settings.store("proxy_port", value)


func _on_cbScaleOverrideEnable_toggled(button_pressed: bool) -> void:

Settings.store("ui_scale_override_enabled", button_pressed)
Expand All @@ -142,3 +172,5 @@ func _on_sbScaleOverride_value_changed(value: float) -> void:
Settings.store("ui_scale_override", value / 100.0)
Geom.scale = value / 100.0
_root.theme.apply_scale(Geom.scale)


9 changes: 5 additions & 4 deletions scripts/SoundpackManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ func install_pack(soundpack_index: int, from_file = null, reinstall = false, kee
if from_file:
archive = from_file
else:
Downloader.download_file(pack["url"], Paths.own_dir, pack["filename"])
yield(Downloader, "download_finished")
archive = Paths.own_dir.plus_file(pack["filename"])
archive = Paths.cache_dir.plus_file(pack["filename"])
if Settings.read("ignore_cache") or not Directory.new().file_exists(archive):
Downloader.download_file(pack["url"], Paths.cache_dir, pack["filename"])
yield(Downloader, "download_finished")
if not Directory.new().file_exists(archive):
Status.post(tr("msg_sound_download_failed"), Enums.MSG_ERROR)
emit_signal("soundpack_installation_finished")
Expand All @@ -173,7 +174,7 @@ func install_pack(soundpack_index: int, from_file = null, reinstall = false, kee

FS.extract(archive, tmp_dir)
yield(FS, "extract_done")
if not keep_archive:
if not keep_archive and not Settings.read("keep_cache"):
Directory.new().remove(archive)
FS.move_dir(tmp_dir + "/" + pack["internal_path"], sound_dir + "/" + pack["name"])
yield(FS, "move_dir_done")
Expand Down
20 changes: 20 additions & 0 deletions scripts/download_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,29 @@ func _enter_tree() -> void:
self.add_child(_http)
_http.connect("request_completed", self, "_on_HTTPRequest_request_completed")

func set_proxy(host: String, port: int) -> void:

_http.set_http_proxy(host, port)
_http.set_https_proxy(host, port)

func download_file(url: String, target_dir: String, target_filename: String) -> void:

if Settings.read("proxy_option") == "on" or Settings.read("proxy_option") == "download":
var host = Settings.read("proxy_host")
var port = Settings.read("proxy_port") as int
Status.post(tr("msg_using_proxy") % [host, port])
set_proxy(host, port)
else:
set_proxy("", -1)

var d = Directory.new()
if not d.dir_exists(target_dir):
var err = d.make_dir_recursive(target_dir)
if err:
Status.post(tr("msg_download_failed") % target_filename, Enums.MSG_ERROR)
emit_signal("download_finished")
return

Status.post(tr("msg_downloading_file") % target_filename)
emit_signal("download_started")
_current_filename = target_filename
Expand Down
6 changes: 6 additions & 0 deletions scripts/path_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ signal status_message

var own_dir: String setget , _get_own_dir
var installs_summary: Dictionary setget , _get_installs_summary
var cache_dir: String setget , _get_cache_dir
var game_dir: String setget , _get_game_dir
var next_install_dir: String setget , _get_next_install_dir
var userdata: String setget , _get_userdata_dir
Expand Down Expand Up @@ -61,6 +62,11 @@ func _get_installs_summary() -> Dictionary:
return result


func _get_cache_dir() -> String:

return _get_own_dir().plus_file("cache")


func _get_game_dir() -> String:

var active_name = Settings.read("active_install_" + Settings.read("game"))
Expand Down
5 changes: 5 additions & 0 deletions scripts/settings_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const _HARDCODED_DEFAULTS = {
"font_preview_cyrillic": false,
"show_game_desc": true,
"keep_open_after_starting_game": true,
"keep_cache": false,
"ignore_cache": false,
"proxy_option": "off",
"proxy_host": "",
"proxy_port": 0,
"debug_mode": false,
}

Expand Down
Loading