Skip to content

Commit 2f242f6

Browse files
committed
Release v4.8: Refactor update scripts and improve zip selection logic
1 parent 483846f commit 2f242f6

6 files changed

Lines changed: 54 additions & 81 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v4.8
4+
5+
- Updater: refactored zip selection to strict priority order (`preferred_release_zip_names`, `pick_best_zip_url`) instead of scoring; native Windows prefers `release_windows.zip` then `release_windows_xp.zip` when the main zip is missing (fixes Windows 7 receiving wine_linux build). Wine detection hardened (validate `wine_get_version` return).
6+
- Update scripts: clarified prompts in `update_from_zip.sh` and `update_from_zip.cmd` for user input options when applying fresh settings.
7+
38
## v4.7
49

510
- Raw mouse: SetCursorPos hook now always calls the original so the OS cursor is warped when the game recenters, fixing dual-monitor focus loss (e.g. left edge on Wine/Kubuntu).

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.7
1+
4.8

hdr/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
Increment version using: ./increment_version.sh
88
*/
99

10-
#define SOFBUDDY_VERSION "4.7"
10+
#define SOFBUDDY_VERSION "4.8"

rsrc/lin_scripts/update_from_zip.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ else
5151
echo "Warning: could not delete ${ZIP_PATH}"
5252
fi
5353
echo
54-
read -r -p "Start with fresh settings? [Y/n]: " ans
55-
if [[ ! "${ans,,}" =~ ^n(o)?$ ]]; then
54+
read -r -p "Start with fresh settings? [y/N]: " ans
55+
if [[ "${ans,,}" =~ ^y(es)?$ ]]; then
5656
echo "Searching for old configuration to prune..."
5757
find "${ROOT_DIR}" -type f -name "sofbuddy.cfg" -print -delete 2>/dev/null || true
5858
fi

