ff7tk 0.80.25
Work with Final Fantasy 7 game data
Lgp.h
Go to the documentation of this file.
1/****************************************************************************/
2// copyright 2009 - 2021 Arzel Jérôme <myst6re@gmail.com> //
3// copyright 2019 Chris Rizzitello <sithlord48@gmail.com> //
4// //
5// This file is part of FF7tk //
6// //
7// FF7tk is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// FF7tk is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16/****************************************************************************/
17/*
18 * This file may contains some code (especially the conflict part)
19 * inspired from LGP/UnLGP tool written by Aali.
20 * http://forums.qhimm.com/index.php?topic=8641.0
21 */
22#pragma once
23
24#include "Archive.h"
25#include "ff7tkformats_export.h"
26
27#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
28#define QMultiHashIterator QHashIterator
29#endif
30
31class LgpHeaderEntry;
32class LgpToc;
33class Lgp;
34
35class FF7TKFORMATS_EXPORT LgpIterator
36{
37 friend class Lgp;
38public:
39 explicit LgpIterator(const Lgp &lgp);
40 bool hasNext() const;
41 void next();
42 void toBack();
43 void toFront();
44 QIODevice *file();
45 QIODevice *modifiedFile();
46 const QString &fileName() const;
47 const QString &fileDir() const;
48 QString filePath() const;
49private:
50 LgpIterator(LgpToc *toc, QFile *lgp);
51 QMultiHashIterator<quint16, LgpHeaderEntry *> it;
52 QFile *_lgp;
53};
54
55class FF7TKFORMATS_EXPORT Lgp : public Archive
56{
57 friend class LgpIterator;
58public:
59 enum LgpError {
73 FileNotFoundError
74 };
75
76 Lgp();
77 explicit Lgp(const QString &name);
78 explicit Lgp(QFile *device);
79 virtual ~Lgp() override;
80 void clear() override;
81 QStringList fileList() const override;
82 int fileCount() const override;
83 LgpIterator iterator();
84 bool fileExists(const QString &filePath) const override;
85 QIODevice *file(const QString &filePath) override;
86 QIODevice *modifiedFile(const QString &filePath) override;
87 bool setFile(const QString &filePath, QIODevice *data) override;
88 bool addFile(const QString &filePath, QIODevice *data) override;
89 bool removeFile(const QString &filePath) override;
90 bool isNameValid(const QString &filePath) const override;
91 bool renameFile(const QString &filePath, const QString &newFilePath) override;
92 const QString &companyName();
93 void setCompanyName(const QString &companyName);
94 const QString &productName();
95 void setProductName(const QString &productName);
96 bool pack(const QString &destination=QString(), ArchiveObserver *observer = nullptr) override;
97 LgpError error() const;
98 void unsetError();
99private:
100 Q_DISABLE_COPY(Lgp)
101 bool openHeader() override;
102 bool openCompanyName();
103 bool openProductName();
104 LgpHeaderEntry *headerEntry(const QString &filePath) const;
105 void setError(LgpError error, const QString &errorString = QString());
106 static QByteArray readAll(QIODevice *d, bool *ok);
107
108 QString _companyName;
109 LgpToc *_files;
110 QString _productName;
111 LgpError _error;
112
113};
The Archive class is a device list in a file system or an archive file.
Definition: Archive.h:35
QString fileName() const
Definition: Archive.cpp:164
Definition: Lgp_p.h:70
Definition: Lgp.h:36
QIODevice * file()
Definition: Lgp.cpp:82
friend class Lgp
Definition: Lgp.h:37
QIODevice * modifiedFile()
Definition: Lgp.cpp:91
QString filePath() const
Definition: Lgp.cpp:118
Definition: Lgp_p.h:117
Definition: Lgp.h:56
QIODevice * modifiedFile(const QString &filePath) override
Definition: Lgp.cpp:228
QIODevice * file(const QString &filePath) override
Definition: Lgp.cpp:214
LgpError
Definition: Lgp.h:59
@ AbortError
Definition: Lgp.h:65
@ OpenTempError
Definition: Lgp.h:64
@ RenameError
Definition: Lgp.h:67
@ OpenError
Definition: Lgp.h:63
@ NoError
Definition: Lgp.h:60
@ PositionError
Definition: Lgp.h:68
@ WriteError
Definition: Lgp.h:62
@ InvalidError
Definition: Lgp.h:72
@ ResizeError
Definition: Lgp.h:69
@ ReadError
Definition: Lgp.h:61
@ RemoveError
Definition: Lgp.h:66
@ CopyError
Definition: Lgp.h:71
@ PermissionsError
Definition: Lgp.h:70
friend class LgpIterator
Definition: Lgp.h:57
Definition: Archive.h:25