/
cache.h
113 lines (99 loc) · 3.37 KB
/
cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
* cache.h
*
* Wed Jun 18 12:00:00 CEST 2017
* Copyright 2017 Lars Muldjord
* muldjordlars@gmail.com
****************************************************************************/
/*
* This file is part of skyscraper.
*
* skyscraper is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* skyscraper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with skyscraper; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#ifndef CACHE_H
#define CACHE_H
#include <QObject>
#include <QString>
#include <QMutex>
#include <QDirIterator>
#include <QMap>
#include <QSharedPointer>
#include "gameentry.h"
#include "queue.h"
#include "settings.h"
struct Resource {
QString sha1 = "";
QString type = "";
QString source = "";
QString value = "";
qint64 timestamp = 0;
};
struct ResCounts {
int titles;
int platforms;
int descriptions;
int publishers;
int developers;
int players;
int ages;
int tags;
int ratings;
int releaseDates;
int covers;
int screenshots;
int wheels;
int marquees;
int videos;
};
class Cache
{
public:
Cache(const QString &cacheFolder);
bool createFolders(const QString &scraper);
bool read();
void purgeResources(QString purgeStr);
void printPriorities(QString sha1);
void editResources(QSharedPointer<Queue> queue);
void purgeAll(const bool unattend = false);
void vacuumResources(const QString inputFolder, const QString filters,
const int verbosity, const bool unattend = false);
void assembleReport(const QString inputFolder, const QString filters, QString platform, bool subdirs = true, QString reportStr = "");
void showStats(int verbosity);
void readPriorities();
bool write();
void validate();
void addResources(GameEntry &entry, const Settings &config);
void fillBlanks(GameEntry &entry, const QString scraper = "");
bool hasEntries(const QString &sha1, const QString scraper = "");
void merge(Cache &mergeCache, bool overwrite, const QString &mergeCacheFolder);
QList<Resource> getResources();
private:
QDir cacheDir;
QMutex cacheMutex;
QMap<QString, QList<QString> > prioMap;
QMap<QString, ResCounts> resCountsMap;
QList<Resource> resources;
QList<QFileInfo> getFileInfos(const QString &inputFolder, const QString &filter, const bool subdirs = true);
QList<QString> getSha1List(const QList<QFileInfo> &fileInfos);
void addToResCounts(const QString source, const QString type);
void addResource(const Resource &resource, GameEntry &entry, const QString &cacheAbsolutePath,
const Settings &config);
void verifyFiles(QDirIterator &dirIt, int &filesDeleted, int &noDelete, QString resType);
void verifyResources(int &resourcesDeleted);
bool fillType(QString &type, QList<Resource> &matchingResources,
QString &result, QString &source);
int resAtLoad = 0;
};
#endif // CACHE_H