Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
libretro-chailove
Commits
496bdc6b
Unverified
Commit
496bdc6b
authored
Sep 22, 2018
by
RobLoach
Browse files
Add newFileData
parent
602d6b59
Changes
7
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
496bdc6b
...
...
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
-
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)`
### Fixes
-
Fixed loading ChaiLove without active content
...
...
src/love/Types/FileSystem/FileData.cpp
View file @
496bdc6b
...
...
@@ -16,6 +16,10 @@ FileData::FileData(const std::string& filepath) : m_filepath(filepath) {
// Nothing.
}
FileData
::
FileData
(
const
std
::
string
&
contents
,
const
std
::
string
&
name
)
:
m_contents
(
contents
),
m_filepath
(
name
)
{
// Nothing.
}
int
FileData
::
getSize
()
{
ChaiLove
*
app
=
ChaiLove
::
getInstance
();
return
app
->
filesystem
.
getSize
(
m_filepath
);
...
...
@@ -26,8 +30,11 @@ std::string FileData::getFilename() {
}
std
::
string
FileData
::
getString
()
{
if
(
!
m_contents
.
empty
())
{
return
m_contents
;
}
ChaiLove
*
app
=
ChaiLove
::
getInstance
();
return
app
->
filesystem
.
read
(
m_filepath
);
return
m_contents
=
app
->
filesystem
.
read
(
m_filepath
);
}
std
::
string
FileData
::
getExtension
()
{
...
...
src/love/Types/FileSystem/FileData.h
View file @
496bdc6b
...
...
@@ -20,6 +20,13 @@ class FileData {
* @param filepath Path to the file.
*/
FileData
(
const
std
::
string
&
filepath
);
/**
* Creates a new FileData from the given data and filename.
*
* @param contents The data for the file.
* @param name The filename of the file.
*/
FileData
(
const
std
::
string
&
contents
,
const
std
::
string
&
name
);
/**
* The size of the Data in bytes.
...
...
@@ -42,6 +49,7 @@ class FileData {
std
::
string
getExtension
();
std
::
string
m_filepath
;
std
::
string
m_contents
;
};
}
// namespace FileSystem
...
...
src/love/filesystem.cpp
View file @
496bdc6b
...
...
@@ -376,6 +376,11 @@ FileData filesystem::newFileData(const std::string& filepath) {
return
f
;
}
FileData
filesystem
::
newFileData
(
const
std
::
string
&
contents
,
const
std
::
string
&
name
)
{
FileData
f
(
contents
,
name
);
return
f
;
}
std
::
string
filesystem
::
getSaveDirectory
()
{
return
"/libretro/saves"
;
}
...
...
src/love/filesystem.h
View file @
496bdc6b
...
...
@@ -100,6 +100,18 @@ class filesystem {
*/
FileData
newFileData
(
const
std
::
string
&
filepath
);
/**
* Creates a new FileData object.
*
* @param contents The contents fof the file.
* @param name The name of the file.
*
* @return Your new FileData.
*
* @see love::Types::FileSystem::FileData
*/
FileData
newFileData
(
const
std
::
string
&
contents
,
const
std
::
string
&
name
);
/**
* Unmounts a zip file or folder previously mounted with love.filesystem.mount.
*
...
...
src/love/script.cpp
View file @
496bdc6b
...
...
@@ -294,7 +294,8 @@ script::script(const std::string& file) {
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
<
FileData
,
filesystem
,
const
std
::
string
&>
(
&
filesystem
::
newFileData
),
"newFileData"
);
chai
.
add
(
fun
<
FileData
,
filesystem
,
const
std
::
string
&
,
const
std
::
string
&>
(
&
filesystem
::
newFileData
),
"newFileData"
);
chai
.
add
(
fun
(
&
filesystem
::
getDirectoryItems
),
"getDirectoryItems"
);
chai
.
add
(
fun
<
bool
,
filesystem
,
const
std
::
string
&
,
const
std
::
string
&>
(
&
filesystem
::
mount
),
"mount"
);
chai
.
add
(
fun
<
int
,
filesystem
,
const
std
::
string
&>
(
&
filesystem
::
getSize
),
"getSize"
);
...
...
test/unittests/filesystem.chai
View file @
496bdc6b
...
...
@@ -55,6 +55,8 @@ assert_equal(loadedFileData.getFilename(), "filesystem.chai", " .getFilename(
var fileDataContents = loadedFileData.getString()
var fileDataFind = fileDataContents.find("// newFileData()")
assert_greater(fileDataFind, 50, " .getString()")
var newFileData = love.filesystem.newFileData("Hello World!", "helloworld.txt")
assert_equal(newFileData.getString(), "Hello World!", " newFileData.getString()")
// getSaveDirectory()
assert_equal(love.filesystem.getSaveDirectory(), "/libretro/saves", "love.filesystem.getSaveDirectory()")
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment