Skip to content
10 changes: 5 additions & 5 deletions src/modules/app/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void App::onFrame() {
if (!request.execute(stream, &statusCode)) {
Log::error("Failed to upload crash log with status: %i", statusCode);
} else {
_filesystem->sysRemoveFile(crashlogFilename);
_filesystem->sysRemoveFile(core::Path(crashlogFilename));
}
}
}
Expand Down Expand Up @@ -447,9 +447,9 @@ AppState App::onConstruct() {
}
core_assert_init(_filesystem->homePath().c_str());

for (const core::String &path : _filesystem->registeredPaths()) {
for (const core::Path &path : _filesystem->registeredPaths()) {
_dictManager.addDirectory(path);
_dictManager.addDirectory(core::string::path(path, "po"));
_dictManager.addDirectory(path.append("po"));
}

FL_Locale *locale = nullptr;
Expand Down Expand Up @@ -595,7 +595,7 @@ AppState App::onConstruct() {
#endif
}

const core::String &logfilePath = _filesystem->homeWritePath("log.txt");
const core::Path &logfilePath = _filesystem->homeWritePath("log.txt");
Log::init(logfilePath.c_str());

return AppState::Init;
Expand Down Expand Up @@ -947,7 +947,7 @@ void App::usage() const {
Log::info("------------");
Log::info("Search paths:");
const io::Paths &paths = _filesystem->registeredPaths();
for (const core::String &path : paths) {
for (const core::Path &path : paths) {
Log::info(" * %s", path.c_str());
}
Log::info("------------");
Expand Down
4 changes: 2 additions & 2 deletions src/modules/app/i18n/DictionaryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Dictionary &DictionaryManager::getDictionary(const Language &language) {
}

if (!bestFilename.empty()) {
const core::String &pofile = core::string::path(*p, bestFilename);
const core::Path &pofile = p->append(bestFilename);
const io::FilePtr &in = _filesystem->open(pofile);
if (!in) {
Log::error("failure opening: %s", pofile.c_str());
Expand Down Expand Up @@ -173,7 +173,7 @@ bool DictionaryManager::getUseFuzzy() const {
return _useFuzzy;
}

void DictionaryManager::addDirectory(const core::String &pathname, bool precedence /* = false */) {
void DictionaryManager::addDirectory(const core::Path &pathname, bool precedence /* = false */) {
if (core::find(_searchPath.begin(), _searchPath.end(), pathname) == _searchPath.end()) {
clearCache(); // adding directories invalidates cache
if (precedence) {
Expand Down
5 changes: 3 additions & 2 deletions src/modules/app/i18n/DictionaryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "Dictionary.h"
#include "Language.h"
#include "core/Path.h"
#include "io/Filesystem.h"

namespace app {
Expand All @@ -39,7 +40,7 @@ class DictionaryManager : public core::NonCopyable {
typedef core::Map<Language, Dictionary *, 11, Language_hash> Dictionaries;
Dictionaries _dictionaries;

typedef core::DynamicArray<core::String> SearchPath;
typedef core::DynamicArray<core::Path> SearchPath;
SearchPath _searchPath;

core::String _charset;
Expand Down Expand Up @@ -87,7 +88,7 @@ class DictionaryManager : public core::NonCopyable {
* added directories have higher priority then later added ones.
* Set @p precedence to true to invert this for a single addition.
*/
void addDirectory(const core::String &pathname, bool precedence = false);
void addDirectory(const core::Path &pathname, bool precedence = false);

/** Remove a directory from the search path */
void removeDirectory(const core::String &pathname);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/app/i18n/POParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ namespace app {

bool POParser::pedantic = true;

bool POParser::parse(const core::String &filename, io::SeekableReadStream &in, Dictionary &dict) {
bool POParser::parse(const core::Path &filename, io::SeekableReadStream &in, Dictionary &dict) {
POParser parser(filename, in, dict);
return parser.parse();
}

POParser::POParser(const core::String &filename, io::SeekableReadStream &in, Dictionary &dict, bool useFuzzy)
POParser::POParser(const core::Path &filename, io::SeekableReadStream &in, Dictionary &dict, bool useFuzzy)
: _filename(filename), _in(in), _dict(dict), _useFuzzy(useFuzzy) {
}

Expand Down
7 changes: 4 additions & 3 deletions src/modules/app/i18n/POParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "Iconv.h"
#include "core/NonCopyable.h"
#include "core/Path.h"
#include "io/Stream.h"

namespace app {
Expand All @@ -33,7 +34,7 @@ class Dictionary;

class POParser : public core::NonCopyable {
private:
core::String _filename;
core::Path _filename;
io::SeekableReadStream &_in;
Dictionary &_dict;
bool _useFuzzy;
Expand All @@ -47,7 +48,7 @@ class POParser : public core::NonCopyable {

IConv _conv;

POParser(const core::String &filename, io::SeekableReadStream &in, Dictionary &dict, bool useFuzzy = true);
POParser(const core::Path &filename, io::SeekableReadStream &in, Dictionary &dict, bool useFuzzy = true);
~POParser();

bool parseHeader(const core::String &header);
Expand All @@ -66,7 +67,7 @@ class POParser : public core::NonCopyable {
* @param in stream from which the PO file is read.
* @param dict dictionary to which the strings are written
*/
static bool parse(const core::String &filename, io::SeekableReadStream &in, Dictionary &dict);
static bool parse(const core::Path &filename, io::SeekableReadStream &in, Dictionary &dict);
static bool pedantic;
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/tests/CommandCompleterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CommandCompleterTest: public app::AbstractTest {
public:
bool onInitApp() override{
const io::FilesystemPtr& fs = io::filesystem();
fs->sysCreateDir("commandcompletertest/dir1");
fs->sysCreateDir(core::Path("commandcompletertest/dir1"));
fs->sysWrite("commandcompletertest/dir1/ignored", "ignore");
fs->sysWrite("commandcompletertest/dir1/ignoredtoo", "ignore");
fs->sysWrite("commandcompletertest/dir1/foo1.foo", "foo1");
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/tests/POParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ msgstr "Translation for Single line string"
};

TEST_F(POParserTest, testParse) {
const core::String filename = "mem";
const core::Path filename("mem");
io::MemoryReadStream stream(poString, strlen(poString));
Dictionary dict;
ASSERT_TRUE(POParser::parse(filename, stream, dict));
Expand Down
1 change: 0 additions & 1 deletion src/modules/core/StringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ char *strncpyz(const char *input, size_t inputSize, char *target, size_t targetS

/**
* @brief Ensure that exactly one / is at the end of the given path
* @sa io::normalizePath()
*/
core::String sanitizeDirPath(core::String str);

Expand Down
2 changes: 1 addition & 1 deletion src/modules/io/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool Archive::exists(const core::String &file) const {

void Archive::list(const core::String &basePath, ArchiveFiles &out, const core::String &filter) const {
for (const auto &entry : _files) {
if (!basePath.empty() && !core::string::startsWith(entry.fullPath, basePath)) {
if (!basePath.empty() && !core::string::startsWith(entry.fullPath.str(), basePath)) {
continue;
}
if (core::string::fileMatchesMultiple(entry.name.c_str(), filter.c_str())) {
Expand Down
36 changes: 13 additions & 23 deletions src/modules/io/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,14 @@

namespace io {

void normalizePath(core::String& str) {
core::string::replaceAllChars(str, '\\', '/');
#ifndef __WINDOWS__
if (str.size() >= 3 && str[0] != '\0' && core::string::isAlpha(str[0]) && str[1] == ':' && (str[2] == '\\' || str[2] == '/')) {
str.erase(0, 2);
}
#endif
File::File(const core::Path &rawPath, FileMode mode) : IOResource(), _rawPath(rawPath), _mode(mode) {
_file = createRWops(mode);
}

File::File(const core::String& rawPath, FileMode mode) :
IOResource(), _rawPath(rawPath), _mode(mode) {
normalizePath(_rawPath);
_file = createRWops(mode);
File::File(const core::String &rawPath, FileMode mode) : File(core::String(rawPath), mode) {
}

File::File(core::String&& rawPath, FileMode mode) :
IOResource(), _rawPath(core::move(rawPath)), _mode(mode) {
normalizePath(_rawPath);
File::File(core::String &&rawPath, FileMode mode) : IOResource(), _rawPath(core::move(rawPath)), _mode(mode) {
_file = createRWops(mode);
}

Expand Down Expand Up @@ -69,6 +59,10 @@ bool File::exists() const {
}

const core::String& File::name() const {
return _rawPath.str();
}

const core::Path& File::path() const {
return _rawPath;
}

Expand Down Expand Up @@ -173,21 +167,17 @@ long File::write(const unsigned char *buf, size_t len) const {
return (long)len;
}

core::String File::dir() const {
return core::string::extractDir(name());
core::Path File::dir() const {
return _rawPath.dirname();
}

core::String File::fileName() const {
return core::string::extractFilename(name());
const core::Path &bn = _rawPath.basename();
return core::string::stripExtension(bn.str());
}

core::String File::extension() const {
const char *ext = SDL_strrchr(name().c_str(), '.');
if (ext == nullptr) {
return "";
}
++ext;
return core::String(ext);
return _rawPath.extension();
}

long File::length() const {
Expand Down
12 changes: 5 additions & 7 deletions src/modules/io/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include "core/Path.h"
#include "core/String.h"
#include "core/SharedPtr.h"
#include "IOResource.h"
Expand All @@ -25,11 +26,6 @@ enum class FileMode {
ReadNoHome /**< reading from the virtual file system but skip user setting files in the home directories */
};

/**
* @sa core::string::sanitizeDirPath()
*/
extern void normalizePath(core::String& str);

/**
* @brief Wrapper for file based io.
*
Expand All @@ -41,13 +37,14 @@ class File : public IOResource {
friend class core::SharedPtr<io::File>;
protected:
SDL_RWops* _file;
core::String _rawPath;
core::Path _rawPath;
FileMode _mode;
mutable core::String _error;

void error(CORE_FORMAT_STRING const char *msg, ...) const CORE_PRINTF_VARARG_FUNC(2);

public:
File(const core::Path& rawPath, FileMode mode = FileMode::Read);
File(const core::String& rawPath, FileMode mode = FileMode::Read);
File(core::String&& rawPath, FileMode mode = FileMode::Read);
virtual ~File();
Expand Down Expand Up @@ -87,7 +84,7 @@ class File : public IOResource {
* @return The path of the file, without the name - or an
* empty string if no path component was found
*/
core::String dir() const;
core::Path dir() const;
/**
* @return Just the base file name component part - without
* path and extension
Expand All @@ -97,6 +94,7 @@ class File : public IOResource {
* @return The full raw path of the file
*/
const core::String& name() const;
const core::Path& path() const;

SDL_RWops* createRWops(FileMode mode) const;
long write(io::ReadStream &stream) const;
Expand Down
Loading