diff --git a/include/dindexer-machinery/scantask/mime.hpp b/include/dindexer-machinery/scantask/mime.hpp
new file mode 100644
index 0000000..bb4bd7a
--- /dev/null
+++ b/include/dindexer-machinery/scantask/mime.hpp
@@ -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 .
+ */
+
+#ifndef idE173D2BA33744F448B870BB53AF52610
+#define idE173D2BA33744F448B870BB53AF52610
+
+#include "dindexer-machinery/scantask/base.hpp"
+#include "dindexer-machinery/scantask/leanbase.hpp"
+#include
+#include
+
+namespace mchlib {
+ struct FileRecordData;
+
+ namespace scantask {
+ class Mime : public LeanBase> {
+ public:
+ using DirTreeTaskPtr = std::shared_ptr>>;
+
+ explicit Mime ( DirTreeTaskPtr parDirTree );
+ virtual ~Mime ( void ) noexcept;
+
+
+ private:
+ virtual void on_data_fill ( void ) override;
+ virtual std::vector& on_data_get ( void ) override;
+
+ DirTreeTaskPtr m_file_tree_task;
+ };
+ } //namespace scantask
+} //namespace mchlib
+
+#endif
diff --git a/src/machinery/CMakeLists.txt b/src/machinery/CMakeLists.txt
index cd6eb36..9eaceb1 100644
--- a/src/machinery/CMakeLists.txt
+++ b/src/machinery/CMakeLists.txt
@@ -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}
diff --git a/src/machinery/scantask/mime.cpp b/src/machinery/scantask/mime.cpp
new file mode 100644
index 0000000..678e190
--- /dev/null
+++ b/src/machinery/scantask/mime.cpp
@@ -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 .
+ */
+
+#include "dindexer-machinery/scantask/mime.hpp"
+#include "dindexer-machinery/recorddata.hpp"
+#include "mimetype.hpp"
+#include
+
+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& Mime::on_data_get() {
+ return m_file_tree_task->get_or_create();
+ }
+ } //namespace scantask
+} //namespace mchlib
diff --git a/src/scan/main.cpp b/src/scan/main.cpp
index 92e5f2a..e90aafc 100644
--- a/src/scan/main.cpp
+++ b/src/scan/main.cpp
@@ -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
#include
#include
@@ -82,12 +83,14 @@ int main (int parArgc, char* parArgv[]) {
std::shared_ptr media_type(new mchlib::scantask::MediaType((vm.count("type") ? vm["type"].as() : 'O'), vm.count("type"), search_path));
std::shared_ptr hashing(new mchlib::scantask::Hashing(scan_dirtree, true));
std::shared_ptr content_type(new mchlib::scantask::ContentType(scan_dirtree, media_type));
+ std::shared_ptr 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;