mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 02:05:55 +02:00
Fixed table pushing for LuaCollection::getItemAt(). Cleaned up configuration loading.
This commit is contained in:
@@ -22,6 +22,58 @@ int LuaCollection::load(lua_State *l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaCollection::getSize(lua_State *l)
|
||||
{
|
||||
CollectionInfo *i = (CollectionInfo *)luaL_checkinteger(l, 1);
|
||||
|
||||
lua_pushinteger(l, (int)i->items.size());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaCollection::getName(lua_State *l)
|
||||
{
|
||||
CollectionInfo *i = (CollectionInfo *)luaL_checkinteger(l, 1);
|
||||
|
||||
lua_pushstring(l, i->name.c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaCollection::getItemAt(lua_State *l)
|
||||
{
|
||||
CollectionInfo *i = (CollectionInfo *)luaL_checkinteger(l, 1);
|
||||
int index = (int)luaL_checkinteger(l, 2);
|
||||
Item *item = i->items.at(index);
|
||||
|
||||
std::string name;
|
||||
std::string filepath;
|
||||
std::string title;
|
||||
std::string fullTitle;
|
||||
std::string year;
|
||||
std::string manufacturer;
|
||||
std::string genre;
|
||||
std::string cloneof;
|
||||
std::string numberPlayers;
|
||||
std::string numberButtons;
|
||||
|
||||
lua_createtable(l, 0, 4);
|
||||
lua_pushstring(l, "name");
|
||||
lua_pushstring(l, item->name.c_str());
|
||||
lua_settable(l, -3);
|
||||
|
||||
lua_pushstring(l, "title");
|
||||
lua_pushstring(l, item->title.c_str());
|
||||
lua_settable(l, -3);
|
||||
|
||||
lua_pushstring(l, "filepath");
|
||||
lua_pushstring(l, item->filepath.c_str());
|
||||
lua_settable(l, -3);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int LuaCollection::destroy(lua_State *l)
|
||||
{
|
||||
CollectionInfo *i = (CollectionInfo *)luaL_checkinteger(l, 1);
|
||||
@@ -31,9 +83,17 @@ int LuaCollection::destroy(lua_State *l)
|
||||
}
|
||||
|
||||
|
||||
CollectionInfo *loadingCollection = NULL;
|
||||
void LuaCollection::loadCallback(void *context, CollectionInfo *info)
|
||||
{
|
||||
lua_State *l = (lua_State *)context;
|
||||
events->trigger(l, "onCollectionLoaded", (void *)info);
|
||||
|
||||
loadingCollection = info;
|
||||
}
|
||||
|
||||
void LuaCollection::update(lua_State *l) {
|
||||
if(loadingCollection) {
|
||||
events->trigger(l, "onCollectionLoaded", (void *)loadingCollection);
|
||||
loadingCollection = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ namespace LuaCollection
|
||||
{
|
||||
void initialize(Configuration *c, CollectionInfoBuilder *b, LuaEvent *e);
|
||||
int load(lua_State *l);
|
||||
int getSize(lua_State *l);
|
||||
int getName(lua_State *l);
|
||||
int getItemAt(lua_State *l);
|
||||
int destroy(lua_State *l);
|
||||
void update(lua_State *l);
|
||||
|
||||
void loadCallback(void *context, CollectionInfo *info);
|
||||
};
|
||||
@@ -30,7 +30,9 @@ int main(int argc, char **argv)
|
||||
{
|
||||
Configuration::initialize();
|
||||
Configuration config;
|
||||
config.import("", "C:/Users/Don/Downloads/RetroFE-FTP/settings.conf");
|
||||
if(!ImportConfiguration(&config)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!StartLogging())
|
||||
{
|
||||
@@ -46,6 +48,96 @@ int main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ImportConfiguration(Configuration *c)
|
||||
{
|
||||
std::string configPath = Configuration::absolutePath;
|
||||
std::string launchersPath = Utils::combinePath(Configuration::absolutePath, "launchers");
|
||||
std::string collectionsPath = Utils::combinePath(Configuration::absolutePath, "collections");
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
|
||||
std::string settingsConfPath = Utils::combinePath(configPath, "settings.conf");
|
||||
if(!c->import("", settingsConfPath))
|
||||
{
|
||||
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsConfPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string controlsConfPath = Utils::combinePath(configPath, "controls.conf");
|
||||
if(!c->import("controls", controlsConfPath))
|
||||
{
|
||||
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + controlsConfPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
dp = opendir(launchersPath.c_str());
|
||||
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::write(Logger::ZONE_NOTICE, "RetroFE", "Could not read directory \"" + launchersPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
|
||||
{
|
||||
std::string basename = dirp->d_name;
|
||||
|
||||
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
|
||||
basename = basename.substr(0, basename.find_last_of("."));
|
||||
|
||||
if(extension == ".conf")
|
||||
{
|
||||
std::string prefix = "launchers." + basename;
|
||||
|
||||
std::string importFile = Utils::combinePath(launchersPath, std::string(dirp->d_name));
|
||||
|
||||
if(!c->import(prefix, importFile))
|
||||
{
|
||||
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\"");
|
||||
closedir(dp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dp);
|
||||
|
||||
dp = opendir(collectionsPath.c_str());
|
||||
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not read directory \"" + collectionsPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
std::string collection = (dirp->d_name);
|
||||
if (dirp->d_type == DT_DIR && collection != "." && collection != ".." && collection.length() > 0 && collection[0] != '_')
|
||||
{
|
||||
std::string prefix = "collections." + collection;
|
||||
|
||||
std::string settingsFile = Utils::combinePath(collectionsPath, collection, "settings.conf");
|
||||
|
||||
if(!c->import(collection, prefix, settingsFile))
|
||||
{
|
||||
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsFile + "\"");
|
||||
closedir(dp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dp);
|
||||
|
||||
Logger::write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StartLogging()
|
||||
{
|
||||
std::string logFile = Utils::combinePath(Configuration::absolutePath, "log.txt");
|
||||
|
||||
@@ -83,6 +83,9 @@ const luaL_Reg RetroFE::luaImageFuncs[] = {
|
||||
const luaL_Reg RetroFE::luaCollectionFuncs[] = {
|
||||
{"load", LuaCollection::load},
|
||||
{"destroy", LuaCollection::destroy},
|
||||
{"getSize", LuaCollection::getSize},
|
||||
{"getName", LuaCollection::getName},
|
||||
{"getItemAt", LuaCollection::getItemAt},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -188,6 +191,8 @@ void RetroFE::run()
|
||||
|
||||
deltaTime = currentTime - lastTime;
|
||||
|
||||
LuaCollection::update(lua_.state);
|
||||
|
||||
state.update((float)deltaTime);
|
||||
|
||||
SDL_LockMutex(SDL::getMutex());
|
||||
|
||||
Reference in New Issue
Block a user