-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Windows cross-platform compatibility and bug fixes #91
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ logs/ | |
| **/*.exe | ||
| **/*.out* | ||
| resources/databases/* | ||
| games/* | ||
| games/ | ||
| **/*.o | ||
| ArcadeMachine | ||
| **/.DS_Store | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no particular need to override 0 stars to max rating. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,20 @@ | |
| #include "Configuration.h" | ||
| #include <regex> | ||
| #include <iostream> | ||
| #include <sys/stat.h> | ||
| #include <sys/types.h> | ||
| #include <cstring> | ||
| #include <exception> | ||
| #ifndef _WIN32 | ||
| #include <sys/wait.h> | ||
| #endif | ||
|
|
||
| #if __cplusplus >= 201703L | ||
| #include <filesystem> | ||
| namespace fs = std::filesystem; | ||
| #else | ||
| #define _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM | ||
| #include <experimental/filesystem> | ||
| namespace fs = std::experimental::filesystem; | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Construct a new Config Data object | ||
|
|
@@ -18,6 +26,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 +84,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); | ||
| } | ||
|
|
||
|
|
@@ -139,25 +189,34 @@ 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; | ||
| 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) | ||
| fs::path dirPath(dir); | ||
| bool isPull = fs::is_directory(dirPath) && fs::exists(dirPath / ".git"); | ||
|
|
||
| int exitCode; | ||
|
|
||
| if (isPull) | ||
| { | ||
| // dir exists -- pull instead | ||
| system(("git -C " + std::string(dir) + " pull " + url).c_str()); | ||
| std::cerr << "[Git] pulling: " << url << " → " << dir << std::endl; | ||
| exitCode = system(("git -C " + std::string(dir) + " pull " + url).c_str()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work on linux (even though it perfectly does on Windows). You will have to wrap it in the special macros to get the actual exit code. Please see
|
||
| } | ||
| else | ||
| { | ||
| // dir does not exist -- clone from scratch | ||
| system(("git clone " + url + " " + dir).c_str()); | ||
| std::cerr << "[Git] cloning: " << url << " → " << dir << std::endl; | ||
| exitCode = system(("git clone " + url + " " + dir).c_str()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly to my comment on 197, pointing out that this is not going to work on linux. |
||
| } | ||
|
|
||
| return true; | ||
| #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; | ||
| else | ||
| std::cerr << "[Git] " << (isPull ? "pull" : "clone") << " failed: " << dir << std::endl; | ||
|
|
||
| return success; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As changed in #87, dependency on this function has been removed, so there is no need to add this.