Skip to content

Commit f414ac4

Browse files
committed
fix build for case when DEPTHAI_ENABLE_CURL=OFF
1 parent ae3f03a commit f414ac4

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/modelzoo/Zoo.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ static std::string MODEL_ZOO_DOWNLOAD_ENDPOINT = "https://easyml.cloud.luxonis.c
2323
static std::string MODEL_ZOO_DEFAULT_CACHE_PATH = ".depthai_cached_models"; // hidden cache folder
2424
static std::string MODEL_ZOO_DEFAULT_MODELS_PATH = "depthai_models"; // folder
2525

26-
#ifdef DEPTHAI_ENABLE_CURL
2726
class ZooManager {
2827
public:
2928
/**
@@ -166,6 +165,46 @@ class ZooManager {
166165
std::string cacheDirectory;
167166
};
168167

168+
std::string combinePaths(const std::string& path1, const std::string& path2) {
169+
return std::filesystem::path(path1).append(path2).string();
170+
}
171+
172+
std::string ZooManager::getYamlFilePath(const std::string& name, const std::string& modelsPath) {
173+
// No empty names allowed
174+
if(name.empty()) {
175+
throw std::runtime_error("name cannot be empty!");
176+
}
177+
178+
// If the name does not start with any dot or slash, we treat it as the special
179+
// case of where we prepend the DEPTHAI_ZOO_MODELS_PATH environment variable first.
180+
// We check whether the first character is a letter or a number here (model.yaml, model, 3model, ...)
181+
if(isalnum(name[0])) {
182+
std::string useModelsPath = modelsPath;
183+
if(useModelsPath.empty()) {
184+
useModelsPath = utility::getEnvAs<std::string>("DEPTHAI_ZOO_MODELS_PATH", dai::modelzoo::getDefaultModelsPath(), false);
185+
}
186+
std::string path = combinePaths(useModelsPath, name);
187+
188+
// if path does not contain the yaml or yml extension, add it
189+
if(!utility::isYamlFile(path)) {
190+
if(std::filesystem::exists(path + ".yaml")) {
191+
path += ".yaml";
192+
} else if(std::filesystem::exists(path + ".yml")) {
193+
path += ".yml";
194+
} else {
195+
throw std::runtime_error("Model file not found: (neither `" + path + ".yaml` nor `" + path
196+
+ ".yml` exists) | If you meant to use a relative path, prefix with ./ (e.g. `./" + name
197+
+ "`) | Also, make sure the file exists. Read the documentation for more information.");
198+
}
199+
}
200+
return path;
201+
}
202+
203+
// We treat the name either as a relative path or an absolute path
204+
return name;
205+
}
206+
207+
#ifdef DEPTHAI_ENABLE_CURL
169208
std::string generateErrorMessageHub(const cpr::Response& response) {
170209
std::string errorMessage;
171210
errorMessage += "There was an error while sending a request to the Hub\n";
@@ -189,10 +228,6 @@ std::string generateErrorMessageModelDownload(const cpr::Response& response) {
189228
return errorMessage;
190229
}
191230

192-
std::string combinePaths(const std::string& path1, const std::string& path2) {
193-
return std::filesystem::path(path1).append(path2).string();
194-
}
195-
196231
bool checkIsErrorHub(const cpr::Response& response) {
197232
// Check if response is an HTTP error
198233
if(response.status_code != cpr::status::HTTP_OK) return true;
@@ -535,41 +570,6 @@ bool ZooManager::connectionToZooAvailable() {
535570
return connected;
536571
}
537572

538-
std::string ZooManager::getYamlFilePath(const std::string& name, const std::string& modelsPath) {
539-
// No empty names allowed
540-
if(name.empty()) {
541-
throw std::runtime_error("name cannot be empty!");
542-
}
543-
544-
// If the name does not start with any dot or slash, we treat it as the special
545-
// case of where we prepend the DEPTHAI_ZOO_MODELS_PATH environment variable first.
546-
// We check whether the first character is a letter or a number here (model.yaml, model, 3model, ...)
547-
if(isalnum(name[0])) {
548-
std::string useModelsPath = modelsPath;
549-
if(useModelsPath.empty()) {
550-
useModelsPath = utility::getEnvAs<std::string>("DEPTHAI_ZOO_MODELS_PATH", dai::modelzoo::getDefaultModelsPath(), false);
551-
}
552-
std::string path = combinePaths(useModelsPath, name);
553-
554-
// if path does not contain the yaml or yml extension, add it
555-
if(!utility::isYamlFile(path)) {
556-
if(std::filesystem::exists(path + ".yaml")) {
557-
path += ".yaml";
558-
} else if(std::filesystem::exists(path + ".yml")) {
559-
path += ".yml";
560-
} else {
561-
throw std::runtime_error("Model file not found: (neither `" + path + ".yaml` nor `" + path
562-
+ ".yml` exists) | If you meant to use a relative path, prefix with ./ (e.g. `./" + name
563-
+ "`) | Also, make sure the file exists. Read the documentation for more information.");
564-
}
565-
}
566-
return path;
567-
}
568-
569-
// We treat the name either as a relative path or an absolute path
570-
return name;
571-
}
572-
573573
std::string ZooManager::getMetadataFilePath() const {
574574
return combinePaths(getModelCacheFolderPath(cacheDirectory), "metadata.yaml");
575575
}
@@ -588,7 +588,7 @@ std::string getModelFromZoo(const NNModelDescription& modelDescription, bool use
588588
throw std::runtime_error("getModelFromZoo requires libcurl to be enabled. Please recompile DepthAI with libcurl enabled.");
589589
}
590590

591-
void downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory, const std::string& apiKey) {
591+
bool downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory, const std::string& apiKey) {
592592
(void)path;
593593
(void)cacheDirectory;
594594
(void)apiKey;

0 commit comments

Comments
 (0)