diff options
author | Ben Hilburn <ben.hilburn@ettus.com> | 2014-11-03 17:05:26 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-11-21 00:16:47 +0100 |
commit | beabf3d302a98a0a1e28ae8cc4d338f0bd13db6e (patch) | |
tree | e2b7ab145ec2daa83c4589e96b0f67bc5a3fd38d /host/lib/utils/paths.cpp | |
parent | 3407376f8af0fc39f29c1c8ce9020d02a2bf05d9 (diff) | |
download | uhd-beabf3d302a98a0a1e28ae8cc4d338f0bd13db6e.tar.gz uhd-beabf3d302a98a0a1e28ae8cc4d338f0bd13db6e.tar.bz2 uhd-beabf3d302a98a0a1e28ae8cc4d338f0bd13db6e.zip |
uhd: replaced the `images_error` with a generic utility error
- Deleted images.*, moved functionality to paths.*
- Applies for all devices that check FPGA or FW compat numbers
- Adds generic utility search tool
Diffstat (limited to 'host/lib/utils/paths.cpp')
-rw-r--r-- | host/lib/utils/paths.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 3e2bea1c6..282ebb566 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -17,15 +17,19 @@ #include <uhd/config.hpp> #include <uhd/utils/paths.hpp> -#include <boost/tokenizer.hpp> + +#include <boost/bind.hpp> +#include <uhd/exception.hpp> #include <boost/filesystem.hpp> #include <boost/foreach.hpp> -#include <boost/bind.hpp> +#include <boost/tokenizer.hpp> + +#include <cstdio> //P_tmpdir #include <cstdlib> +#include <iostream> #include <string> #include <vector> -#include <cstdlib> //getenv -#include <cstdio> //P_tmpdir + #ifdef BOOST_MSVC #define USE_GET_TEMP_PATH #include <windows.h> //GetTempPath @@ -136,3 +140,28 @@ std::string uhd::get_app_path(void){ return uhd::get_tmp_path(); } + +std::string uhd::find_image_path(const std::string &image_name){ + if (fs::exists(image_name)){ + return fs::system_complete(image_name).string(); + } + BOOST_FOREACH(const fs::path &path, get_image_paths()){ + fs::path image_path = path / image_name; + if (fs::exists(image_path)) return image_path.string(); + } + throw uhd::io_error("Could not find path for image: " + image_name + + "\n\n" + uhd::print_utility_error("uhd_images_downloader.py")); +} + +std::string uhd::find_utility(std::string name) { + return fs::path(fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / name) + .string(); +} + +std::string uhd::print_utility_error(std::string name){ + #ifdef UHD_PLATFORM_WIN32 + return "As an Administrator, please run:\n\n\"" + find_utility(name) + "\""; + #else + return "Please run:\n\n \"" + find_utility(name) + "\""; + #endif +} |