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:
parent
97de157724
commit
2cdf0cb3b9
9 changed files with 53 additions and 9 deletions
|
@ -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)
|
||||
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(PROJECT_VERSION_BETA "1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra")
|
||||
|
|
|
@ -38,7 +38,7 @@ The following libraries must be available on your system:
|
|||
- PostgreSQL (libpq)
|
||||
- Boost 1.53 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 ###
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
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}
|
||||
main.cpp
|
||||
|
@ -19,11 +25,19 @@ add_executable(${PROJECT_NAME}
|
|||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||
PRIVATE ${BLKID_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
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}
|
||||
)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE WITH_MEDIA_AUTODETECT
|
||||
)
|
||||
endif()
|
||||
|
|
|
@ -60,7 +60,9 @@ namespace din {
|
|||
oss << ", " << g_allowed_types[z];
|
||||
}
|
||||
oss << '.';
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
oss << " Default is 'autodetect'.";
|
||||
#endif
|
||||
type_param_help = oss.str();
|
||||
}
|
||||
|
||||
|
@ -76,7 +78,11 @@ namespace din {
|
|||
po::options_description set_options("Set 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.")
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
("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");
|
||||
positional_options.add_options()
|
||||
|
@ -121,9 +127,15 @@ namespace din {
|
|||
if (parVarMap.count("search-path") == 0) {
|
||||
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\"");
|
||||
}
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
} //namespace din
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace din {
|
|||
namespace {
|
||||
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
|
||||
enum LinuxDeviceTypes {
|
||||
LinuxDeviceType_Disk = 0x00,
|
||||
|
@ -114,7 +115,7 @@ namespace din {
|
|||
|
||||
DiscType_NoStandardProfile = 0xFFFF, //"No standard Profile"
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
MountpointsMap list_mountpoints() {
|
||||
std::ifstream rd("/proc/mounts");
|
||||
|
@ -136,6 +137,7 @@ namespace din {
|
|||
return std::move(retmap);
|
||||
}
|
||||
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
LinuxDeviceTypes get_dev_type (const std::string& parDev) {
|
||||
const char dev_prefix[] = "/dev/";
|
||||
const std::size_t dev_prefix_len = lengthof(dev_prefix) - 1;
|
||||
|
@ -162,6 +164,7 @@ namespace din {
|
|||
}
|
||||
return static_cast<LinuxDeviceTypes>(retval);
|
||||
}
|
||||
#endif
|
||||
} //unnamed namespace
|
||||
|
||||
DiscInfo::DiscInfo (std::string&& parPath) :
|
||||
|
@ -188,6 +191,7 @@ namespace din {
|
|||
return not m_device.empty();
|
||||
}
|
||||
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
DriveTypes DiscInfo::drive_type() const {
|
||||
auto dev_type = get_dev_type(m_device);
|
||||
switch (dev_type) {
|
||||
|
@ -322,4 +326,5 @@ namespace din {
|
|||
return OpticalType_Unknown;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
} //namespace din
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <string>
|
||||
|
||||
namespace din {
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
enum OpticalTypes {
|
||||
OpticalType_DVD,
|
||||
OpticalType_CDRom,
|
||||
|
@ -36,6 +37,7 @@ namespace din {
|
|||
DriveType_Other,
|
||||
DriveType_Unknown
|
||||
};
|
||||
#endif
|
||||
|
||||
class DiscInfo {
|
||||
public:
|
||||
|
@ -45,9 +47,11 @@ namespace din {
|
|||
const std::string& mountpoint ( void ) const { return m_mountpoint; }
|
||||
const std::string& device ( void ) const { return m_device; }
|
||||
const std::string& original_path ( void ) const { return m_initial_path; }
|
||||
OpticalTypes optical_type ( void ) const;
|
||||
bool mountpoint_found ( void ) const;
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
OpticalTypes optical_type ( void ) const;
|
||||
DriveTypes drive_type ( void ) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
const std::string m_initial_path;
|
||||
|
|
|
@ -73,6 +73,7 @@ int main (int parArgc, char* parArgv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
char set_type;
|
||||
if (0 == vm.count("type")) {
|
||||
std::cout << "Analyzing disc... ";
|
||||
|
@ -89,6 +90,9 @@ int main (int parArgc, char* parArgv[]) {
|
|||
else {
|
||||
set_type = vm["type"].as<char>();
|
||||
}
|
||||
#else
|
||||
const char set_type = vm["type"].as<char>();
|
||||
#endif
|
||||
|
||||
std::cout << "constructing...\n";
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <utility>
|
||||
|
||||
namespace din {
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
UnknownMediaTypeException::UnknownMediaTypeException (const std::string& parWhat) :
|
||||
std::runtime_error(parWhat)
|
||||
{
|
||||
|
@ -64,4 +65,5 @@ namespace din {
|
|||
throw CantAutodetectException("Can't autodetect set type, please specify it manually");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} //namespace din
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace din {
|
|||
MediaType_Other = 'O'
|
||||
};
|
||||
|
||||
#if defined(WITH_MEDIA_AUTODETECT)
|
||||
MediaTypes guess_media_type ( std::string&& parPath );
|
||||
|
||||
class UnknownMediaTypeException : std::runtime_error {
|
||||
|
@ -46,6 +47,7 @@ namespace din {
|
|||
CantAutodetectException ( const std::string& parWhat );
|
||||
CantAutodetectException ( const char* parWhat );
|
||||
};
|
||||
#endif
|
||||
} //namespace din
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue