From 6ff159b7896cca0edd9b69eb058e19af027e659d Mon Sep 17 00:00:00 2001 From: seventhback777 <903157209@qq.com> Date: Sat, 23 May 2026 18:17:20 +1000 Subject: [PATCH 1/3] fix: Windows cross-platform compatibility and bug fixes - Database.h: add stub implementations so the project compiles on Windows (SplashKit database API is missing on Windows; TODO: replace with raw SQLite3) - Rating.h: fix rating lower boundary to start from 1 instead of 0 - Helper.h: prevent double-slash in path concatenation; add early return when games directory does not exist - Configuration.h: add ROWS/COLS grid layout macros - ConfigData.h/cpp: change setFolder() from inline to proper declaration/definition; add missing include for strcpy - resources/bundles/resources.txt: remove extra spaces in MUSIC resource entries - .gitignore: fix games/ directory pattern (was games/*) --- .gitignore | 2 +- include/ConfigData.h | 2 +- include/Configuration.h | 3 ++ include/Database.h | 24 +++++++++++ include/Helper.h | 11 +++++ include/Rating.h | 2 +- resources/bundles/resources.txt | 8 ++-- src/ConfigData.cpp | 75 ++++++++++++++++++++++++++++----- 8 files changed, 110 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 275e8b6..57b9c15 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ logs/ **/*.exe **/*.out* resources/databases/* -games/* +games/ **/*.o ArcadeMachine **/.DS_Store diff --git a/include/ConfigData.h b/include/ConfigData.h index 348cc99..77d4015 100644 --- a/include/ConfigData.h +++ b/include/ConfigData.h @@ -63,7 +63,7 @@ class ConfigData //Setters: auto setId(int &i) { m_id = i; } - auto setFolder(std::string &dir) { m_folder = dir; } + void setFolder(std::string &dir); // Getters: auto id() const -> const int& { return m_id; } auto repo() const -> const std::string& { return m_repo; } diff --git a/include/Configuration.h b/include/Configuration.h index 537c24f..9dfc428 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -5,6 +5,9 @@ #define ARCADE_MACHINE_RES_X 1920 * ARCADE_MACHINE_SCALING_FACTOR #define ARCADE_MACHINE_RES_Y 1080 * ARCADE_MACHINE_SCALING_FACTOR +#define ROWS 7 +#define COLS 15 + #ifdef _WIN32 #define ARCADE_MACHINE_PATH_SEP "\\" #else diff --git a/include/Database.h b/include/Database.h index bc91bd9..e887e84 100644 --- a/include/Database.h +++ b/include/Database.h @@ -9,6 +9,30 @@ #include #include +// --------------------------------------------------------------------------- +// TEMPORARY: SplashKit database API is missing on Windows builds. +// These stubs allow the project to compile on Windows. On Linux/RPi, +// SplashKit provides the real API so no stubs are needed. +// TODO: Rewrite Database.h using raw SQLite3 (-lsqlite3) to restore functionality. +// --------------------------------------------------------------------------- +#if 1 +struct database {}; +struct query_result {}; +inline database open_database(std::string, std::string) { return {}; } +inline void free_database(database) {} +inline query_result run_sql(database, std::string) { return {}; } +inline bool query_success(query_result) { return false; } +inline bool has_row(query_result) { return false; } +inline bool get_next_row(query_result) { return false; } +inline void free_all_query_results() {} +inline int query_column_count(query_result) { return 0; } +inline std::string query_column_for_string(query_result, int) { return ""; } +inline double query_column_for_double(query_result, int) { return 0.0; } +inline int query_column_for_int(query_result, int) { return 0; } +inline std::string query_type_of_col(query_result, int) { return "NULL"; } +#endif +// --------------------------------------------------------------------------- + class Database { private: std::string m_databaseName; diff --git a/include/Helper.h b/include/Helper.h index 1f67fb9..3243f6d 100644 --- a/include/Helper.h +++ b/include/Helper.h @@ -32,6 +32,9 @@ class Helper { string getFolderName(string entryPath) { string dir = fs::path(entryPath).remove_filename().generic_string(); + // Remove trailing slash to prevent double-slash when concatenating paths later + if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) + dir.pop_back(); std::cout << "Game-Directory Path: " << dir << "\n"; return dir; } @@ -46,6 +49,12 @@ class Helper { { vector files; + if (!fs::exists(dir) || !fs::is_directory(dir)) + { + std::cerr << "Warning: Games directory not found: " << dir << "\n"; + return files; + } + for (const auto & entry : fs::recursive_directory_iterator(dir)) { if (entry.path().filename() == "config.txt") @@ -55,6 +64,8 @@ class Helper { } } + std::cerr << "[Helper] found " << files.size() << " config files in " << dir << std::endl; + return files; } diff --git a/include/Rating.h b/include/Rating.h index 3fcfc92..51e5395 100644 --- a/include/Rating.h +++ b/include/Rating.h @@ -38,7 +38,7 @@ class Rating if (key_typed(LEFT_KEY)) { --_rating; - if (_rating < 0) + if (_rating < 1) _rating = _maxRating; updateGrid(); } diff --git a/resources/bundles/resources.txt b/resources/bundles/resources.txt index a632c5d..1e3bbb5 100644 --- a/resources/bundles/resources.txt +++ b/resources/bundles/resources.txt @@ -62,10 +62,10 @@ SOUND,intro_start,completed.wav // Music MUSIC,music_mainmenu,main_menu.mp3 -MUSIC, 1, 1.mp3 -MUSIC, 2, 2.mp3 -MUSIC, 3, 3.mp3 -MUSIC, music_about, insert-no-coins.ogg +MUSIC,1,1.mp3 +MUSIC,2,2.mp3 +MUSIC,3,3.mp3 +MUSIC,music_about,insert-no-coins.ogg // Animations ANIM,info-script,information.txt diff --git a/src/ConfigData.cpp b/src/ConfigData.cpp index 776ef46..d166b68 100644 --- a/src/ConfigData.cpp +++ b/src/ConfigData.cpp @@ -5,10 +5,17 @@ #include #include #include +#include #include +#if __cplusplus >= 201703L +#include +namespace fs = std::filesystem; +#else +#define _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM #include namespace fs = std::experimental::filesystem; +#endif /** * @brief Construct a new Config Data object @@ -18,6 +25,48 @@ namespace fs = std::experimental::filesystem; ConfigData::ConfigData(std::string configFile) { collectConfigData(readTxt(openFile(configFile))); + + if (this->m_title.empty()) + std::cerr << "[Config] missing field 'title' in: " << configFile << std::endl; + if (this->m_image.empty()) + std::cerr << "[Config] missing field 'image' in: " << configFile << std::endl; +} + +void ConfigData::setFolder(std::string &dir) +{ + m_folder = dir; + + fs::path buildsPath = fs::path(dir) / "builds"; + + if (!fs::exists(buildsPath) || !fs::is_directory(buildsPath)) + { + std::cerr << "[Config] no builds/ directory: " << dir << std::endl; + return; + } + + bool hasLinuxArm = false, hasLinuxX86 = false, hasWindows = false; + + for (const auto &entry : fs::directory_iterator(buildsPath)) + { + std::string name = entry.path().filename().string(); + if (name == "linux-arm.out") hasLinuxArm = true; + if (name == "linux-x86.out") hasLinuxX86 = true; + if (name == "windows-x86.exe") hasWindows = true; + } + + if (!hasLinuxArm && !hasLinuxX86 && !hasWindows) + { + std::cerr << "[Config] builds/ is empty: " << dir << std::endl; + return; + } + + std::string platforms = ""; + if (hasLinuxArm) platforms += "Linux ARM, "; + if (hasLinuxX86) platforms += "Linux x86, "; + if (hasWindows) platforms += "Windows, "; + platforms = platforms.substr(0, platforms.size() - 2); // trim trailing ", " + + std::cerr << "[Config] " << m_title << " supports: " << platforms << std::endl; } /** @@ -34,7 +83,7 @@ std::ifstream ConfigData::openFile(std::string file) if(configFile.fail()) { - std::cerr << "Error Opening File" << std::endl; + std::cerr << "[Config] failed to open file: " << file << std::endl; exit(1); } @@ -141,23 +190,29 @@ bool ConfigData::getFromGit(std::string url, const char* dir) { // info struct lets us query the directory to see if it exists struct stat info; - if (stat(dir, &info) != 0) - { - // cant access dir -- clone from scratch - system(("git clone " + url + " " + dir).c_str()); - } - else if (info.st_mode &S_IFDIR) + bool isPull = (stat(dir, &info) == 0 && (info.st_mode & S_IFDIR)); + + if (isPull) { - // dir exists -- pull instead + std::cerr << "[Git] pulling: " << url << " → " << dir << std::endl; system(("git -C " + std::string(dir) + " pull " + url).c_str()); } else { - // dir does not exist -- clone from scratch + std::cerr << "[Git] cloning: " << url << " → " << dir << std::endl; system(("git clone " + url + " " + dir).c_str()); } - return true; + // Verify the directory actually exists after the git operation + struct stat checkInfo; + bool success = (stat(dir, &checkInfo) == 0 && (checkInfo.st_mode & S_IFDIR)); + + if (success) + std::cerr << "[Git] " << (isPull ? "pull" : "clone") << " succeeded: " << dir << std::endl; + else + std::cerr << "[Git] " << (isPull ? "pull" : "clone") << " failed: " << dir << std::endl; + + return success; } /** From d2f65c8fdf1427a54db36863d316bdad42436b37 Mon Sep 17 00:00:00 2001 From: HAOYU LIU Date: Sat, 23 May 2026 21:52:21 +1000 Subject: [PATCH 2/3] fix: address PR #91 review feedback - Replace C stat() calls with fs:: in getFromGit() for consistency - Check for .git directory to confirm dir is a valid git repo before pull - Capture system() return code to properly detect git operation success - Remove duplicate ROWS/COLS macros from Configuration.h (already in ArcadeMachine.h) --- include/Configuration.h | 3 --- src/ConfigData.cpp | 17 +++++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/Configuration.h b/include/Configuration.h index 9dfc428..537c24f 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -5,9 +5,6 @@ #define ARCADE_MACHINE_RES_X 1920 * ARCADE_MACHINE_SCALING_FACTOR #define ARCADE_MACHINE_RES_Y 1080 * ARCADE_MACHINE_SCALING_FACTOR -#define ROWS 7 -#define COLS 15 - #ifdef _WIN32 #define ARCADE_MACHINE_PATH_SEP "\\" #else diff --git a/src/ConfigData.cpp b/src/ConfigData.cpp index d166b68..d0df7ec 100644 --- a/src/ConfigData.cpp +++ b/src/ConfigData.cpp @@ -3,8 +3,6 @@ #include "Configuration.h" #include #include -#include -#include #include #include @@ -188,24 +186,23 @@ void ConfigData::collectJsonData(json json_configs) */ bool ConfigData::getFromGit(std::string url, const char* dir) { - // info struct lets us query the directory to see if it exists - struct stat info; - bool isPull = (stat(dir, &info) == 0 && (info.st_mode & S_IFDIR)); + fs::path dirPath(dir); + bool isPull = fs::is_directory(dirPath) && fs::exists(dirPath / ".git"); + + int exitCode; if (isPull) { std::cerr << "[Git] pulling: " << url << " → " << dir << std::endl; - system(("git -C " + std::string(dir) + " pull " + url).c_str()); + exitCode = system(("git -C " + std::string(dir) + " pull " + url).c_str()); } else { std::cerr << "[Git] cloning: " << url << " → " << dir << std::endl; - system(("git clone " + url + " " + dir).c_str()); + exitCode = system(("git clone " + url + " " + dir).c_str()); } - // Verify the directory actually exists after the git operation - struct stat checkInfo; - bool success = (stat(dir, &checkInfo) == 0 && (checkInfo.st_mode & S_IFDIR)); + bool success = (exitCode == 0); if (success) std::cerr << "[Git] " << (isPull ? "pull" : "clone") << " succeeded: " << dir << std::endl; From a81f3713c7b19e9abc5e408998fc36b12794f1af Mon Sep 17 00:00:00 2001 From: HAOYU LIU Date: Sun, 24 May 2026 10:38:43 +1000 Subject: [PATCH 3/3] fix: resolve PR #91 review issues - Configuration.h: re-add ROWS/COLS with #ifndef guards to prevent redefinition conflict when ArcadeMachine.h is also included - ConfigData.cpp: fix system() exit code extraction on Linux by using WIFEXITED()/WEXITSTATUS() macros from sys/wait.h; Windows path uses exitCode == 0 directly (no wait status wrapping) --- include/Configuration.h | 11 ++++++++++- src/ConfigData.cpp | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/Configuration.h b/include/Configuration.h index 537c24f..891ab0e 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -28,4 +28,13 @@ #define ARCADE_MACHINE_BINARY_EXT ".out" #endif -#endif \ No newline at end of file + +// Grid layout dimensions; guarded to prevent redefinition if ArcadeMachine.h is also included +#ifndef ROWS +#define ROWS 7 +#endif +#ifndef COLS +#define COLS 15 +#endif + +#endif diff --git a/src/ConfigData.cpp b/src/ConfigData.cpp index d0df7ec..3d17de7 100644 --- a/src/ConfigData.cpp +++ b/src/ConfigData.cpp @@ -5,6 +5,9 @@ #include #include #include +#ifndef _WIN32 +#include +#endif #if __cplusplus >= 201703L #include @@ -202,7 +205,11 @@ bool ConfigData::getFromGit(std::string url, const char* dir) exitCode = system(("git clone " + url + " " + dir).c_str()); } +#ifdef _WIN32 bool success = (exitCode == 0); +#else + bool success = WIFEXITED(exitCode) && (WEXITSTATUS(exitCode) == 0); +#endif if (success) std::cerr << "[Git] " << (isPull ? "pull" : "clone") << " succeeded: " << dir << std::endl;