1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-15 16:14:12 +00:00

Allow disabling media autodetection at build time.

Use DINDEXER_WITH_MEDIA_AUTODETECT.
This commit is contained in:
King_DuckZ 2015-12-08 16:07:21 +00:00
parent 97de157724
commit 2cdf0cb3b9
9 changed files with 53 additions and 9 deletions

View file

@ -4,6 +4,7 @@ project("${bare_name}-if" VERSION 0.1.2 LANGUAGES CXX C)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF) option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF)
option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON)
set(ACTIONS_PATH "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Actions search path") set(ACTIONS_PATH "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Actions search path")
set(PROJECT_VERSION_BETA "1") set(PROJECT_VERSION_BETA "1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra")

View file

@ -38,7 +38,7 @@ The following libraries must be available on your system:
- PostgreSQL (libpq) - PostgreSQL (libpq)
- Boost 1.53 or later - Boost 1.53 or later
- yaml-cpp 0.5.1 or later - yaml-cpp 0.5.1 or later
- libblkid (from util-linux/misc-utils) - libblkid (from util-linux/misc-utils) ***optional, build with -DDINDEXER_WITH_MEDIA_AUTODETECT=Off if you don't have this***
### Linux ### ### Linux ###

View file

@ -1,6 +1,12 @@
project(${bare_name}-scan CXX C) project(${bare_name}-scan CXX C)
find_package(blkid REQUIRED) if (DINDEXER_WITH_MEDIA_AUTODETECT)
find_package(blkid)
if (NOT BLKID_FOUND)
message(STATUS "libblkid not found, media autodetection will be disabled")
set(DINDEXER_WITH_MEDIA_AUTODETECT OFF)
endif()
endif()
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}
main.cpp main.cpp
@ -19,11 +25,19 @@ add_executable(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..
) )
target_include_directories(${PROJECT_NAME} SYSTEM
PRIVATE ${BLKID_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE ${bare_name}-if PRIVATE ${bare_name}-if
)
if (DINDEXER_WITH_MEDIA_AUTODETECT)
target_include_directories(${PROJECT_NAME} SYSTEM
PRIVATE ${BLKID_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${BLKID_LIBRARIES} PRIVATE ${BLKID_LIBRARIES}
) )
target_compile_definitions(${PROJECT_NAME}
PRIVATE WITH_MEDIA_AUTODETECT
)
endif()

View file

@ -60,7 +60,9 @@ namespace din {
oss << ", " << g_allowed_types[z]; oss << ", " << g_allowed_types[z];
} }
oss << '.'; oss << '.';
#if defined(WITH_MEDIA_AUTODETECT)
oss << " Default is 'autodetect'."; oss << " Default is 'autodetect'.";
#endif
type_param_help = oss.str(); type_param_help = oss.str();
} }
@ -76,7 +78,11 @@ namespace din {
po::options_description set_options("Set options"); po::options_description set_options("Set options");
set_options.add_options() set_options.add_options()
("setname,n", po::value<std::string>()->default_value("New set"), "Name to be given to the new set being scanned.") ("setname,n", po::value<std::string>()->default_value("New set"), "Name to be given to the new set being scanned.")
#if defined(WITH_MEDIA_AUTODETECT)
("type,t", po::value<char>(), type_param_help.c_str()) ("type,t", po::value<char>(), type_param_help.c_str())
#else
("type,t", po::value<char>()->default_value('V'), type_param_help.c_str())
#endif
; ;
po::options_description positional_options("Positional options"); po::options_description positional_options("Positional options");
positional_options.add_options() positional_options.add_options()
@ -121,9 +127,15 @@ namespace din {
if (parVarMap.count("search-path") == 0) { if (parVarMap.count("search-path") == 0) {
throw std::invalid_argument("No search path specified"); throw std::invalid_argument("No search path specified");
} }
if (parVarMap.count("type") and g_allowed_types + lengthof(g_allowed_types) == std::find(g_allowed_types, g_allowed_types + lengthof(g_allowed_types), parVarMap["type"].as<char>())) { #if defined(WITH_MEDIA_AUTODETECT)
if (parVarMap.count("type")) {
#endif
if (g_allowed_types + lengthof(g_allowed_types) == std::find(g_allowed_types, g_allowed_types + lengthof(g_allowed_types), parVarMap["type"].as<char>())) {
throw std::invalid_argument("Invalid value for parameter \"type\""); throw std::invalid_argument("Invalid value for parameter \"type\"");
} }
#if defined(WITH_MEDIA_AUTODETECT)
}
#endif
return false; return false;
} }
} //namespace din } //namespace din

View file

