TrinityCore
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 "Define.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 const& state)
91 {
92 return (state == "RELEASED") ? RELEASED : ARCHIVED;
93 }
94
95 static inline std::string StateConvert(State const state)
96 {
97 return (state == RELEASED) ? "RELEASED" : "ARCHIVED";
98 }
99
100 std::string GetStateAsString() const
101 {
102 return StateConvert(state);
103 }
104 };
105
106 struct DirectoryEntry;
107
108 typedef std::pair<Path, State> LocaleFileEntry;
109
111 {
112 bool operator()(LocaleFileEntry const& left, LocaleFileEntry const& right) const;
113 };
114
115 typedef std::set<LocaleFileEntry, PathCompare> LocaleFileStorage;
116 typedef std::unordered_map<std::string, std::string> HashToFileNameStorage;
117 typedef std::unordered_map<std::string, AppliedFileEntry> AppliedFileStorage;
118 typedef std::vector<UpdateFetcher::DirectoryEntry> DirectoryStorage;
119
120 LocaleFileStorage GetFileList() const;
121 void FillFileListRecursively(Path const& path, LocaleFileStorage& storage,
122 State const state, uint32 const depth) const;
123
124 DirectoryStorage ReceiveIncludedDirectories() const;
125 AppliedFileStorage ReceiveAppliedFiles() const;
126
127 std::string ReadSQLUpdate(Path const& file) const;
128
129 uint32 Apply(Path const& path) const;
130
131 void UpdateEntry(AppliedFileEntry const& entry, uint32 const speed = 0) const;
132 void RenameEntry(std::string const& from, std::string const& to) const;
133 void CleanUp(AppliedFileStorage const& storage) const;
134
135 void UpdateState(std::string const& name, State const state) const;
136
137 std::unique_ptr<Path> const _sourceDirectory;
138
139 std::function<void(std::string const&)> const _apply;
140 std::function<void(Path const& path)> const _applyFile;
141 std::function<QueryResult(std::string const&)> const _retrieve;
142};
143
144#endif // UpdateFetcher_h__
std::shared_ptr< ResultSet > QueryResult
#define TC_DATABASE_API
Definition: Define.h:111
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint32_t uint32
Definition: Define.h:142
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
Definition: UpdateFetcher.h:52
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
void apply(T *val)
Definition: ByteConverter.h:41
void Update(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:101
static std::string StateConvert(State const state)
Definition: UpdateFetcher.h:95
std::string GetStateAsString() const
static State StateConvert(std::string const &state)
Definition: UpdateFetcher.h:90
AppliedFileEntry(std::string const &name_, std::string const &hash_, State state_, uint64 timestamp_)
Definition: UpdateFetcher.h:79
UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
Definition: UpdateFetcher.h:42
size_t updated
Definition: UpdateFetcher.h:45
size_t archived
Definition: UpdateFetcher.h:47