mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Print human-readable autodetected media type.
This commit is contained in:
parent
6c30621400
commit
10b9be1f85
4 changed files with 51 additions and 2 deletions
|
@ -18,6 +18,8 @@
|
|||
#ifndef id700AFD0F33634ACC88079BB8853A9E13
|
||||
#define id700AFD0F33634ACC88079BB8853A9E13
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace dinlib {
|
||||
enum MediaTypes {
|
||||
MediaType_CDRom = 'C',
|
||||
|
@ -29,6 +31,8 @@ namespace dinlib {
|
|||
MediaType_IomegaZip = 'Z',
|
||||
MediaType_Other = 'O'
|
||||
};
|
||||
|
||||
const std::string& media_type_to_str ( MediaTypes parType );
|
||||
} //namespace dinlib
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@ project(${bare_name}-common CXX C)
|
|||
|
||||
add_library(${PROJECT_NAME}
|
||||
commandline.cpp
|
||||
mediatypes.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
|
|
42
src/common/mediatypes.cpp
Normal file
42
src/common/mediatypes.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* Copyright 2015, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dindexer-common/mediatypes.hpp"
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace dinlib {
|
||||
const std::string& media_type_to_str (MediaTypes parType) {
|
||||
static const std::map<MediaTypes, const std::string> types {
|
||||
{MediaType_CDRom, "CD-Rom"},
|
||||
{MediaType_Directory, "Directory"},
|
||||
{MediaType_DVD, "DVD"},
|
||||
{MediaType_BluRay, "BluRay"},
|
||||
{MediaType_FloppyDisk, "Floppy Disk"},
|
||||
{MediaType_HardDisk, "Hard Disk"},
|
||||
{MediaType_IomegaZip, "Iomega Zip"},
|
||||
{MediaType_Other, "Other"}
|
||||
};
|
||||
|
||||
auto it_ret = types.find(parType);
|
||||
if (types.end() == it_ret) {
|
||||
const char err[2] = {static_cast<char>(parType), '\0'};
|
||||
throw std::out_of_range(err);
|
||||
}
|
||||
return it_ret->second;
|
||||
}
|
||||
} //namespace dinlib
|
|
@ -78,8 +78,10 @@ int main (int parArgc, char* parArgv[]) {
|
|||
if (0 == vm.count("type")) {
|
||||
std::cout << "Analyzing disc... ";
|
||||
try {
|
||||
set_type = din::guess_media_type(std::string(search_path));
|
||||
std::cout << "Setting type to " << set_type << '\n';
|
||||
const auto guessed_type = din::guess_media_type(std::string(search_path));
|
||||
set_type = guessed_type;
|
||||
std::cout << "Setting type to " << set_type << " ("
|
||||
<< dinlib::media_type_to_str(guessed_type) << ")\n";
|
||||
}
|
||||
catch (const std::runtime_error& e) {
|
||||
std::cout << '\n';
|
||||
|
|
Loading…
Reference in a new issue