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

Merge ZiDeveloper/VostokMods #8

Merged
merged 4 commits into from
Jan 23, 2025
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
52 changes: 43 additions & 9 deletions Injector/AutoUpdater.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func checkInjectorUpdate():
var err = httpReq.request(Main.githubAPIBaseURL + "repos/Ryhon0/VostokMods/releases", ["accept: application/vnd.github+json"])
if err != OK:
push_error("Failed to create mod loader releases request ", err)
await checkModUpdates()
if Main.config.allowModsAutoUpdate:
await checkModUpdates()
else:
Main.Mods.loadMods()
Main.launchOrShowConfig()
return

Main.StatusLabel.text = "Checking for updates"
Expand All @@ -27,11 +31,19 @@ func checkInjectorUpdate():
func injectorReleasesRequestCompleted(result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray):
if result != HTTPRequest.RESULT_SUCCESS:
push_error("Failed to get mod loader releases")
await checkModUpdates()
if Main.config.allowModsAutoUpdate:
await checkModUpdates()
else:
Main.Mods.loadMods()
Main.launchOrShowConfig()
return
if response_code < 200 || response_code >= 300:
push_error("Failed to get mod loader releases (HTTP code " + str(response_code) + ")")
await checkModUpdates()
if Main.config.allowModsAutoUpdate:
await checkModUpdates()
else:
Main.Mods.loadMods()
Main.launchOrShowConfig()
return

