Skip to content

Commit

Permalink
Auto update settings and version pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryhon0 committed Jan 23, 2025
1 parent a3cd4f1 commit 0061b81
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 36 deletions.
4 changes: 3 additions & 1 deletion Injector/AutoUpdater.gd
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ func checkModUpdates():
var updatableMods = []
var mwsIds = []
for mod in Main.Mods.mods:
if mod.disabled:
if mod.versionPinned: continue
if mod.disabled && !Main.config.autoUpdateDisalbedMods:
continue

if mod.config.has_section_key("updates", "modworkshop"):
updatableMods.append(mod)
mwsIds.append(mod.config.get_value("updates", "modworkshop"))
Expand Down
6 changes: 5 additions & 1 deletion Injector/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ModLoaderConfig:
var autoUpdatePreRelease : bool = false
var allowAutoUpdate: bool = true
var allowModAutoUpdates: bool = true
var autoUpdateDisalbedMods: bool = false
var config : ModLoaderConfig = ModLoaderConfig.new()

func loadConfig():
Expand All @@ -40,6 +41,8 @@ func loadConfig():
config.allowAutoUpdate = obj["allowAutoUpdate"]
if "allowModAutoUpdates" in obj:
config.allowModAutoUpdates = obj["allowModAutoUpdates"]
if "autoUpdateDisalbedMods" in obj:
config.autoUpdateDisalbedMods = obj["autoUpdateDisalbedMods"]
SettingsPage.onLoaded()

func saveConfig():
Expand All @@ -48,7 +51,8 @@ func saveConfig():
"startOnConfigScreen": config.startOnConfigScreen,
"autoUpdatePreRelease": config.autoUpdatePreRelease,
"allowAutoUpdate": config.allowAutoUpdate,
"allowModAutoUpdates": config.allowModAutoUpdates
"allowModAutoUpdates": config.allowModAutoUpdates,
"autoUpdateDisalbedMods": config.autoUpdateDisalbedMods
}
var jstr = JSON.stringify(jarr)
var f = FileAccess.open(configPath, FileAccess.WRITE)
Expand Down
37 changes: 25 additions & 12 deletions Injector/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=7 format=3 uid="uid://b6nywv6aqxm3r"]
[gd_scene load_steps=9 format=3 uid="uid://b6nywv6aqxm3r"]

[ext_resource type="Script" path="res://Main.gd" id="1_x5slr"]
[ext_resource type="Texture2D" uid="uid://wbaqykif8euy" path="res://icon.svg" id="2_74yqq"]
[ext_resource type="Script" path="res://Settings.gd" id="2_b0jil"]
[ext_resource type="Script" path="res://ModList.gd" id="3_xyy35"]
[ext_resource type="Texture2D" uid="uid://bhyjjcpqm564o" path="res://pin.svg" id="4_rv4x7"]
[ext_resource type="Texture2D" uid="uid://epy24urpfgha" path="res://pin_disabled.svg" id="5_33vpw"]
[ext_resource type="Texture2D" uid="uid://bcc6fhil26kqe" path="res://donate_icon.png" id="5_r2nj5"]
[ext_resource type="Script" path="res://AutoUpdater.gd" id="6_etu4i"]

Expand Down Expand Up @@ -48,7 +50,6 @@ layout_mode = 2
max_value = 1.0

[node name="ConfigScreen" type="HBoxContainer" parent="."]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
Expand All @@ -61,15 +62,16 @@ layout_mode = 2
size_flags_horizontal = 3
current_tab = 0

[node name="Settings" type="ScrollContainer" parent="ConfigScreen/TabContainer" node_paths=PackedStringArray("Main", "CustomModDirLine", "StartOnConfigCheckBox", "AllowAutoUpdateCheckBox", "AllowModsAutoUpdateCheckBox")]
[node name="Settings" type="ScrollContainer" parent="ConfigScreen/TabContainer" node_paths=PackedStringArray("Main", "CustomModDirLine", "StartOnConfigCheckBox", "AllowAutoUpdateCheckBox", "AllowModAutoUpdatesCheckBox", "AutoUpdateDisabledModsCheckBox")]
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")
AllowModAutoUpdatesCheckBox = NodePath("VBoxContainer/GridContainer/CheckBox3")
StartOnConfigCheckBox = NodePath("VBoxContainer/GridContainer/ConfigStartCheckBox")
AllowAutoUpdateCheckBox = NodePath("VBoxContainer/GridContainer/LoaderUpdatesCheckBox")
AllowModAutoUpdatesCheckBox = NodePath("VBoxContainer/GridContainer/ModUpdatesCheckBox")
AutoUpdateDisabledModsCheckBox = NodePath("VBoxContainer/GridContainer/DisabledModUpdatesCheckBox")
metadata/_tab_index = 0