@ -38,6 +38,7 @@ namespace din {
namespace { namespace {
using MountpointsMap = std::map<std::string, std::string>; using MountpointsMap = std::map<std::string, std::string>;
#if defined(WITH_MEDIA_AUTODETECT)
//See: http://lkml.iu.edu/hypermail/linux/kernel/0602.1/1295.html //See: http://lkml.iu.edu/hypermail/linux/kernel/0602.1/1295.html
enum LinuxDeviceTypes { enum LinuxDeviceTypes {
LinuxDeviceType_Disk = 0x00, LinuxDeviceType_Disk = 0x00,
@ -114,7 +115,7 @@ namespace din {
DiscType_NoStandardProfile = 0xFFFF, //"No standard Profile" DiscType_NoStandardProfile = 0xFFFF, //"No standard Profile"
}; };
#endif
MountpointsMap list_mountpoints() { MountpointsMap list_mountpoints() {
std::ifstream rd("/proc/mounts"); std::ifstream rd("/proc/mounts");
@ -136,6 +137,7 @@ namespace din {
return std::move(retmap); return std::move(retmap);
} }
#if defined(WITH_MEDIA_AUTODETECT)
LinuxDeviceTypes get_dev_type (const std::string& parDev) { LinuxDeviceTypes get_dev_type (const std::string& parDev) {
const char dev_prefix[] = "/dev/"; const char dev_prefix[] = "/dev/";
const std::size_t dev_prefix_len = lengthof(dev_prefix) - 1; const std::size_t dev_prefix_len = lengthof(dev_prefix) - 1;
@ -162,6 +164,7 @@ namespace din {
} }
return static_cast<LinuxDeviceTypes>(retval); return static_cast<LinuxDeviceTypes>(retval);
} }
#endif
} //unnamed namespace } //unnamed namespace
DiscInfo::DiscInfo (std::string&& parPath) : DiscInfo::DiscInfo (std::string&& parPath) :
@ -188,6 +191,7 @@ namespace din {
return not m_device.empty(); return not m_device.empty();
} }
#if defined(WITH_MEDIA_AUTODETECT)
DriveTypes DiscInfo::drive_type() const { DriveTypes DiscInfo::drive_type() const {
auto dev_type = get_dev_type(m_device); auto dev_type = get_dev_type(m_device);
switch (dev_type) { switch (dev_type) {
@ -322,4 +326,5 @@ namespace din {
return OpticalType_Unknown; return OpticalType_Unknown;
}; };
} }
#endif
} //namespace din } //namespace din

View file

@ -21,6 +21,7 @@
#include <string> #include <string>
namespace din { namespace din {
#if defined(WITH_MEDIA_AUTODETECT)
enum OpticalTypes { enum OpticalTypes {
OpticalType_DVD, OpticalType_DVD,
OpticalType_CDRom, OpticalType_CDRom,
@ -36,6 +37,7 @@ namespace din {
DriveType_Other, DriveType_Other,
DriveType_Unknown DriveType_Unknown
}; };
#endif
class DiscInfo { class DiscInfo {
public: public:
@ -45,9 +47,11 @@ namespace din {
const std::string& mountpoint ( void ) const { return m_mountpoint; } const std::string& mountpoint ( void ) const { return m_mountpoint; }
const std::string& device ( void ) const { return m_device; } const std::string& device ( void ) const { return m_device; }
const std::string& original_path ( void ) const { return m_initial_path; } const std::string& original_path ( void ) const { return m_initial_path; }
OpticalTypes optical_type ( void ) const;
bool mountpoint_found ( void ) const; bool mountpoint_found ( void ) const;
#if defined(WITH_MEDIA_AUTODETECT)
OpticalTypes optical_type ( void ) const;
DriveTypes drive_type ( void ) const; DriveTypes drive_type ( void ) const;
#endif
private: private:
const std::string m_initial_path; const std::string m_initial_path;

View file

@ -73,6 +73,7 @@ int main (int parArgc, char* parArgv[]) {
} }
} }
#if defined(WITH_MEDIA_AUTODETECT)
char set_type; char set_type;
if (0 == vm.count("type")) { if (0 == vm.count("type")) {
std::cout << "Analyzing disc... "; std::cout << "Analyzing disc... ";
@ -89,6 +90,9 @@ int main (int parArgc, char* parArgv[]) {
else { else {
set_type = vm["type"].as<char>(); set_type = vm["type"].as<char>();
} }
#else
const char set_type = vm["type"].as<char>();
#endif
std::cout << "constructing...\n"; std::cout << "constructing...\n";

View file

@ -21,6 +21,7 @@
#include <utility> #include <utility>
namespace din { namespace din {
#if defined(WITH_MEDIA_AUTODETECT)
UnknownMediaTypeException::UnknownMediaTypeException (const std::string& parWhat) : UnknownMediaTypeException::UnknownMediaTypeException (const std::string& parWhat) :
std::runtime_error(parWhat) std::runtime_error(parWhat)
{ {
@ -64,4 +65,5 @@ namespace din {
throw CantAutodetectException("Can't autodetect set type, please specify it manually"); throw CantAutodetectException("Can't autodetect set type, please specify it manually");
} }
} }
#endif
} //namespace din } //namespace din

View file

@ -33,6 +33,7 @@ namespace din {
MediaType_Other = 'O' MediaType_Other = 'O'
}; };
#if defined(WITH_MEDIA_AUTODETECT)
MediaTypes guess_media_type ( std::string&& parPath ); MediaTypes guess_media_type ( std::string&& parPath );
class UnknownMediaTypeException : std::runtime_error { class UnknownMediaTypeException : std::runtime_error {
@ -46,6 +47,7 @@ namespace din {
CantAutodetectException ( const std::string& parWhat ); CantAutodetectException ( const std::string& parWhat );
CantAutodetectException ( const char* parWhat ); CantAutodetectException ( const char* parWhat );
}; };
#endif
} //namespace din } //namespace din
#endif #endif