var json = JSON.parse_string(body.get_string_from_utf8())
Expand All @@ -52,7 +64,12 @@ func injectorReleasesRequestCompleted(result: int, response_code: int, _headers:
print("Latest version: " + tag)
if Main.version != tag:
downloadLoaderUpdate(tag, injectorAsset)
else: await checkModUpdates()
else:
if Main.config.allowModsAutoUpdate:
await checkModUpdates()
else:
Main.Mods.loadMods()
Main.launchOrShowConfig()
return

func downloadLoaderUpdate(tag, asset):
Expand All @@ -61,7 +78,10 @@ func downloadLoaderUpdate(tag, asset):
var err = httpReq.request(asset["browser_download_url"])
if err != OK:
Main.StatusLabel.text = "Failed to download mod loader update.\nCode " + str(err)
get_tree().create_timer(2).timeout.connect(checkModUpdates)
if Main.config.allowModsAutoUpdate:
get_tree().create_timer(2).timeout.connect(checkModUpdates)
else:
get_tree().create_timer(2).timeout.connect(func(): Main.Mods.loadMods(); Main.launchOrShowConfig())
return

Main.StatusLabel.text = "Downloading mod loader version " + tag
Expand All @@ -73,12 +93,18 @@ func injectorFileDownloaded(result: int, response_code: int, _headers: PackedStr
if result != HTTPRequest.RESULT_SUCCESS:
push_error("Failed to download mod loader")
Main.StatusLabel.text = "Failed to save mod loader, error " + str(FileAccess.get_open_error())
get_tree().create_timer(2).timeout.connect(checkModUpdates)
if Main.config.allowModsAutoUpdate:
get_tree().create_timer(2).timeout.connect(checkModUpdates)
else:
get_tree().create_timer(2).timeout.connect(func(): Main.Mods.loadMods(); Main.launchOrShowConfig())
return
if response_code < 200 || response_code >= 300:
push_error("Failed to get mod loader releases (HTTP code " + str(response_code) + ")")
Main.StatusLabel.text = "Failed to save mod loader, error " + str(FileAccess.get_open_error())
get_tree().create_timer(2).timeout.connect(checkModUpdates)
if Main.config.allowModsAutoUpdate:
get_tree().create_timer(2).timeout.connect(checkModUpdates)
else:
get_tree().create_timer(2).timeout.connect(func(): Main.Mods.loadMods(); Main.launchOrShowConfig())
return

var dir = ProjectSettings.globalize_path(".")
Expand All @@ -88,14 +114,20 @@ func injectorFileDownloaded(result: int, response_code: int, _headers: PackedStr
var err = DirAccess.rename_absolute(injectorPath, deletemePath)
if err != OK:
Main.StatusLabel.text = "Failed to move moad loader, error " + str(err)
get_tree().create_timer(2).timeout.connect(checkModUpdates)
if Main.config.allowModsAutoUpdate:
get_tree().create_timer(2).timeout.connect(checkModUpdates)
else:
get_tree().create_timer(2).timeout.connect(func(): Main.Mods.loadMods(); Main.launchOrShowConfig())
return

var f = FileAccess.open(injectorPath, FileAccess.WRITE)
if !f:
DirAccess.rename_absolute(deletemePath, injectorPath)
Main.StatusLabel.text = "Failed to save mod loader, error " + str(FileAccess.get_open_error())
get_tree().create_timer(2).timeout.connect(checkModUpdates)
if Main.config.allowModsAutoUpdate:
get_tree().create_timer(2).timeout.connect(checkModUpdates)
else:
get_tree().create_timer(2).timeout.connect(func(): Main.Mods.loadMods(); Main.launchOrShowConfig())
return
f.store_buffer(body)
f.close()
Expand All @@ -113,6 +145,8 @@ func checkModUpdates():
var updatableMods = []
var mwsIds = []
for mod in Main.Mods.mods:
if mod.disabled:
continue
if mod.config.has_section_key("updates", "modworkshop"):
updatableMods.append(mod)
mwsIds.append(mod.config.get_value("updates", "modworkshop"))
Expand Down
22 changes: 17 additions & 5 deletions Injector/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ModLoaderConfig:
var customModDir : String = ""
var startOnConfigScreen : bool = false
var autoUpdatePreRelease : bool = false
var allowAutoUpdate: bool = true
var allowModsAutoUpdate: bool = true
var config : ModLoaderConfig = ModLoaderConfig.new()

func loadConfig():
Expand All @@ -34,14 +36,19 @@ func loadConfig():
config.startOnConfigScreen = obj["startOnConfigScreen"]
if "autoUpdatePreRelease" in obj:
config.autoUpdatePreRelease = obj["autoUpdatePreRelease"]

if "allowAutoUpdate" in obj:
config.allowAutoUpdate = obj["allowAutoUpdate"]
if "allowModsAutoUpdate" in obj:
config.allowModsAutoUpdate = obj["allowModsAutoUpdate"]
SettingsPage.onLoaded()

func saveConfig():
var jarr = {
"customModDir": config.customModDir,
"startOnConfigScreen": config.startOnConfigScreen,
"autoUpdatePreRelease": config.autoUpdatePreRelease
"autoUpdatePreRelease": config.autoUpdatePreRelease,
"allowAutoUpdate": config.allowAutoUpdate,
"allowModsAutoUpdate": config.allowModsAutoUpdate
}
var jstr = JSON.stringify(jarr)
var f = FileAccess.open(configPath, FileAccess.WRITE)
Expand Down Expand Up @@ -102,9 +109,14 @@ func _ready() -> void:

Mods.loadMods()
showLoadingScreen()
if !OS.has_feature("editor"):
if !OS.has_feature("editor") and config.allowAutoUpdate:
await Updater.checkInjectorUpdate()
else: await Updater.checkModUpdates()
else:
if config.allowModsAutoUpdate:
await Updater.checkModUpdates()
else:
Mods.loadMods()
launchOrShowConfig()

func launchOrShowConfig():
if config.startOnConfigScreen:
Expand Down Expand Up @@ -331,4 +343,4 @@ func hashPCK(path):
return res.hex_encode()

func openDonatePage():
OS.shell_open("https://github.com/sponsors/Ryhon0")
OS.shell_open("https://github.com/sponsors/Ryhon0")
20 changes: 19 additions & 1 deletion Injector/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ layout_mode = 2
size_flags_horizontal = 3
current_tab = 0

[node name="Settings" type="ScrollContainer" parent="ConfigScreen/TabContainer" node_paths=PackedStringArray("Main", "CustomModDirLine", "StartOnConfigCheckBox")]
[node name="Settings" type="ScrollContainer" parent="ConfigScreen/TabContainer" node_paths=PackedStringArray("Main", "CustomModDirLine", "StartOnConfigCheckBox", "AllowAutoUpdateCheckBox", "AllowModsAutoUpdateCheckBox")]
layout_mode = 2
size_flags_horizontal = 3
script = ExtResource("2_b0jil")
Main = NodePath("../../..")
CustomModDirLine = NodePath("VBoxContainer/GridContainer/HBoxContainer/CustomModDirLine")
StartOnConfigCheckBox = NodePath("VBoxContainer/GridContainer/CheckBox")
AllowAutoUpdateCheckBox = NodePath("VBoxContainer/GridContainer/CheckBox2")
AllowModsAutoUpdateCheckBox = NodePath("VBoxContainer/GridContainer/CheckBox3")
metadata/_tab_index = 0

[node name="VBoxContainer" type="VBoxContainer" parent="ConfigScreen/TabContainer/Settings"]
Expand Down Expand Up @@ -105,6 +107,22 @@ text = "Start on config screen"
layout_mode = 2
size_flags_horizontal = 0

[node name="Label3" type="Label" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
layout_mode = 2
text = "Enable VostokMods auto update"

[node name="CheckBox2" type="CheckBox" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
layout_mode = 2
size_flags_horizontal = 0

[node name="Label4" type="Label" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
layout_mode = 2
text = "Enable auto update of Mods"

[node name="CheckBox3" type="CheckBox" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
layout_mode = 2
size_flags_horizontal = 0

[node name="Mods" type="ScrollContainer" parent="ConfigScreen/TabContainer" node_paths=PackedStringArray("Main", "List")]
visible = false
layout_mode = 2
Expand Down
2 changes: 2 additions & 0 deletions Injector/ModList.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var mods : Array[ModInfo] = []
class ModInfo:
var zipPath : String
var config : ConfigFile
var disabled : bool

func _ready():
List.set_column_title(0, "Name")
Expand Down Expand Up @@ -66,6 +67,7 @@ func loadMods():
var modi = ModInfo.new()
modi.config = cfg
modi.zipPath = modsdir.path_join(zipname)
modi.disabled = disabled
mods.append(modi)

var li = List.create_item()
Expand Down
10 changes: 8 additions & 2 deletions Injector/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ extends Control
@export var Main: Control
@export var CustomModDirLine: LineEdit
@export var StartOnConfigCheckBox: CheckBox
@export var AllowAutoUpdateCheckBox: CheckBox
@export var AllowModsAutoUpdateCheckBox: CheckBox

func _ready() -> void:
CustomModDirLine.text_changed.connect(func(val): Main.config.customModDir = val; Main.Mods.loadMods())
StartOnConfigCheckBox.toggled.connect(func(val): Main.config.startOnConfigScreen = val)
CustomModDirLine.text_changed.connect(func(val): Main.config.customModDir = val; Main.saveConfig(); Main.Mods.loadMods())
StartOnConfigCheckBox.toggled.connect(func(val): Main.config.startOnConfigScreen = val; Main.saveConfig())
AllowAutoUpdateCheckBox.toggled.connect(func(val): Main.config.allowAutoUpdate = val; Main.saveConfig())
AllowModsAutoUpdateCheckBox.toggled.connect(func(val): Main.config.allowModsAutoUpdate = val; Main.saveConfig())

func openModDirDialog():
var fd = FileDialog.new()
Expand All @@ -20,3 +24,5 @@ func openModDirDialog():
func onLoaded():
CustomModDirLine.text = Main.config.customModDir
StartOnConfigCheckBox.button_pressed = Main.config.startOnConfigScreen
AllowAutoUpdateCheckBox.button_pressed = Main.config.allowAutoUpdate
AllowModsAutoUpdateCheckBox.button_pressed = Main.config.allowModsAutoUpdate