[node name="VBoxContainer" type="VBoxContainer" parent="ConfigScreen/TabContainer/Settings"]
Expand Down Expand Up @@ -103,23 +105,31 @@ text = "..."
layout_mode = 2
text = "Start on config screen"

[node name="CheckBox" type="CheckBox" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
[node name="ConfigStartCheckBox" type="CheckBox" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
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"
text = "Automatically update mod loader"

[node name="CheckBox2" type="CheckBox" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
[node name="LoaderUpdatesCheckBox" 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"
text = "Automatically update mods"

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

[node name="Label5" type="Label" parent="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer"]
layout_mode = 2
text = "Automatically update disabled mods"

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

Expand All @@ -129,13 +139,15 @@ layout_mode = 2
script = ExtResource("3_xyy35")
Main = NodePath("../../..")
List = NodePath("ModListTree")
PinIcon = ExtResource("4_rv4x7")
PinIconDisabled = ExtResource("5_33vpw")
metadata/_tab_index = 1

[node name="ModListTree" type="Tree" parent="ConfigScreen/TabContainer/Mods"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
columns = 5
columns = 6
column_titles_visible = true
hide_root = true
select_mode = 1
Expand Down Expand Up @@ -229,6 +241,7 @@ Main = NodePath("..")

[connection signal="tab_changed" from="ConfigScreen/TabContainer" to="ConfigScreen/TabContainer/Mods" method="tabChanged"]
[connection signal="pressed" from="ConfigScreen/TabContainer/Settings/VBoxContainer/GridContainer/HBoxContainer/Button" to="ConfigScreen/TabContainer/Settings" method="openModDirDialog"]
[connection signal="button_clicked" from="ConfigScreen/TabContainer/Mods/ModListTree" to="ConfigScreen/TabContainer/Mods" method="buttonPressed"]
[connection signal="column_title_clicked" from="ConfigScreen/TabContainer/Mods/ModListTree" to="ConfigScreen/TabContainer/Mods" method="titleClicked"]
[connection signal="item_edited" from="ConfigScreen/TabContainer/Mods/ModListTree" to="ConfigScreen/TabContainer/Mods" method="itemEdited"]
[connection signal="pressed" from="ConfigScreen/VBoxContainer2/Button2" to="." method="openDonatePage"]
Expand Down
99 changes: 77 additions & 22 deletions Injector/ModList.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,75 @@ class_name ModList

@export var Main: Control
@export var List: Tree

@export var PinIcon: Texture2D
@export var PinIconDisabled: Texture2D

var mods : Array[ModInfo] = []

class ModInfo:
var zipPath : String
var config : ConfigFile
var disabled : bool
var versionPinned : bool

func makeDisabled(disable: bool):
var from = zipPath + ".zip"
var to = zipPath + ".zip"

if disable: to += ".disabled"
else: from += ".disabled"

var err = DirAccess.rename_absolute(from, to)
if err != OK:
OS.alert("Could not move file " + from + " to " + to + ". Error " + err)
return

disabled = disable

func pinVersion(pin: bool):
if !pin:
var err = DirAccess.remove_absolute(zipPath + ".dontupdate")
if err != OK:
OS.alert("Could remove file " + zipPath + ".dontupdate. Error " + err)
return
versionPinned = pin
else:
var f = FileAccess.open(zipPath + ".dontupdate", FileAccess.ModeFlags.WRITE)
var err = FileAccess.get_open_error()

if err != OK:
OS.alert("Failed to create file " + zipPath + ".dontupdate. Error " + err)
return

f.store_string("")
f.close()

err = f.get_error()
if err != OK:
OS.alert("Failed to save file " + zipPath + ".dontupdate. Error " + err)
return

versionPinned = pin

const VERSION_COLUMN = 2
const VERSION_COLUMN_BUTTON_PIN = 0

const ENABLED_COLUMN = 4

func _ready():
List.set_column_title(0, "Name")
List.set_column_title(1, "ID")
List.set_column_title(2, "Version")
List.set_column_title(VERSION_COLUMN, "Version")
List.set_column_title(3, "File name")
List.set_column_title(4, "Enabled")
List.set_column_title(ENABLED_COLUMN, "Enabled")

for i in range(List.columns):
List.set_column_expand(i, false)

List.set_column_expand(0, true)
List.set_column_custom_minimum_width(1, 175)
List.set_column_custom_minimum_width(VERSION_COLUMN, 75)
List.set_column_custom_minimum_width(3, 175)

func loadMods():
Expand All @@ -45,6 +95,7 @@ func loadMods():
disabled = false
else:
continue
var pinned = FileAccess.file_exists(modsdir.path_join(zipname) + ".dontupdate")

var zr = ZIPReader.new()
if zr.open(modsdir.path_join(f)) != OK:
Expand All @@ -68,35 +119,39 @@ func loadMods():
modi.config = cfg
modi.zipPath = modsdir.path_join(zipname)
modi.disabled = disabled
modi.versionPinned = pinned
mods.append(modi)

var li = List.create_item()
li.set_meta("filename", zipname)
li.set_meta("mod", modi)

li.set_text(0, modname)
li.set_text(1, modid)
li.set_text(2, modver)
li.set_text(VERSION_COLUMN, modver)
li.set_text(3, zipname)
li.set_cell_mode(List.columns - 1, TreeItem.CELL_MODE_CHECK)
li.set_checked(List.columns - 1, !disabled)
li.set_editable(List.columns - 1, true)

# Mod disalbed
li.set_cell_mode(ENABLED_COLUMN, TreeItem.CELL_MODE_CHECK)
li.set_checked(ENABLED_COLUMN, !disabled)
li.set_editable(ENABLED_COLUMN, true)

# Pin version
li.add_button(VERSION_COLUMN, PinIcon if pinned else PinIconDisabled, VERSION_COLUMN_BUTTON_PIN, false, "Pin version")

func buttonPressed(item: TreeItem, column: int, button: int, mousebtn: int) -> void:
if column == VERSION_COLUMN && button == VERSION_COLUMN_BUTTON_PIN:
if mousebtn == MOUSE_BUTTON_LEFT:
var mod : ModInfo = item.get_meta("mod")
mod.pinVersion(!mod.versionPinned)
item.set_button(VERSION_COLUMN, VERSION_COLUMN_BUTTON_PIN, PinIcon if mod.versionPinned else PinIconDisabled)
return

func itemEdited() -> void:
if List.get_edited_column() != List.columns - 1:
return

var item: TreeItem = List.get_edited()
var disabled = item.is_checked(List.columns - 1)
var file = Main.getModsDir().path_join(item.get_meta("filename"))

var from = file + ".zip"
var to = file + ".zip"
if disabled: from += ".disabled"
else: to += ".disabled"


if DirAccess.rename_absolute(from, to) != OK:
OS.alert("Could not move file " + from)
if List.get_edited_column() == 4:
var item: TreeItem = List.get_edited()
var modi: ModInfo = item.get_meta("mod")
modi.makeDisabled(!modi.disabled)
item.set_checked(ENABLED_COLUMN, modi.disabled)

func titleClicked(col: int, mouse: int) -> void:
if mouse != MOUSE_BUTTON_LEFT:
Expand Down
3 changes: 3 additions & 0 deletions Injector/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ extends Control
@export var StartOnConfigCheckBox: CheckBox
@export var AllowAutoUpdateCheckBox: CheckBox
@export var AllowModAutoUpdatesCheckBox: CheckBox
@export var AutoUpdateDisabledModsCheckBox: CheckBox

func _ready() -> void:
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())
AllowModAutoUpdatesCheckBox.toggled.connect(func(val): Main.config.allowModAutoUpdates = val; Main.saveConfig())
AutoUpdateDisabledModsCheckBox.toggled.connect(func(val): Main.config.autoUpdateDisalbedMods = val; Main.saveConfig())

func openModDirDialog():
var fd = FileDialog.new()
Expand All @@ -26,3 +28,4 @@ func onLoaded():
StartOnConfigCheckBox.button_pressed = Main.config.startOnConfigScreen
AllowAutoUpdateCheckBox.button_pressed = Main.config.allowAutoUpdate
AllowModAutoUpdatesCheckBox.button_pressed = Main.config.allowModAutoUpdates
AutoUpdateDisabledModsCheckBox.button_pressed = Main.config.autoUpdateDisalbedMods
37 changes: 37 additions & 0 deletions Injector/mws_logo_white.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://d1c10pv53ai2x"
path="res://.godot/imported/mws_logo_white.svg-9e2febccbc8e44d82ff854ce9d86db63.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://mws_logo_white.svg"
dest_files=["res://.godot/imported/mws_logo_white.svg-9e2febccbc8e44d82ff854ce9d86db63.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
1 change: 1 addition & 0 deletions Injector/pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions Injector/pin.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bhyjjcpqm564o"
path="res://.godot/imported/pin.svg-8ffcbdbbbe25fd7c71979555d8a64c28.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://pin.svg"
dest_files=["res://.godot/imported/pin.svg-8ffcbdbbbe25fd7c71979555d8a64c28.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
Loading

0 comments on commit 0061b81

Please sign in to comment.