Verified Commit 2ec9c442 authored by RobLoach's avatar RobLoach
Browse files

0.27.0

parent 050bf6e0
......@@ -4,13 +4,14 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be
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 - 2018-09-25
## 0.27.0 - 2018-09-25
### Features
- Live updating of core options
- Mounts `/libretro/core` as the directory where the core was loaded from
- Adds `love.filesystem.getSaveDirectory()`
- Adds `love.filesystem.newFileData(contents, name)`
- Adds `love.filesystem.getExecutablePath()`
- Adds `love.filesystem.remove()`
### Fixes
- Fixed loading ChaiLove without active content
......
......@@ -85,6 +85,8 @@ class filesystem {
* If the file exists in the .love but not in the save directory, it returns false as well.
* An opened File prevents removal of the underlying file. Simply close the File to remove it.
*
* @param name The file or directory to remove.
*
* @return True if the file or directory was removed, false otherwise.
*/
bool remove(const std::string& name);
......
diff --git a/.gitignore b/.gitignore
index 3e22579..a32a01e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,3 @@ node_modules
/package.json
/.bsv
/*.mkv
-libretro-chailove-test.txt
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8d20826..089c67f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Mounts `/libretro/core` as the directory where the core was loaded from
- Adds `love.filesystem.getSaveDirectory()`
- Adds `love.filesystem.newFileData(contents, name)`
+- Adds `love.filesystem.getExecutablePath()`

### Fixes
- Fixed loading ChaiLove without active content
diff --git a/src/love/filesystem.cpp b/src/love/filesystem.cpp
index e7d2fae..98b892c 100644
--- a/src/love/filesystem.cpp
+++ b/src/love/filesystem.cpp
@@ -8,6 +8,7 @@
#include "filesystem/path.h"
#include "../ChaiLove.h"
#include "Types/FileSystem/FileInfo.h"
+#include <SDL.h>

using love::Types::FileSystem::FileInfo;
using love::Types::FileSystem::FileData;
@@ -222,14 +223,10 @@ bool filesystem::unmount(const std::string& archive) {
}

bool filesystem::mount(const char *archive, const std::string& mountpoint) {
- // Allow mounting character pointers safely.
- if (archive == NULL) {
- return false;
- }
return mount(std::string(archive), mountpoint);
}

-std::string filesystem::getWorkingDirectory() {
+std::string filesystem::getExecutablePath() {
return std::string(PHYSFS_getBaseDir());
}

@@ -239,25 +236,18 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint

bool filesystem::mount(const std::string& archive, const std::string& mountpoint, bool appendToPath) {
// Protect against empty archive/mount points.
- std::string finalArchive;
int append = appendToPath ? 1 : 0;
- if (archive.length() <= 0 || mountpoint.length() <= 0) {
+ if (archive.length() <= 0) {
+ std::cout << "[ChaiLove] [filesystem] Mounting failed because archive was empty." << std::endl;
return false;
}

- if (archive == ".") {
- finalArchive = getWorkingDirectory();
- }
- else {
- finalArchive = archive;
- }
-
// Display a message.
- std::cout << "[ChaiLove] [filesystem] Mounting " << finalArchive << " as " << mountpoint << std::endl;
+ std::cout << "[ChaiLove] [filesystem] Mounting " << archive << " as " << mountpoint << std::endl;

// Use the simple mount method if we're mounting the root directory.
if (mountpoint == "/") {
- int returnValue = PHYSFS_mount(finalArchive.c_str(), mountpoint.c_str(), append);
+ int returnValue = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), append);
if (returnValue == 0) {
std::cout << "[ChaiLove] [filesystem] Error mounting /: " << getLastError() << std::endl;
return false;
@@ -266,11 +256,11 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint
}

// See if we're mounting a file.
- if (isFile(finalArchive)) {
+ if (isFile(archive)) {
// Mount using a handle instead, since we're doing another archive.
- PHYSFS_File* file = openFile(finalArchive);
+ PHYSFS_File* file = openFile(archive);
if (file != NULL) {
- if (PHYSFS_mountHandle(file, finalArchive.c_str(), mountpoint.c_str(), append) == 0) {
+ if (PHYSFS_mountHandle(file, archive.c_str(), mountpoint.c_str(), append) == 0) {
std::cout << "[ChaiLove] [filesystem] Error mounting file: " << getLastError() << std::endl;
return false;
}
@@ -280,15 +270,12 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint
}

// Check if we're mounting a directory.
- if (isDirectory(finalArchive)) {
- int returnVal = PHYSFS_mount(finalArchive.c_str(), mountpoint.c_str(), append);
- if (returnVal == 0) {
- std::cout << "[ChaiLove] [filesystem] Error mounting directory: " << getLastError() << std::endl;
- return false;
- }
- return true;
+ int returnVal = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), append);
+ if (returnVal == 0) {
+ std::cout << "[ChaiLove] [filesystem] Error mounting directory: " << getLastError() << std::endl;
+ return false;
}
- return false;
+ return true;
}

/**
diff --git a/src/love/filesystem.h b/src/love/filesystem.h
index b263d7b..3b2c562 100644
--- a/src/love/filesystem.h
+++ b/src/love/filesystem.h
@@ -223,11 +223,11 @@ class filesystem {
std::vector<std::string> lines(const std::string& filename);

/**
- * Gets the current working directory.
+  * Get the path to the executable that was used to run this application.
*
- * @return The current working directory.
+  * @return The base path of the application.
*/
- std::string getWorkingDirectory();
+ std::string getExecutablePath();

std::string getLastError();
};
diff --git a/src/love/script.cpp b/src/love/script.cpp
index 1b8ae1f..9269419 100644
--- a/src/love/script.cpp
+++ b/src/love/script.cpp
@@ -290,10 +290,10 @@ script::script(const std::string& file) {
chai.add(fun(&filesystem::createDirectory), "createDirectory");
chai.add(fun(&filesystem::isSymlink), "isSymlink");
chai.add(fun(&filesystem::isFile), "isFile");
- chai.add(fun(&filesystem::getWorkingDirectory), "getWorkingDirectory");
chai.add(fun(&filesystem::write), "write");
chai.add(fun(&filesystem::remove), "remove");
chai.add(fun(&filesystem::exists), "exists");
+ chai.add(fun(&filesystem::getExecutablePath), "getExecutablePath");
chai.add(fun(&filesystem::getSaveDirectory), "getSaveDirectory");
chai.add(fun(&filesystem::getInfo), "getInfo");
chai.add(fun<FileData, filesystem, const std::string&>(&filesystem::newFileData), "newFileData");
diff --git a/test/.gitignore b/test/.gitignore
index 852dc25..41ee3e1 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,2 +1,2 @@
/test
-/createDirectoryTest
+createDirectoryTest
diff --git a/test/unittests/filesystem.chai b/test/unittests/filesystem.chai
index c1285a3..9cd6c81 100644
--- a/test/unittests/filesystem.chai
+++ b/test/unittests/filesystem.chai
@@ -62,13 +62,21 @@ assert_equal(newFileData.getString(), "Hello World!", " newFileData.getString
assert_equal(love.filesystem.getSaveDirectory(), "/libretro/saves", "love.filesystem.getSaveDirectory()")

// createDirectory()
-var createDirectoryReturn = love.filesystem.createDirectory("test/createDirectoryTest")
+var createDirectoryReturn = love.filesystem.createDirectory("test/unittests/createDirectoryTest")
assert(createDirectoryReturn, "love.filesystem.createDirectory()")

// write()
-var writeFileReturn = love.filesystem.write("test/createDirectoryTest/test.md", "# Test\n\nHello World!");
+var writeFileReturn = love.filesystem.write("test/unittests/createDirectoryTest/test.md", "# Test\n\nHello World!");
assert(writeFileReturn, "love.filesystem.write()")

+// remove()
+assert(love.filesystem.exists("createDirectoryTest/test.md"), "love.filesystem.remove()")
+assert(love.filesystem.exists("createDirectoryTest"), " directory exists")
+assert(love.filesystem.remove("test/unittests/createDirectoryTest/test.md"), " remove file")
+assert_not(love.filesystem.exists("createDirectoryTest/test.md"), " file is gone")
+assert(love.filesystem.remove("test/unittests/createDirectoryTest"), " remove directory")
+assert_not(love.filesystem.exists("createDirectoryTest"), " directory is gone")
+
// mount()
var mountResult = love.filesystem.mount("assets/hello.zip", "hello")
assert(mountResult, "love.filesystem.mount()")
@@ -94,14 +102,3 @@ requiretestFileLoaded = false
requireReturn = require("assets.requiretest")
assert(requireReturn, " double call")
assert_not(requiretestFileLoaded, " not loaded twice")
-
-// remove()
-var removeTestDestination = "libretro-chailove-test.txt"
-print(removeTestDestination)
-
-print(love.filesystem.getDirectoryItems("/libretro/saves"))
-
-love.filesystem.write(removeTestDestination, "Hello World!")
-assert(love.filesystem.exists("libretro/saves/" + removeTestDestination), "love.filesystem.write(saveDirectory)")
-//love.filesystem.remove(removeTestDestination)
-//assert_not(love.filesystem.exists(removeTestDestination), "love.filesystem.remove()")
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