From 96d97bbfb38b8b532582f1459ea4762ca7a87ffe Mon Sep 17 00:00:00 2001 From: Hiroshi Matoba Date: Thu, 30 May 2019 18:33:12 +0200 Subject: [PATCH] Support ADDON_DATA in addon_config.mk (#190) --- ofxProjectGenerator/src/addons/ofAddon.cpp | 2 +- .../src/projects/baseProject.cpp | 36 +++++++++++++++++++ .../src/projects/baseProject.h | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ofxProjectGenerator/src/addons/ofAddon.cpp b/ofxProjectGenerator/src/addons/ofAddon.cpp index 5d738d1ab..670440304 100644 --- a/ofxProjectGenerator/src/addons/ofAddon.cpp +++ b/ofxProjectGenerator/src/addons/ofAddon.cpp @@ -310,7 +310,7 @@ void ofAddon::parseVariableValue(string variable, string value, bool addToValue, } if(variable == "ADDON_DATA"){ - addReplaceStringVector(data,value,addonRelPath,addToValue); + addReplaceStringVector(data,value,"",addToValue); } if(variable == "ADDON_LIBS_EXCLUDE"){ diff --git a/ofxProjectGenerator/src/projects/baseProject.cpp b/ofxProjectGenerator/src/projects/baseProject.cpp index f4678ed42..5a170c955 100644 --- a/ofxProjectGenerator/src/projects/baseProject.cpp +++ b/ofxProjectGenerator/src/projects/baseProject.cpp @@ -254,7 +254,43 @@ void baseProject::addAddon(std::string addonName){ auto standardPath = ofFilePath::join(ofFilePath::join(getOFRoot(), "addons"), addonName); addon.fromFS(standardPath, target); } + addAddon(addon); + + // Process values from ADDON_DATA + if(addon.data.size()){ + + for(auto& d : addon.data){ + + filesystem::path path(ofFilePath::join(addon.addonPath, d)); + + if(filesystem::exists(path)){ + if (filesystem::is_regular_file(path)){ + ofFile src(path); + string dest = ofFilePath::join(projectDir, "bin/data/"); + ofStringReplace(d, "data/", ""); // avoid to copy files at /data/data/* + bool success = src.copyTo(ofFilePath::join(dest, d), false, true); + if(success){ + ofLogVerbose() << "adding addon data file: " << d; + }else { + ofLogWarning() << "Can not add addon data file: " << d; + } + }else if(filesystem::is_directory(path)){ + ofDirectory dir(path); + string dest = ofFilePath::join(projectDir, "bin/data/"); + ofStringReplace(d, "data/", ""); // avoid to copy files at /data/data/* + bool success = dir.copyTo(ofFilePath::join(dest, d), false, true); + if(success){ + ofLogVerbose() << "adding addon data folder: " << d; + }else{ + ofLogWarning() << "Can not add addon data folder: " << d; + } + } + }else{ + ofLogWarning() << "addon data file does not exist, skipping: " << d; + } + } + } } void baseProject::addAddon(ofAddon & addon){ diff --git a/ofxProjectGenerator/src/projects/baseProject.h b/ofxProjectGenerator/src/projects/baseProject.h index 535af6dd5..c4048b102 100644 --- a/ofxProjectGenerator/src/projects/baseProject.h +++ b/ofxProjectGenerator/src/projects/baseProject.h @@ -66,7 +66,7 @@ class baseProject { virtual void addDefine(std::string define, LibType libType = RELEASE_LIB) {} virtual void addAddon(std::string addon); - virtual void addAddon(ofAddon & addon); + virtual void addAddon(ofAddon & addon); std::string getName() { return projectName;} std::string getPath() { return projectDir; }