rsrc/win_scripts/update_from_zip.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ if /i "!EXTRACT_METHOD!"=="vbscript" (
7777
)
7878
)
7979
echo.
80-
set "FRESH=Y"
81-
set /p "FRESH=Start with fresh settings? [Y/n]: "
82-
if /i not "!FRESH!"=="n" (
80+
set "FRESH=N"
81+
set /p "FRESH=Start with fresh settings? [y/N]: "
82+
if /i "!FRESH!"=="y" (
8383
echo Searching for old configuration to prune...
8484
for /r "%ROOT_DIR%" %%F in (sofbuddy.cfg) do (
8585
if exist "%%F" (

src/core/update_command.cpp

Lines changed: 42 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <cstdio>
1616
#include <cstring>
1717
#include <cstdint>
18-
#include <limits>
1918
#include <string>
2019
#include <vector>
2120

@@ -84,7 +83,15 @@ bool is_regular_file(const char* path) {
8483

8584
bool is_running_under_wine() {
8685
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
87-
return ntdll && GetProcAddress(ntdll, "wine_get_version");
86+
if (!ntdll) return false;
87+
typedef const char* (*wine_get_version_fn)(void);
88+
auto fn = reinterpret_cast<wine_get_version_fn>(GetProcAddress(ntdll, "wine_get_version"));
89+
if (!fn) return false;
90+
const char* ver = fn();
91+
if (!ver || !ver[0]) return false;
92+
for (const char* p = ver; *p; ++p)
93+
if (std::isdigit(static_cast<unsigned char>(*p))) return true;
94+
return false;
8895
}
8996

9097
bool prefer_linux_wine_release_zip() {
@@ -594,80 +601,44 @@ std::string zip_asset_name_from_url(const std::string& url) {
594601
return to_lower_ascii(asset_name_from_url(url));
595602
}
596603

597-
int score_release_zip_candidate(const std::string& url) {
598-
const std::string name = zip_asset_name_from_url(url);
599-
if (name.size() < 4 || name.compare(name.size() - 4, 4, ".zip") != 0)
600-
return std::numeric_limits<int>::min();
601-
602-
const bool is_debug = (name.find("debug") != std::string::npos);
603-
const bool is_release = (name.find("release") != std::string::npos);
604-
const bool has_sofbuddy = (name.find("sof_buddy") != std::string::npos) ||
605-
(name.find("sofbuddy") != std::string::npos);
606-
const bool is_windows = (name.find("windows") != std::string::npos);
607-
const bool is_linux_wine = (name.find("linux") != std::string::npos) ||
608-
(name.find("wine") != std::string::npos);
609-
const bool is_xp = (name.find("xp") != std::string::npos);
610-
const bool prefer_linux_wine = prefer_linux_wine_release_zip();
611-
612-
int score = 0;
613-
if (is_release) score += 400;
614-
if (has_sofbuddy) score += 120;
615-
if (is_windows) score += 30;
616-
if (is_linux_wine) score += 20;
617-
if (is_xp) score -= 40;
618-
if (is_debug) score -= 500;
619-
620-
if (name == "release_windows.zip") score += 200;
621-
else if (name == "release_linux_wine.zip") score += 180;
622-
else if (name == "release_windows_xp.zip") score += 100;
623-
else if (name == "debug_windows.zip") score -= 100;
624-
else if (name == "debug_windows_xp.zip") score -= 150;
625-
604+
void preferred_release_zip_names(std::vector<std::string>& out) {
605+
out.clear();
626606
#if defined(SOFBUDDY_XP_BUILD)
627-
if (is_windows && is_xp) score += 1200;
628-
if (is_windows && !is_xp) score -= 400;
629-
if (is_linux_wine) score -= 700;
607+
out.push_back("release_windows_xp.zip");
630608
#else
631-
if (prefer_linux_wine) {
632-
if (is_linux_wine) score += 1200;
633-
if (is_windows && !is_xp) score -= 150;
634-
if (is_windows && is_xp) score -= 700;
635-
} else {
636-
if (is_windows && !is_xp) score += 1200;
637-
if (is_windows && is_xp) score -= 700;
638-
if (is_linux_wine) score -= 150;
609+
if (prefer_linux_wine_release_zip())
610+
out.push_back("release_linux_wine.zip");
611+
else {
612+
out.push_back("release_windows.zip");
613+
out.push_back("release_windows_xp.zip");
639614
}
640615
#endif
641-
642-
return score;
643616
}
644617

645-
bool zip_matches_build_preference(const std::string& url) {
646-
const std::string name = zip_asset_name_from_url(url);
647-
if (name.empty()) return false;
648-
if (name.size() < 4 || name.compare(name.size() - 4, 4, ".zip") != 0) return false;
618+
bool is_preferred_release_zip(const std::string& name) {
619+
if (name.empty() || name.size() < 4 || name.compare(name.size() - 4, 4, ".zip") != 0)
620+
return false;
649621
if (name.find("debug") != std::string::npos) return false;
622+
std::vector<std::string> preferred;
623+
preferred_release_zip_names(preferred);
624+
for (const auto& p : preferred)
625+
if (name == p) return true;
626+
return false;
627+
}
650628

651-
const bool is_windows = (name.find("windows") != std::string::npos);
652-
const bool is_linux_wine = (name.find("linux") != std::string::npos) ||
653-
(name.find("wine") != std::string::npos);
654-
const bool is_xp = (name.find("xp") != std::string::npos);
655-
const bool prefer_linux_wine = prefer_linux_wine_release_zip();
656-
657-
#if defined(SOFBUDDY_XP_BUILD)
658-
if (is_windows && is_xp) return true;
659-
if (is_windows && !is_xp) return false;
660-
if (is_linux_wine) return false;
661-
#else
662-
if (prefer_linux_wine) {
663-
if (is_linux_wine) return true;
664-
if (is_windows && !is_xp) return false;
665-
if (is_windows && is_xp) return false;
629+
std::string pick_best_zip_url(const std::vector<std::string>& candidates) {
630+
std::vector<std::string> preferred;
631+
preferred_release_zip_names(preferred);
632+
for (const auto& name : preferred) {
633+
for (const auto& url : candidates) {
634+
if (zip_asset_name_from_url(url) == name) return url;
635+
}
666636
}
667-
if (is_windows && !is_xp) return true;
668-
if (is_windows && is_xp) return false;
669-
#endif
670-
return true;
637+
return std::string();
638+
}
639+
640+
bool zip_matches_build_preference(const std::string& url) {
641+
return is_preferred_release_zip(zip_asset_name_from_url(url));
671642
}
672643

673644
std::vector<int> parse_version_parts(const std::string& version_text) {
@@ -788,15 +759,12 @@ bool fetch_latest_release(ReleaseInfo& out, std::string& error) {
788759
}
789760

790761
out.zip_url.clear();
791-
int best_score = std::numeric_limits<int>::min();
762+
std::vector<std::string> candidates;
792763
size_t search = 0;
793764
std::string candidate;
794-
while (json_find_string_field(body, "browser_download_url", search, candidate, &search)) {
795-
const int score = score_release_zip_candidate(candidate);
796-
if (score <= best_score) continue;
797-
best_score = score;
798-
out.zip_url = candidate;
799-
}
765+
while (json_find_string_field(body, "browser_download_url", search, candidate, &search))
766+
candidates.push_back(candidate);
767+
out.zip_url = pick_best_zip_url(candidates);
800768
if (out.zip_url.empty()) {
801769
std::string fallback_zip_url;
802770
if (json_find_string_field(body, "zip_url", 0, fallback_zip_url, nullptr) ||

0 commit comments

Comments
 (0)