commit afee3cd7e638f6701d21965d8089756ba13274a4
parent 003c3eed89c281d39acb8df9aeee1f101ac5029e
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 16 Apr 2016 11:53:37 -0400
support data packages
Diffstat:
4 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -591,7 +591,7 @@ bool Browser::match(const Entry &entry) const
const auto typeIt = m_types.find(type);
- if(typeIt == m_types.end() ||
+ if(typeIt != m_types.end() &&
SendMessage(typeIt->second, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
return false;
diff --git a/src/package.cpp b/src/package.cpp
@@ -33,6 +33,8 @@ Package::Type Package::typeFor(const char *type)
return ExtensionType;
else if(!strcmp(type, "effect"))
return EffectType;
+ else if(!strcmp(type, "data"))
+ return DataType;
else
return UnknownType;
}
@@ -48,6 +50,8 @@ string Package::displayType(const Type type)
return "Extension";
case EffectType:
return "Effect";
+ case DataType:
+ return "Data";
}
return {}; // MSVC is stupid
@@ -123,22 +127,19 @@ Path Package::makeTargetPath(const string &file) const
if(!m_category || !m_category->index())
throw reapack_error("category or index is unset");
+ // select the target directory
switch(m_type) {
case ScriptType:
path.append("Scripts");
- path.append(m_category->index()->name());
-
- // only allow directory traversal up to the index name
- path += Path(m_category->name()) + file;
break;
case EffectType:
path.append("Effects");
- path.append(m_category->index()->name());
- path += Path(m_category->name()) + file;
+ break;
+ case DataType:
+ path.append("Data");
break;
case ExtensionType:
path.append("UserPlugins");
- path.append(file, false);
break;
case UnknownType:
// The package has an unsupported type, so we return an empty path.
@@ -149,5 +150,22 @@ Path Package::makeTargetPath(const string &file) const
break;
}
+ // append the rest of the path
+ switch(m_type) {
+ case ScriptType:
+ case EffectType:
+ case DataType:
+ path.append(m_category->index()->name());
+
+ // only allow directory traversal up to the index name
+ path += Path(m_category->name()) + file;
+ break;
+ case ExtensionType:
+ path.append(file, false);
+ break;
+ case UnknownType:
+ break;
+ }
+
return path;
}
diff --git a/src/package.hpp b/src/package.hpp
@@ -33,6 +33,7 @@ public:
ScriptType,
ExtensionType,
EffectType,
+ DataType,
};
static Type typeFor(const char *);
diff --git a/test/package.cpp b/test/package.cpp
@@ -24,6 +24,9 @@ TEST_CASE("package type from string", M) {
SECTION("effect")
REQUIRE(Package::typeFor("effect") == Package::EffectType);
+
+ SECTION("data")
+ REQUIRE(Package::typeFor("data") == Package::DataType);
}
TEST_CASE("package type to string", M) {
@@ -46,6 +49,11 @@ TEST_CASE("package type to string", M) {
REQUIRE("Effect" == Package::displayType(Package::EffectType));
REQUIRE("Effect" == Package(Package::EffectType, "test").displayType());
}
+
+ SECTION("data") {
+ REQUIRE("Data" == Package::displayType(Package::DataType));
+ REQUIRE("Data" == Package(Package::DataType, "test").displayType());
+ }
}
TEST_CASE("empty package name", M) {
@@ -209,6 +217,24 @@ TEST_CASE("effect target path", M) {
REQUIRE(pack.makeTargetPath("../../../hello_world.jsfx") == expected);
}
+TEST_CASE("data target path", M) {
+ Index ri("Remote Name");
+ Category cat("Category Name", &ri);
+
+ Package pack(Package::DataType, "file.name", &cat);
+
+ Path expected;
+ expected.append("Data");
+ expected.append("Remote Name");
+ expected.append("Category Name");
+
+ REQUIRE(pack.makeTargetPath() == expected);
+
+ expected.removeLast();
+ expected.append("hello_world.jsfx");
+ REQUIRE(pack.makeTargetPath("../../../hello_world.jsfx") == expected);
+}
+
TEST_CASE("full name", M) {
SECTION("no category") {
Package pack(Package::ScriptType, "file.name");