Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logs/
**/*.exe
**/*.out*
resources/databases/*
games/*
games/
**/*.o
ArcadeMachine
**/.DS_Store
2 changes: 1 addition & 1 deletion include/ConfigData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
11 changes: 10 additions & 1 deletion include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@
#define ARCADE_MACHINE_BINARY_EXT ".out"
#endif

#endif

// 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
24 changes: 24 additions & 0 deletions include/Database.h
Copy link
Copy Markdown

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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@
#include <map>
#include <tuple>

// ---------------------------------------------------------------------------
// 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;
Expand Down
11 changes: 11 additions & 0 deletions include/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -46,6 +49,12 @@ class Helper {
{
vector<string> 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")
Expand All @@ -55,6 +64,8 @@ class Helper {
}
}

std::cerr << "[Helper] found " << files.size() << " config files in " << dir << std::endl;

return files;
}

Expand Down
2 changes: 1 addition & 1 deletion include/Rating.h
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
Expand Up @@ -38,7 +38,7 @@ class Rating
if (key_typed(LEFT_KEY))
{
--_rating;
if (_rating < 0)
if (_rating < 1)
_rating = _maxRating;
updateGrid();
}
Expand Down
8 changes: 4 additions & 4 deletions resources/bundles/resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
91 changes: 75 additions & 16 deletions src/ConfigData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 system manual entry on linux:

the return value is a "wait status" that can be examined using the macros described in waitpid(2). (i.e., WIFEXITED(), WEXITSTATUS(), and so on)

}
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());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
}

/**
Expand Down