mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-20 12:14:55 +00:00
Refactor the new media type autodetection code.
This commit is contained in:
parent
c82b41207e
commit
97de157724
7 changed files with 135 additions and 48 deletions
|
@ -13,6 +13,7 @@ add_executable(${PROJECT_NAME}
|
|||
settings.cpp
|
||||
commandline.cpp
|
||||
discinfo.cpp
|
||||
mediatype.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
|
|
|
@ -30,14 +30,14 @@ namespace po = boost::program_options;
|
|||
namespace din {
|
||||
namespace {
|
||||
const char g_allowed_types[] = {
|
||||
static_cast<char>(SetSourceType_CDRom),
|
||||
static_cast<char>(SetSourceType_Directory),
|
||||
static_cast<char>(SetSourceType_DVD),
|
||||
static_cast<char>(SetSourceType_BluRay),
|
||||
static_cast<char>(SetSourceType_FloppyDisk),
|
||||
static_cast<char>(SetSourceType_HardDisk),
|
||||
static_cast<char>(SetSourceType_IomegaZip),
|
||||
static_cast<char>(SetSourceType_Other)
|
||||
static_cast<char>(MediaType_CDRom),
|
||||
static_cast<char>(MediaType_Directory),
|
||||
static_cast<char>(MediaType_DVD),
|
||||
static_cast<char>(MediaType_BluRay),
|
||||
static_cast<char>(MediaType_FloppyDisk),
|
||||
static_cast<char>(MediaType_HardDisk),
|
||||
static_cast<char>(MediaType_IomegaZip),
|
||||
static_cast<char>(MediaType_Other)
|
||||
};
|
||||
const char* const g_version_string =
|
||||
PROGRAM_NAME " v"
|
||||
|
|
|
@ -19,19 +19,9 @@
|
|||
#define id1B7A42F6E46547A6AB0F914E2A91399F
|
||||
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include "mediatype.hpp"
|
||||
|
||||
namespace din {
|
||||
enum SetSourceTypes {
|
||||
SetSourceType_CDRom = 'C',
|
||||
SetSourceType_Directory = 'D',
|
||||
SetSourceType_DVD = 'V',
|
||||
SetSourceType_BluRay = 'B',
|
||||
SetSourceType_FloppyDisk = 'F',
|
||||
SetSourceType_HardDisk = 'H',
|
||||
SetSourceType_IomegaZip = 'Z',
|
||||
SetSourceType_Other = 'O'
|
||||
};
|
||||
|
||||
bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap );
|
||||
} //namespace din
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ 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;
|
||||
DriveTypes drive_type ( void ) const;
|
||||
|
|
|
@ -31,13 +31,11 @@
|
|||
# include <condition_variable>
|
||||
#endif
|
||||
#include <wordexp.h>
|
||||
#include "discinfo.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "filesearcher.hpp"
|
||||
#include "indexer.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "commandline.hpp"
|
||||
#include "pathname.hpp"
|
||||
|
||||
namespace {
|
||||
void run_hash_calculation ( din::Indexer& parIndexer, bool parShowProgress );
|
||||
|
@ -78,40 +76,19 @@ int main (int parArgc, char* parArgv[]) {
|
|||
char set_type;
|
||||
if (0 == vm.count("type")) {
|
||||
std::cout << "Analyzing disc... ";
|
||||
din::DiscInfo info((std::string(search_path)));
|
||||
const din::DriveTypes drive_type = info.drive_type();
|
||||
if (din::DriveType_HardDisk == drive_type) {
|
||||
if (info.mountpoint() == din::PathName(search_path).path())
|
||||
set_type = din::SetSourceType_HardDisk;
|
||||
else
|
||||
set_type = din::SetSourceType_Directory;
|
||||
try {
|
||||
set_type = din::guess_media_type(std::string(search_path));
|
||||
std::cout << "Setting type to " << set_type << '\n';
|
||||
}
|
||||
else if (din::DriveType_Optical == drive_type) {
|
||||
switch (info.optical_type()) {
|
||||
case din::OpticalType_DVD:
|
||||
set_type = din::SetSourceType_DVD;
|
||||
break;
|
||||
case din::OpticalType_CDRom:
|
||||
set_type = din::SetSourceType_CDRom;
|
||||
break;
|
||||
case din::OpticalType_BluRay:
|
||||
set_type = din::SetSourceType_BluRay;
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Set autodetect failed because this media type is unknown, please specify the set type manually\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "Can't autodetect set type, please specify it manually\n";
|
||||
catch (const std::runtime_error& e) {
|
||||
std::cout << '\n';
|
||||
std::cerr << e.what();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
set_type = vm["type"].as<char>();
|
||||
}
|
||||
std::cout << "Setting type to " << set_type << '\n';
|
||||
return 0;
|
||||
|
||||
std::cout << "constructing...\n";
|
||||
|
||||
|
|
67
src/scan/mediatype.cpp
Normal file
67
src/scan/mediatype.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* 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 "mediatype.hpp"
|
||||
#include "pathname.hpp"
|
||||
#include "discinfo.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace din {
|
||||
UnknownMediaTypeException::UnknownMediaTypeException (const std::string& parWhat) :
|
||||
std::runtime_error(parWhat)
|
||||
{
|
||||
}
|
||||
UnknownMediaTypeException::UnknownMediaTypeException (const char* parWhat) :
|
||||
std::runtime_error(parWhat)
|
||||
{
|
||||
}
|
||||
|
||||
CantAutodetectException::CantAutodetectException (const std::string& parWhat) :
|
||||
std::runtime_error(parWhat)
|
||||
{
|
||||
}
|
||||
CantAutodetectException::CantAutodetectException (const char* parWhat) :
|
||||
std::runtime_error(parWhat)
|
||||
{
|
||||
}
|
||||
|
||||
MediaTypes guess_media_type (std::string&& parPath) {
|
||||
DiscInfo info(std::move(parPath));
|
||||
const DriveTypes drive_type = info.drive_type();
|
||||
if (DriveType_HardDisk == drive_type) {
|
||||
if (info.mountpoint() == PathName(info.original_path()).path())
|
||||
return MediaType_HardDisk;
|
||||
else
|
||||
return MediaType_Directory;
|
||||
}
|
||||
else if (DriveType_Optical == drive_type) {
|
||||
switch (info.optical_type()) {
|
||||
case OpticalType_DVD:
|
||||
return MediaType_DVD;
|
||||
case OpticalType_CDRom:
|
||||
return MediaType_CDRom;
|
||||
case OpticalType_BluRay:
|
||||
return MediaType_BluRay;
|
||||
default:
|
||||
throw UnknownMediaTypeException("Set autodetect failed because this media type is unknown, please specify the set type manually");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw CantAutodetectException("Can't autodetect set type, please specify it manually");
|
||||
}
|
||||
}
|
||||
} //namespace din
|
51
src/scan/mediatype.hpp
Normal file
51
src/scan/mediatype.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef id66D41389BC59433CA58E325395A6197B
|
||||
#define id66D41389BC59433CA58E325395A6197B
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace din {
|
||||
enum MediaTypes {
|
||||
MediaType_CDRom = 'C',
|
||||
MediaType_Directory = 'D',
|
||||
MediaType_DVD = 'V',
|
||||
MediaType_BluRay = 'B',
|
||||
MediaType_FloppyDisk = 'F',
|
||||
MediaType_HardDisk = 'H',
|
||||
MediaType_IomegaZip = 'Z',
|
||||
MediaType_Other = 'O'
|
||||
};
|
||||
|
||||
MediaTypes guess_media_type ( std::string&& parPath );
|
||||
|
||||
class UnknownMediaTypeException : std::runtime_error {
|
||||
public:
|
||||
UnknownMediaTypeException ( const std::string& parWhat );
|
||||
UnknownMediaTypeException ( const char* parWhat );
|
||||
};
|
||||
|
||||
class CantAutodetectException : std::runtime_error {
|
||||
public:
|
||||
CantAutodetectException ( const std::string& parWhat );
|
||||
CantAutodetectException ( const char* parWhat );
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue