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 <set>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28namespace boost
29{
30 namespace filesystem
31 {
32 class path;
33 }
34}
35
37{
39 : updated(0), recent(0), archived(0) { }
40
41 UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
42 : updated(updated_), recent(recent_), archived(archived_) { }
43
44 size_t updated;
45 size_t recent;
46 size_t archived;
47};
48
50{
51 typedef boost::filesystem::path Path;
52
53public:
54 UpdateFetcher(Path const& updateDirectory,
55 std::function<void(std::string const&)> const& apply,
56 std::function<void(Path const& path)> const& applyFile,
57 std::function<QueryResult(std::string const&)> const& retrieve);
59
60 UpdateResult Update(bool const redundancyChecks, bool const allowRehash,
61 bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const;
62
63private:
65 {
67 MODE_REHASH
68 };
69
70 enum State
71 {
73 ARCHIVED
74 };
75
77 {
78 AppliedFileEntry(std::string const& name_, std::string const& hash_, State state_, uint64 timestamp_)
79 : name(name_), hash(hash_), state(state_), timestamp(timestamp_) { }
80
81 std::string const name;
82
83 std::string const hash;
84
85 State const state;
86
88
89 static inline State StateConvert(std::string const& state)
90 {
91 return (state == "RELEASED") ? RELEASED : ARCHIVED;
92 }
93
94 static inline std::string StateConvert(State const state)
95 {
96 return (state == RELEASED) ? "RELEASED" : "ARCHIVED";
97 }
98
99 std::string GetStateAsString() const
100 {
101 return StateConvert(state);
102 }
103 };
104
105 struct DirectoryEntry;
106
107 typedef std::pair<Path, State> LocaleFileEntry;
108
110 {
111 bool operator()(LocaleFileEntry const& left, LocaleFileEntry const& right) const;
112 };
113
114 typedef std::set<LocaleFileEntry, PathCompare> LocaleFileStorage;
115 typedef std::unordered_map<std::string, std::string> HashToFileNameStorage;
116 typedef std::unordered_map<std::string, AppliedFileEntry> AppliedFileStorage;
117 typedef std::vector<UpdateFetcher::DirectoryEntry> DirectoryStorage;
118
119 LocaleFileStorage GetFileList() const;
120 void FillFileListRecursively(Path const& path, LocaleFileStorage& storage,
121 State const state, uint32 const depth) const;
122
123 DirectoryStorage ReceiveIncludedDirectories() const;
124 AppliedFileStorage ReceiveAppliedFiles() const;
125
126 std::string ReadSQLUpdate(Path const& file) const;
127
128 uint32 Apply(Path const& path) const;
129
130 void UpdateEntry(AppliedFileEntry const& entry, uint32 const speed = 0) const;
131 void RenameEntry(std::string const& from, std::string const& to) const;
132 void CleanUp(AppliedFileStorage const& storage) const;
133
134 void UpdateState(std::string const& name, State const state) const;
135
136 std::unique_ptr<Path> const _sourceDirectory;
137
138 std::function<void(std::string const&)> const _apply;
139 std::function<void(Path const& path)> const _applyFile;
140 std::function<QueryResult(std::string const&)> const _retrieve;
141};
142
143#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:51
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:90
static std::string StateConvert(State const state)
Definition: UpdateFetcher.h:94
std::string GetStateAsString() const
Definition: UpdateFetcher.h:99
static State StateConvert(std::string const &state)
Definition: UpdateFetcher.h:89
AppliedFileEntry(std::string const &name_, std::string const &hash_, State state_, uint64 timestamp_)
Definition: UpdateFetcher.h:78
UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
Definition: UpdateFetcher.h:41
size_t updated
Definition: UpdateFetcher.h:44
size_t archived
Definition: UpdateFetcher.h:46