Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

Commit e1efebc

Browse files
committed
feat: add configuration loading and branch handling for integration updates
1 parent 7ab3ef8 commit e1efebc

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

crates/real/src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const BIN_DIR: &str = "garrysmod/lua/bin";
3131
const GWSOCKETS_API: &str = "https://api.github.com/repos/FredyH/GWSockets/releases/latest";
3232
const REQWEST_API: &str = "https://api.github.com/repos/WilliamVenner/gmsv_reqwest/releases/latest";
3333
const TMP_JSON_PATH: &str = "garrysmod/data/gm_integration/tmp.json";
34+
const CONFIG_JSON_PATH: &str = "garrysmod/data/gm_integration/config.json";
3435

3536
fn print_log(msg: &str) {
3637
let time = Local::now().format("%Y-%m-%d %H:%M:%S");
@@ -130,6 +131,26 @@ fn update_tmp_json() {
130131
}
131132
}
132133

134+
#[derive(Deserialize, Debug)]
135+
struct Config {
136+
#[serde(rename = "dllBranch")]
137+
dll_branch: Option<String>,
138+
}
139+
140+
fn load_config() -> Option<Config> {
141+
fs::read_to_string(CONFIG_JSON_PATH)
142+
.ok()
143+
.and_then(|content| serde_json::from_str(&content).ok())
144+
}
145+
146+
fn get_api_url_for_branch(branch: &str) -> String {
147+
if branch == "main" || branch.is_empty() {
148+
"https://api.github.com/repos/gmod-integration/gmod-integration/releases/latest".to_string()
149+
} else {
150+
format!("https://api.github.com/repos/gmod-integration/gmod-integration/releases/tags/{}", branch)
151+
}
152+
}
153+
133154
#[gmod13_open]
134155
fn gmod13_open(_lua: State) -> i32 {
135156
print_log("Starting auto-updater...");
@@ -168,8 +189,19 @@ fn gmod13_open(_lua: State) -> i32 {
168189
// Continue with main integration update
169190
print_log("Checking main integration...");
170191

192+
// Load config and determine branch
193+
let config = load_config();
194+
let branch = config
195+
.as_ref()
196+
.and_then(|c| c.dll_branch.as_ref())
197+
.map(|s| s.as_str())
198+
.unwrap_or("main");
199+
200+
print_log(&format!("Using branch: {}", branch));
201+
202+
let api_url = get_api_url_for_branch(branch);
171203
let res = match client
172-
.get("https://api.github.com/repos/gmod-integration/gmod-integration/releases/latest")
204+
.get(&api_url)
173205
.header("User-Agent", "Gmod-Integration-Updater")
174206
.send()
175207
{
@@ -196,7 +228,7 @@ fn gmod13_open(_lua: State) -> i32 {
196228
}
197229
}
198230

199-
print_log("Downloading latest version...");
231+
print_log(&format!("Downloading {} version...", release.tag_name));
200232

201233
let response = match client
202234
.get(&release.zipball_url)

0 commit comments

Comments
 (0)