Commit 3e81c78b authored by Bkg2k's avatar Bkg2k Committed by OyyoDams

feat(externals): write real-time system/game information to /tmp/es_state.inf

parent f758d8bd
......@@ -11,6 +11,7 @@
#include <boost/make_shared.hpp>
#include <RecalboxConf.h>
#include <RootFolders.h>
#include <recalbox/RecalboxSystem.h>
std::vector<SystemData *> SystemData::sSystemVector;
......@@ -208,7 +209,9 @@ void SystemData::launchGame(Window* window, FileData* game, const std::string& n
LOG(LogInfo) << " " << command;
std::cout << "==============================================\n";
RecalboxSystem::getInstance()->NotifyGame(*game, true, false);
int exitCode = runSystemCommand(command);
RecalboxSystem::getInstance()->NotifyGame(*game, false, false);
std::cout << "==============================================\n";
if( exitCode != 0)
......@@ -278,10 +281,11 @@ bool SystemData::demoLaunchGame(FileData* game, int duration, const std::string&
command += std::to_string(duration);
LOG(LogInfo) << "Demo command: " << command;
//std::cout << " " << command << "\r\n";
RecalboxSystem::getInstance()->NotifyGame(*game, true, true);
int exitCode = runSystemCommand(command);
RecalboxSystem::getInstance()->NotifyGame(*game, false, false);
LOG(LogInfo) << "Demo exit code : " << exitCode;
//std::cout << "ExitCode : " << exitCode << "\r\n";
// Configgen returns an exitcode 0x33 when the user interact with any pad/mouse
// this exitcode returns here byte-swapped or shifted. Need further investigation
......
......@@ -14,6 +14,7 @@
#include "AudioManager.h"
#include "VolumeControl.h"
#include "SystemData.h"
#include <ifaddrs.h>
#include <fstream>
......@@ -37,6 +38,24 @@ RecalboxSystem *RecalboxSystem::getInstance() {
return RecalboxSystem::instance;
}
void RecalboxSystem::NotifySystemAndGame(const SystemData* system, const FileData* game, bool play, bool demo)
{
std::string output;
output.append("System=").append((system != nullptr) ? system->getFullName() : "").append("\r\n");
output.append("SystemId=").append((system != nullptr) ? system->getName() : "").append("\r\n");
output.append("Game=").append((game != nullptr) ? game->getName() : "").append("\r\n");
output.append("GamePath=").append((game != nullptr) ? game->getPath().generic_string() : "").append("\r\n");
output.append("ImagePath=").append((game != nullptr) ? game->Metadata().Image() : "").append("\r\n");
output.append("State=").append(play ? (demo ? "demo" : "playing") : "selected").append("\r\n");
FILE* f = fopen("/tmp/es_state.inf", "w");
if (f != nullptr)
{
fwrite(output.c_str(), output.size(), 1, f);
fclose(f);
}
}
unsigned long RecalboxSystem::getFreeSpaceGB(std::string mountpoint) {
struct statvfs fiData;
const char *fnPath = mountpoint.c_str();
......
......@@ -4,6 +4,7 @@
#include <string>
#include "Window.h"
#include "components/BusyComponent.h"
#include "FileData.h"
struct EmulatorDefaults {
std::string core;
......@@ -81,6 +82,9 @@ public:
EmulatorDefaults getEmulatorDefaults(std::string emulatorName);
void NotifyGame(const FileData& game, bool play, bool demo) { NotifySystemAndGame(game.getSystem(), &game, play, demo); }
void NotifySystem(const SystemData& system) { NotifySystemAndGame(&system, nullptr, false, false); }
private:
static RecalboxSystem *instance;
......@@ -91,6 +95,7 @@ private:
std::string runCmd(std::string cmd);
std::string getJSONStringValue(std::string json, std::string key);
void NotifySystemAndGame(const SystemData* system, const FileData* game, bool play, bool demo);
};
#endif
......
......@@ -351,6 +351,9 @@ void SystemView::onCursorChanged(const CursorState& state)
// update help style
updateHelpPrompts();
// update externs
RecalboxSystem::getInstance()->NotifySystem(*getSelected());
float startPos = mCamOffset;
float posMax = (float)mEntries.size();
......
......@@ -77,6 +77,8 @@ void ViewController::goToSystemView(SystemData* system)
mCurrentView->onShow();
playViewTransition();
RecalboxSystem::getInstance()->NotifySystem(*system);
}
void ViewController::goToNextGameList()
......@@ -147,6 +149,8 @@ void ViewController::goToGameList(SystemData* system)
mCurrentView = getGameListView(system);
playViewTransition();
RecalboxSystem::getInstance()->NotifyGame(*getGameListView(system).get()->getCursor(), false, false);
}
void ViewController::updateFavorite(SystemData* system, FileData* file)
......
......@@ -11,6 +11,7 @@
#include "Settings.h"
#include "Locale.h"
#include <boost/assign.hpp>
#include <recalbox/RecalboxSystem.h>
static const std::map<std::string, const char*> favorites_icons_map = boost::assign::map_list_of
("snes" , "\uF25e ")
......@@ -299,8 +300,10 @@ void BasicGameListView::setCursorIndex(int index){
mList.setCursorIndex(index);
}
int BasicGameListView::getCursorIndex(){
return mList.getCursorIndex();
int BasicGameListView::getCursorIndex()
{
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
return mList.getCursorIndex();
}
void BasicGameListView::setCursor(FileData* cursor)
......@@ -330,6 +333,7 @@ void BasicGameListView::setCursor(FileData* cursor)
}
}
}
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
}
void BasicGameListView::launch(FileData* game) {
......
......@@ -142,7 +142,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) {
setCursorIndex(0);
}
}
return true;
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
return true;
}
if(config->isMappedTo("a", input))
......@@ -159,6 +160,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) {
setCursor(selected);
//Sound::getFromTheme(getTheme(), getName(), "back")->play();
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
}
else if (!hideSystemView)
{
......@@ -209,7 +211,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) {
setCursorIndex(std::max(0, cursorPlace + (removeFavorite ? -1 : 1)));
}
}
return true;
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
return true;
}
if (config->isMappedTo("right", input)) {
......@@ -220,7 +223,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) {
mFavoriteChange = false;
}
ViewController::get()->goToNextGameList();
return true;
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
return true;
}
}
......@@ -232,6 +236,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) {
mFavoriteChange = false;
}
ViewController::get()->goToPrevGameList();
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
return true;
}
}else if ((config->isMappedTo("x", input)) && (RecalboxConf::getInstance()->get("global.netplay") == "1")
......@@ -246,5 +251,14 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) {
}
}
return IGameListView::input(config, input);
bool result = IGameListView::input(config, input);
// TODO: Guess there is a better way to detect a game change
if (config->isMappedTo("down", input) ||
config->isMappedTo("up", input) ||
config->isMappedTo("pagedown", input) ||
config->isMappedTo("pageup", input) )
RecalboxSystem::getInstance()->NotifyGame(*getCursor(), false, false);
return result;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment