1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-02 14:04:22 +00:00

New Mime task.

This commit is contained in:
King_DuckZ 2016-03-09 09:02:17 +01:00
parent c068f93bac
commit 5798e0d315
4 changed files with 105 additions and 1 deletions

View file

@ -0,0 +1,47 @@
/* Copyright 2015, 2016, 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 idE173D2BA33744F448B870BB53AF52610
#define idE173D2BA33744F448B870BB53AF52610
#include "dindexer-machinery/scantask/base.hpp"
#include "dindexer-machinery/scantask/leanbase.hpp"
#include <vector>
#include <memory>
namespace mchlib {
struct FileRecordData;
namespace scantask {
class Mime : public LeanBase<std::vector<FileRecordData>> {
public:
using DirTreeTaskPtr = std::shared_ptr<Base<std::vector<FileRecordData>>>;
explicit Mime ( DirTreeTaskPtr parDirTree );
virtual ~Mime ( void ) noexcept;
private:
virtual void on_data_fill ( void ) override;
virtual std::vector<FileRecordData>& on_data_get ( void ) override;
DirTreeTaskPtr m_file_tree_task;
};
} //namespace scantask
} //namespace mchlib
#endif

View file

@ -20,6 +20,7 @@ add_library(${PROJECT_NAME} SHARED
scantask/mediatype.cpp
scantask/hashing.cpp
scantask/contenttype.cpp
scantask/mime.cpp
)
#target_include_directories(${PROJECT_NAME}

View file

@ -0,0 +1,53 @@
/* Copyright 2015, 2016, 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-machinery/scantask/mime.hpp"
#include "dindexer-machinery/recorddata.hpp"
#include "mimetype.hpp"
#include <cassert>
namespace mchlib {
namespace {
} //unnamed namespace
namespace scantask {
Mime::Mime (DirTreeTaskPtr parDirTree) :
m_file_tree_task(parDirTree)
{
assert(m_file_tree_task);
}
Mime::~Mime() noexcept {
}
void Mime::on_data_fill() {
MimeType mime;
auto& list = m_file_tree_task->get_or_create();
for (auto& itm : list) {
itm.mime_full = mime.analyze(itm.abs_path);
auto mime_pair = split_mime(itm.mime_full);
itm.mime_type = mime_pair.first;
itm.mime_charset = mime_pair.second;
}
}
std::vector<FileRecordData>& Mime::on_data_get() {
return m_file_tree_task->get_or_create();
}
} //namespace scantask
} //namespace mchlib

View file

@ -30,6 +30,7 @@
#include "dindexer-machinery/scantask/mediatype.hpp"
#include "dindexer-machinery/scantask/hashing.hpp"
#include "dindexer-machinery/scantask/contenttype.hpp"
#include "dindexer-machinery/scantask/mime.hpp"
#include <iostream>
#include <iomanip>
#include <ciso646>
@ -82,12 +83,14 @@ int main (int parArgc, char* parArgv[]) {
std::shared_ptr<mchlib::scantask::MediaType> media_type(new mchlib::scantask::MediaType((vm.count("type") ? vm["type"].as<char>() : 'O'), vm.count("type"), search_path));
std::shared_ptr<mchlib::scantask::Hashing> hashing(new mchlib::scantask::Hashing(scan_dirtree, true));
std::shared_ptr<mchlib::scantask::ContentType> content_type(new mchlib::scantask::ContentType(scan_dirtree, media_type));
std::shared_ptr<mchlib::scantask::Mime> mime(new mchlib::scantask::Mime(scan_dirtree));
std::cout << "Content type: " << mchlib::content_type_to_char(content_type->get_or_create()) << std::endl;
mime->get_or_create();
const auto& hashes = hashing->get_or_create();
for (const auto& hash : hashes) {
std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << "\n";
std::cout << '"' << hash.path << "\" -> " << mchlib::tiger_to_string(hash.hash) << " mime: " << hash.mime_type << "\n";
}
return 0;