commit 8303c656bf0fd9641683539306850646535bd168
parent c264a7c4ad951aa9657d60f4500be8e52a5984a7
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 25 Jan 2016 18:52:51 -0500
refactor 53f57fcb41509539f51fe7e5de16b68198e80bfd
Diffstat:
5 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/src/path.hpp b/src/path.hpp
@@ -25,11 +25,10 @@ class UseRootPath;
class Path {
public:
- static Path prefix(const Path &p) { return s_root + p; }
- static Path configFile() { return s_root + "reapack.ini"; }
static Path cacheDir() { return s_root + "ReaPack"; }
- static Path cache(const std::string &p) { return cacheDir() + p; }
- static Path registry() { return cacheDir() + "registry.db"; }
+ static Path prefixRoot(const Path &p) { return s_root + p; }
+ static Path prefixRoot(const std::string &p) { return s_root + p; }
+ static Path prefixCache(const std::string &p) { return cacheDir() + p; }
Path(const std::string &path = std::string());
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -37,7 +37,7 @@ ReaPack::ReaPack(REAPER_PLUGIN_HINSTANCE instance)
RecursiveCreateDirectory(Path::cacheDir().join().c_str(), 0);
m_config = new Config;
- m_config->read(Path::configFile());
+ m_config->read(Path::prefixRoot("reapack.ini"));
m_progress = Dialog::Create<Progress>(m_instance, m_mainWindow);
m_manager = Dialog::Create<Manager>(m_instance, m_mainWindow, this);
diff --git a/src/task.cpp b/src/task.cpp
@@ -61,8 +61,8 @@ void Task::rollback()
bool Task::RenameFile(const Path &from, const Path &to)
{
- const string &fullFrom = Path::prefix(from).join();
- const string &fullTo = Path::prefix(to).join();
+ const string &fullFrom = Path::prefixRoot(from).join();
+ const string &fullTo = Path::prefixRoot(to).join();
#ifdef _WIN32
return !_wrename(make_autostring(fullFrom).c_str(),
@@ -75,7 +75,7 @@ bool Task::RenameFile(const Path &from, const Path &to)
bool Task::RemoveFile(const Path &path)
{
const auto_string &fullPath =
- make_autostring(Path::prefix(path).join());
+ make_autostring(Path::prefixRoot(path).join());
#ifdef _WIN32
if(GetFileAttributes(fullPath.c_str()) & FILE_ATTRIBUTE_DIRECTORY)
@@ -144,7 +144,7 @@ void InstallTask::saveSource(Download *dl, Source *src)
if(old != m_oldFiles.end())
m_oldFiles.erase(old);
- if(!transaction()->saveFile(dl, Path::prefix(tmpPath))) {
+ if(!transaction()->saveFile(dl, Path::prefixRoot(tmpPath))) {
rollback();
return;
}
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -32,7 +32,7 @@ using namespace std;
Transaction::Transaction()
: m_isCancelled(false)
{
- m_registry = new Registry(Path::registry());
+ m_registry = new Registry(Path::prefixCache("registry.db"));
m_downloadQueue.onDone([=](void *) {
if(m_installQueue.empty())
@@ -67,7 +67,7 @@ void Transaction::synchronize(const Remote &remote)
void Transaction::upgradeAll(Download *dl)
{
- const Path path = Path::cache("remote_" + dl->name() + ".xml");
+ const Path path = Path::prefixCache("remote_" + dl->name() + ".xml");
if(!saveFile(dl, path))
return;
@@ -245,7 +245,7 @@ void Transaction::addError(const string &message, const string &title)
bool Transaction::allFilesExists(const set<Path> &list) const
{
for(const Path &path : list) {
- if(!file_exists(Path::prefix(path).join().c_str()))
+ if(!file_exists(Path::prefixRoot(path).join().c_str()))
return false;
}
diff --git a/test/path.cpp b/test/path.cpp
@@ -164,27 +164,23 @@ TEST_CASE("remove last component of path", M) {
REQUIRE(a[0] == "a");
}
-TEST_CASE("path collection", M) {
+TEST_CASE("path generation utilities", M) {
const Path path("world");
- REQUIRE(Path::prefix(path) == Path("world"));
+ REQUIRE(Path::prefixRoot(path) == Path("world"));
+ REQUIRE(Path::cacheDir() == Path("ReaPack"));
+ REQUIRE(Path::prefixCache("test") == Path("ReaPack/test"));
{
UseRootPath root("hello");
(void)root;
- REQUIRE(Path::prefix(path) == Path("hello/world"));
- }
-
- REQUIRE(Path::prefix(path) == Path("world"));
-}
+ REQUIRE(Path::prefixRoot(path) == Path("hello/world"));
+ REQUIRE(Path::prefixRoot("world") == Path("hello/world"));
-TEST_CASE("standard paths", M) {
- UseRootPath root("root");
- (void)root;
+ REQUIRE(Path::cacheDir() == Path("hello/ReaPack"));
+ REQUIRE(Path::prefixCache("test") == Path("hello/ReaPack/test"));
+ }
- REQUIRE(Path::configFile() == Path("root/reapack.ini"));
- REQUIRE(Path::cacheDir() == Path("root/ReaPack"));
- REQUIRE(Path::cache("test") == Path("root/ReaPack/test"));
- REQUIRE(Path::registry() == Path("root/ReaPack/registry.db"));
+ REQUIRE(Path::prefixRoot(path) == Path("world"));
}