Statistics
| Branch: | Tag: | Revision:

root / host / lib / utils / images.cpp @ e7df6384

History | View | Annotate | Download (1.95 KB)

1
//
2
// Copyright 2010-2012 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
#include <uhd/utils/images.hpp>
19
#include <uhd/exception.hpp>
20
#include <uhd/utils/paths.hpp>
21
#include <boost/foreach.hpp>
22
#include <boost/filesystem.hpp>
23
#include <vector>
24
#include <iostream>
25

    
26
namespace fs = boost::filesystem;
27

    
28
std::vector<fs::path> get_image_paths(void); //defined in paths.cpp
29

    
30
/***********************************************************************
31
 * Find an image in the image paths
32
 **********************************************************************/
33
std::string uhd::find_image_path(const std::string &image_name){
34
    if (fs::exists(image_name)){
35
        return fs::system_complete(image_name).string();
36
    }
37
    BOOST_FOREACH(const fs::path &path, get_image_paths()){
38
        fs::path image_path = path / image_name;
39
        if (fs::exists(image_path)) return image_path.string();
40
    }
41
    throw uhd::io_error("Could not find path for image: " + image_name);
42
}
43

    
44
std::string uhd::find_images_downloader(void){
45
    return fs::path((fs::path(get_pkg_data_path()) / "utils" / "uhd_images_downloader.py")).string();
46
}
47

    
48
std::string uhd::print_images_error(void){
49
    #ifdef UHD_PLATFORM_WIN32
50
    return "As an Administrator, please run:\n\n\"" + find_images_downloader() + "\"";
51
    #else
52
    return "Please run:\n\nsudo \"" + find_images_downloader() + "\"";
53
    #endif
54
}