MLBookProc 1.1
 
Loading...
Searching...
No Matches
RefreshCollection.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 REFRESHCOLLECTION_H
18#define REFRESHCOLLECTION_H
19
20#include <AuxFunc.h>
21#include <BaseKeeper.h>
22#include <BookBaseEntry.h>
23#include <BookMarks.h>
24#include <CreateCollection.h>
25#include <FileParseEntry.h>
26#include <cstdint>
27#include <filesystem>
28#include <functional>
29#include <memory>
30#include <string>
31#include <vector>
32
33#ifndef USE_OPENMP
34#include <atomic>
35#include <mutex>
36#else
37#include <omp.h>
38#endif
39
47{
48public:
66 RefreshCollection(const std::shared_ptr<AuxFunc> &af,
67 const std::string &collection_name, const int &num_threads,
68 const bool &remove_empty, const bool &refresh_bookmarks,
69 const bool &fast_refresh,
70 const std::shared_ptr<BookMarks> &bookmarks);
71
76
84 std::function<void(const double &total_hash)> total_bytes_to_hash;
85
93 std::function<void(const double &hashed)> bytes_hashed;
94
101 void
103
108 void
110
119 bool
120 editBook(const BookBaseEntry &bbe_old, const BookBaseEntry &bbe_new);
121
127 bool
129
137 void
139
140private:
141 std::filesystem::path
142 get_base_path(const std::string &collection_name);
143
144 std::filesystem::path
145 get_books_path();
146
147 void
148 compaire_vectors(std::vector<FileParseEntry> &base,
149 std::vector<std::filesystem::path> &books_files);
150
151 bool
152 compare_function1(const std::filesystem::path &book_path,
153 const FileParseEntry &ent);
154
155 bool
156 compare_function2(const FileParseEntry &ent,
157 const std::filesystem::path &book_path);
158
159 void
160 check_hashes(std::vector<FileParseEntry> *base,
161 std::vector<std::filesystem::path> *books_files);
162
163 void
164 hash_thread(const std::filesystem::path &file_to_hash,
165 std::vector<FileParseEntry> *base);
166
167 void
168 refreshBookMarks(const std::shared_ptr<BaseKeeper> &bk);
169
170 std::shared_ptr<AuxFunc> af;
171 int num_threads = 1;
172 bool remove_empty = false;
173 bool fast_refresh = false;
174 bool refresh_bookmarks = false;
175 std::shared_ptr<BookMarks> bookmarks;
176
177 std::string collection_name;
178
179#ifndef USE_OPENMP
180 std::atomic<uintmax_t> bytes_summ;
181
182 std::mutex basemtx;
183 std::mutex already_hashedmtx;
184 std::mutex need_to_parsemtx;
185
186 std::mutex newthrmtx;
187 std::condition_variable continue_hashing;
188 int run_threads = 0;
189#else
190 uintmax_t bytes_summ = 0;
191 omp_lock_t basemtx;
192 omp_lock_t already_hashedmtx;
193 omp_lock_t need_to_parsemtx;
194#endif
195};
196
197#endif // REFRESHCOLLECTION_H
The BookBaseEntry class.
Definition BookBaseEntry.h:30
bool rar_support
If true, rar archives will be processed, otherwise - not.
Definition CreateCollection.h:165
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.
The FileParseEntry class.
Definition FileParseEntry.h:31
bool refreshBook(const BookBaseEntry &bbe)
Refreshes information in database about particular book.
void refreshCollection()
Refreshes whole collection.
bool editBook(const BookBaseEntry &bbe_old, const BookBaseEntry &bbe_new)
Replaces information in database.
RefreshCollection(const std::shared_ptr< AuxFunc > &af, const std::string &collection_name, const int &num_threads, const bool &remove_empty, const bool &refresh_bookmarks, const bool &fast_refresh, const std::shared_ptr< BookMarks > &bookmarks)
RefreshCollection constructor.
void set_rar_support(const bool &rar_support)
Enables support of rar archives.
std::function< void(const double &total_hash)> total_bytes_to_hash
"Total bytes to hash" signal.
Definition RefreshCollection.h:84
virtual ~RefreshCollection()
RefreshCollection destructor.
std::function< void(const double &hashed)> bytes_hashed
"Total bytes hashed" signal.
Definition RefreshCollection.h:93
void refreshFile(const BookBaseEntry &bbe)
Refreshes iformation about particular file.