Mercurial > minori
diff src/core/filesystem.cpp @ 61:327568ad9be9
core/fs: finish class-ification of paths
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 29 Sep 2023 15:52:31 -0400 |
parents | d417e9381ca5 |
children | 4c6dd5999b39 |
line wrap: on
line diff
--- a/src/core/filesystem.cpp Fri Sep 29 13:52:50 2023 -0400 +++ b/src/core/filesystem.cpp Fri Sep 29 15:52:31 2023 -0400 @@ -22,24 +22,9 @@ namespace Filesystem { -/* FIXME: This is a very C-like way of doing this. - Make a path class. */ -class Path { - public: - Path(); - Path(std::string path); - Path(const Path& path); - bool CreateDirectories() const; - bool Exists() const; - std::string Basename(); - std::string Stem(); - std::string Extension(); - Path GetParent(); - void SetPath(); - - private: - std::string _path; -} +Path::Path() { _path = ""; } +Path::Path(const std::string& path) { _path = path; } +Path::Path(const Path& path) { _path = path.GetPath(); } bool Path::CreateDirectories() const { std::string temp = ""; @@ -74,7 +59,7 @@ } std::string Path::Basename() const { - return _path.substr(0, path.find_last_of(DELIM)); + return _path.substr(0, _path.find_last_of(DELIM)); } std::string Path::Stem() const { @@ -83,15 +68,23 @@ } std::string Path::Extension() const { - std::string basename = Basename(_path); - return basename.substr(basename.find_last_of("."), basename.end()); + std::string basename = Basename(); + return basename.substr(basename.find_last_of("."), basename.length()); } -std::string Path::GetParent() const { +Path Path::GetParent() const { return _path.substr(0, _path.find_last_of(DELIM)); } -std::string GetDotPath(void) { +void Path::SetPath(const std::string& path) { + _path = path; +} + +std::string Path::GetPath() const { + return _path; +} + +Path GetDotPath(void) { std::string ret = ""; #ifdef WIN32 char buf[PATH_MAX + 1]; @@ -114,17 +107,17 @@ return ret; } -std::string GetConfigPath(void) { +Path GetConfigPath(void) { std::string ret = ""; - ret += GetDotPath(); + ret += GetDotPath().GetPath(); if (!ret.empty()) ret += DELIM CONFIG_NAME; return ret; } -std::string GetAnimeDBPath(void) { +Path GetAnimeDBPath(void) { std::string ret = ""; - ret += GetDotPath(); + ret += GetDotPath().GetPath(); if (!ret.empty()) ret += DELIM "anime" DELIM "db.json"; return ret;