TrinityCore
Loading...
Searching...
No Matches
UpdateFetcher.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
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
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef UpdateFetcher_h__
19#define UpdateFetcher_h__
20
21#include "Common.h"
22#include "DatabaseEnvFwd.h"
23#include <functional>
24#include <set>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29namespace boost
30{
31 namespace filesystem
32 {
33 class path;
34 }
35}
36
38{
40 : updated(0), recent(0), archived(0) { }
41
42 UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
43 : updated(updated_), recent(recent_), archived(archived_) { }
44
45 size_t updated;
46 size_t recent;
47 size_t archived;
48};
49
51{
52 typedef boost::filesystem::path Path;
53
54public:
55 UpdateFetcher(Path const& updateDirectory,
56 std::function<void(std::string const&)> const& apply,
57 std::function<void(Path const& path)> const& applyFile,
58 std::function<QueryResult(std::string const&)> const& retrieve);
60
61 UpdateResult Update(bool const redundancyChecks, bool const allowRehash,
62 bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const;
63
64private:
66 {
68 MODE_REHASH
69 };
70
71 enum State
72 {
74 ARCHIVED
75 };
76
78 {
79 AppliedFileEntry(std::string const& name_, std::string const& hash_, State state_, uint64 timestamp_)
80 : name(name_), hash(hash_), state(state_), timestamp(timestamp_) { }
81
82 std::string const name;
83
84 std::string const hash;
85
86 State const state;
87
89
90 static inline State StateConvert(std::string_view const& state)
91 {
92 return (state == "RELEASED"sv) ? RELEASED : ARCHIVED;
93 }
94
95 static inline std::string_view StateConvert(State const state)
96 {
97 return (state == RELEASED) ? "RELEASED"sv : "ARCHIVED"sv;
98 }
99
100 std::string_view GetStateAsString() const
101 {
102 return StateConvert(state);
103 }
104 };
105
106 struct DirectoryEntry;
107
108 typedef std::pair<Path, State> LocaleFileEntry;
109
111 {
112 static std::string MakeComparisonObject(LocaleFileEntry const& arg);
113 static std::string const& MakeComparisonObject(std::string const& arg) { return arg; }
114
115 template<typename L, typename R>
116 bool operator()(L const& left, R const& right) const
117 {
118 return PathCompare::MakeComparisonObject(left) < PathCompare::MakeComparisonObject(right);
119 }
120
121 using is_transparent = int;
122 };
123
124 typedef std::set<LocaleFileEntry, PathCompare> LocaleFileStorage;
125 typedef std::unordered_map<std::string, std::string> HashToFileNameStorage;
126 typedef std::unordered_map<std::string, AppliedFileEntry> AppliedFileStorage;
127 typedef std::vector<UpdateFetcher::DirectoryEntry> DirectoryStorage;
128
129 LocaleFileStorage GetFileList() const;
130 void FillFileListRecursively(Path const& path, LocaleFileStorage& storage,
131 State const state, uint32 const depth) const;
132
133 DirectoryStorage ReceiveIncludedDirectories() const;
134 AppliedFileStorage ReceiveAppliedFiles() const;
135
136 std::string ReadSQLUpdate(Path const& file) const;
137
138 uint32 Apply(Path const& path) const;
139
140 void UpdateEntry(AppliedFileEntry const& entry, uint32 const speed = 0) const;
141 void RenameEntry(std::string const& from, std::string const& to) const;
142 void CleanUp(AppliedFileStorage const& storage) const;
143
144 void UpdateState(std::string const& name, State const state) const;
145
146 std::unique_ptr<Path> const _sourceDirectory;
147
148 std::function<void(std::string const&)> const _apply;
149 std::function<void(Path const& path)> const _applyFile;
150 std::function<QueryResult(std::string const&)> const _retrieve;
151};
152
153#endif // UpdateFetcher_h__
std::shared_ptr< ResultSet > QueryResult
#define TC_DATABASE_API
Definition Define.h:111
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
uint32_t uint32
Definition Define.h:154
std::function< void(std::string const &)> const _apply
std::unordered_map< std::string, AppliedFileEntry > AppliedFileStorage
std::unique_ptr< Path > const _sourceDirectory
std::set< LocaleFileEntry, PathCompare > LocaleFileStorage
boost::filesystem::path Path
std::function< void(Path const &path)> const _applyFile
std::vector< UpdateFetcher::DirectoryEntry > DirectoryStorage
std::unordered_map< std::string, std::string > HashToFileNameStorage
std::pair< Path, State > LocaleFileEntry
std::function< QueryResult(std::string const &)> const _retrieve
std::string_view GetStateAsString() const
AppliedFileEntry(std::string const &name_, std::string const &hash_, State state_, uint64 timestamp_)
static State StateConvert(std::string_view const &state)
static std::string_view StateConvert(State const state)
bool operator()(L const &left, R const &right) const
static std::string const & MakeComparisonObject(std::string const &arg)
UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)