MLBookProc 1.1
 
Loading...
Searching...
No Matches
CreateCollection.h
1/*
2 * Copyright (C) 2024-2025 Yury Bobylev <bobilev_yury@mail.ru>
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation, version 3.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#ifndef CREATECOLLECTION_H
18#define CREATECOLLECTION_H
19
20#include <AuxFunc.h>
21#include <FileParseEntry.h>
22#include <Hasher.h>
23#include <filesystem>
24#include <fstream>
25#include <memory>
26#include <string>
27#include <tuple>
28#include <vector>
29
30#ifndef USE_OPENMP
31#include <condition_variable>
32#include <mutex>
33#else
34#include <omp.h>
35#endif
36
43{
44public:
55 CreateCollection(const std::shared_ptr<AuxFunc> &af,
56 const std::filesystem::path &collection_path,
57 const std::filesystem::path &books_path,
58 const bool &rar_support, const int &num_threads);
59
64
70 void
72
79 std::function<void()> pulse;
80
88 std::function<void(const double &)> signal_total_bytes;
89
97 std::function<void(const double &progress)> progress;
98
99protected:
110 CreateCollection(const std::shared_ptr<AuxFunc> &af, const int &num_threads);
111
117 void
119
125 void
127
133 void
135
143 void
145
151 std::filesystem::path base_path;
152
158 std::filesystem::path books_path;
159
165 bool rar_support = false;
166
175 std::vector<std::tuple<std::filesystem::path, std::string>> already_hashed;
176
184 std::vector<std::filesystem::path> need_to_parse;
185
186#ifndef USE_OPENMP
192 std::atomic<double> current_bytes;
193#else
199 double current_bytes = 0.0;
200#endif
201
202private:
203 void
204 threadFunc(const std::filesystem::path &need_to_parse);
205
206 void
207 fb2_thread(const std::filesystem::path &file_col_path,
208 const std::filesystem::path &resolved);
209
210 void
211 epub_thread(const std::filesystem::path &file_col_path,
212 const std::filesystem::path &resolved);
213
214 void
215 pdf_thread(const std::filesystem::path &file_col_path,
216 const std::filesystem::path &resolved);
217
218 void
219 djvu_thread(const std::filesystem::path &file_col_path,
220 const std::filesystem::path &resolved);
221
222 void
223 odt_thread(const std::filesystem::path &file_col_path,
224 const std::filesystem::path &resolved);
225
226 void
227 arch_thread(const std::filesystem::path &file_col_path,
228 const std::filesystem::path &resolved);
229
230 void
231 book_entry_to_file_entry(std::string &file_entry,
232 const std::string &book_entry);
233
234 std::shared_ptr<AuxFunc> af;
235 int num_threads = 1;
236 std::fstream base_strm;
237
238 std::vector<void *> archp_obj;
239
240#ifndef USE_OPENMP
241 std::mutex archp_obj_mtx;
242 int run_threads = 0;
243 std::mutex run_threads_mtx;
244 std::condition_variable run_threads_var;
245 std::mutex base_strm_mtx;
246#else
247 omp_lock_t archp_obj_mtx;
248#endif
249};
250
251#endif // CREATECOLLECTION_H
std::function< void(const double &)> signal_total_bytes
"Total bytes" callback.
Definition CreateCollection.h:88
void closeBaseFile()
Finishes database writing.
std::vector< std::filesystem::path > need_to_parse
"Need to parse" vector.
Definition CreateCollection.h:184
bool rar_support
If true, rar archives will be processed, otherwise - not.
Definition CreateCollection.h:165
std::vector< std::tuple< std::filesystem::path, std::string > > already_hashed
Hashed files.
Definition CreateCollection.h:175
void createCollection()
Starts collection creation.
virtual ~CreateCollection()
CreateCollection destructor.
std::function< void()> pulse
"Pulse" callback.
Definition CreateCollection.h:79
void write_file_to_base(const FileParseEntry &fe)
Writes file data to database.
CreateCollection(const std::shared_ptr< AuxFunc > &af, const std::filesystem::path &collection_path, const std::filesystem::path &books_path, const bool &rar_support, const int &num_threads)
CreateCollection constructor.
CreateCollection(const std::shared_ptr< AuxFunc > &af, const int &num_threads)
CreateCollection constructor.
std::filesystem::path base_path
Absolute path to database.
Definition CreateCollection.h:151
std::filesystem::path books_path
Absolute path to books directory.
Definition CreateCollection.h:158
std::function< void(const double &progress)> progress
"Progress" callback.
Definition CreateCollection.h:97
void threadRegulator()
Threads regulator.
void openBaseFile()
Opens database file for writing.
std::atomic< double > current_bytes
Keeps quantity of bytes have been processed.
Definition CreateCollection.h:192
The FileParseEntry class.
Definition FileParseEntry.h:31
Hasher(const std::shared_ptr< AuxFunc > &af)
Hasher constructor.