Unverified Commit 602d6b59 authored by RobLoach's avatar RobLoach
Browse files

Add filesystem updates

parent 6795e0f3
......@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 0.26.2 - Unreleased
### Features
- Live updating of core options
- Mounts `/libretro/core` as the directory where the core was loaded from
- Adds `love.filesystem.getSaveDirectory()`
### Fixes
- Fixed loading ChaiLove without active content
......
......@@ -79,6 +79,8 @@ void retro_set_environment(retro_environment_t cb) {
*/
static void update_variables(void) {
std::cout << "[ChaiLove] [libretro] update_variables()" << std::endl;
ChaiLove* app = ChaiLove::getInstance();
app->system.updateVariables(app->config);
}
#ifdef __cplusplus
......@@ -427,6 +429,11 @@ void retro_run(void) {
return;
}
bool updated = false;
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) {
update_variables();
}
// Update the game.
app->update();
......
......@@ -56,6 +56,13 @@ void filesystem::mountlibretro() {
const char *system_dir = NULL;
const char *assets_dir = NULL;
const char *save_dir = NULL;
const char *core_dir = NULL;
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_LIBRETRO_PATH, &core_dir) && core_dir) {
// Make sure to get the directory of the core.
::filesystem::path p(core_dir);
mount(p.parent_path().str(), "/libretro/core");
}
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir) {
mount(system_dir, "/libretro/system");
}
......@@ -369,6 +376,10 @@ FileData filesystem::newFileData(const std::string& filepath) {
return f;
}
std::string filesystem::getSaveDirectory() {
return "/libretro/saves";
}
bool filesystem::createDirectory(const std::string& name) {
int ret = PHYSFS_mkdir(name.c_str());
if (ret == 0) {
......
......@@ -121,6 +121,13 @@ class filesystem {
bool mount(const std::string& archive, const std::string& mountpoint);
bool mount(const char *archive, const std::string& mountpoint);
/**
* Gets the path to the designated save directory.
*
* @return The path to the save directory.
*/
std::string getSaveDirectory();
PHYSFS_sint64 getSize(PHYSFS_File* file);
PHYSFS_file* openFile(const std::string& filename);
......
......@@ -292,6 +292,7 @@ script::script(const std::string& file) {
chai.add(fun(&filesystem::isFile), "isFile");
chai.add(fun(&filesystem::write), "write");
chai.add(fun(&filesystem::exists), "exists");
chai.add(fun(&filesystem::getSaveDirectory), "getSaveDirectory");
chai.add(fun(&filesystem::getInfo), "getInfo");
chai.add(fun(&filesystem::newFileData), "newFileData");
chai.add(fun(&filesystem::getDirectoryItems), "getDirectoryItems");
......
......@@ -17,6 +17,7 @@ class sound {
bool hasAudio();
void unload();
void update();
~sound();
/**
......
......@@ -62,7 +62,7 @@ std::string system::getVersionString() {
return CHAILOVE_VERSION_STRING;
}
bool system::load(config& t) {
void system::updateVariables(config& t) {
// Update core option from the libretro variables.
struct retro_variable var = {0};
......@@ -85,6 +85,11 @@ bool system::load(config& t) {
t.options["highquality"] = false;
}
}
}
bool system::load(config& t) {
// Ensure we retrieve the latest variable states.
updateVariables(t);
// Load the semantic version string.
semver_t chailoveVersion = {};
......
......@@ -121,6 +121,7 @@ class system {
* @see love.system.getClipboardText
*/
system& setClipboardText(const std::string& text);
void updateVariables(config& t);
bool load(config& t);
......
......@@ -56,6 +56,9 @@ var fileDataContents = loadedFileData.getString()
var fileDataFind = fileDataContents.find("// newFileData()")
assert_greater(fileDataFind, 50, " .getString()")
// getSaveDirectory()
assert_equal(love.filesystem.getSaveDirectory(), "/libretro/saves", "love.filesystem.getSaveDirectory()")
// createDirectory()
var createDirectoryReturn = love.filesystem.createDirectory("test/createDirectoryTest")
assert(createDirectoryReturn, "love.filesystem.createDirectory()")
......
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