ff7tk  1.2.0.13
Work with Final Fantasy 7 game data
Lgp.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009 - 2021 Arzel Jérôme <myst6re@gmail.com>
2 // SPDX-FileCopyrightText: 2019 Chris Rizzitello <sithlord48@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4 /*
5  * This file may contains some code (especially the conflict part)
6  * inspired from LGP/UnLGP tool written by Aali.
7  * http://forums.qhimm.com/index.php?topic=8641.0
8 */
9 #pragma once
10 
11 #include <Archive>
12 #include <ff7tkformats_export.h>
13 
14 class LgpHeaderEntry;
15 class LgpToc;
16 class Lgp;
17 
18 class FF7TKFORMATS_EXPORT LgpIterator
19 {
20  friend class Lgp;
21 public:
22  explicit LgpIterator(const Lgp &lgp);
23  bool hasNext() const;
24  void next();
25  void toBack();
26  void toFront();
27  QIODevice *file();
28  QIODevice *modifiedFile();
29  const QString &fileName() const;
30  const QString &fileDir() const;
31  QString filePath() const;
32 private:
33  LgpIterator(LgpToc *toc, QFile *lgp);
34  QMultiHashIterator<quint16, LgpHeaderEntry *> it;
35  QFile *_lgp;
36 };
37 
38 class FF7TKFORMATS_EXPORT Lgp : public Archive
39 {
40  friend class LgpIterator;
41 public:
42  enum LgpError {
56  FileNotFoundError
57  };
58 
59  Lgp();
60  explicit Lgp(const QString &name);
61  explicit Lgp(QFile *device);
62  virtual ~Lgp() override;
63  void clear() override;
64  QStringList fileList() const override;
65  int fileCount() const override;
66  LgpIterator iterator();
67  bool fileExists(const QString &filePath) const override;
68  QIODevice *file(const QString &filePath) override;
69  QIODevice *modifiedFile(const QString &filePath) override;
70  bool setFile(const QString &filePath, QIODevice *data) override;
71  bool addFile(const QString &filePath, QIODevice *data) override;
72  bool removeFile(const QString &filePath) override;
73  bool isNameValid(const QString &filePath) const override;
74  bool renameFile(const QString &filePath, const QString &newFilePath) override;
75  const QString &companyName();
76  void setCompanyName(const QString &companyName);
77  const QString &productName();
78  void setProductName(const QString &productName);
79  bool pack(const QString &destination=QString(), ArchiveObserver *observer = nullptr) override;
80  LgpError error() const;
81  void unsetError();
82 private:
83  Q_DISABLE_COPY(Lgp)
84  bool openHeader() override;
85  bool openCompanyName();
86  bool openProductName();
87  LgpHeaderEntry *headerEntry(const QString &filePath) const;
88  void setError(LgpError error, const QString &errorString = QString());
89  static QByteArray readAll(QIODevice *d, bool *ok);
90 
91  QString _companyName;
92  LgpToc *_files;
93  QString _productName;
94  LgpError _error;
95 
96 };
LgpIterator
Definition: Lgp.h:18
Lgp::PermissionsError
@ PermissionsError
Definition: Lgp.h:53
Lgp::file
QIODevice * file(const QString &filePath) override
Definition: Lgp.cpp:201
Archive::pack
virtual bool pack(const QString &destination=QString(), ArchiveObserver *observer=nullptr)=0
Lgp::RenameError
@ RenameError
Definition: Lgp.h:50
Archive::setError
void setError(ArchiveError error, const QString &errorString=QString())
Definition: Archive.cpp:191
Lgp::WriteError
@ WriteError
Definition: Lgp.h:45
Lgp::OpenError
@ OpenError
Definition: Lgp.h:46
Archive::fileCount
virtual int fileCount() const =0
Lgp::InvalidError
@ InvalidError
Definition: Lgp.h:55
Lgp::OpenTempError
@ OpenTempError
Definition: Lgp.h:47
ArchiveObserver
Definition: Archive.h:13
Archive::fileName
QString fileName() const
Definition: Archive.cpp:152
Archive::clear
virtual void clear()
Definition: Archive.h:45
Archive::renameFile
virtual bool renameFile(const QString &filePath, const QString &newFilePath)=0
Lgp::RemoveError
@ RemoveError
Definition: Lgp.h:49
Archive::error
ArchiveError error() const
Definition: Archive.cpp:182
Archive::addFile
virtual bool addFile(const QString &filePath, QIODevice *data)=0
LgpHeaderEntry
Definition: Lgp_p.h:56
LgpIterator::Lgp
friend class Lgp
Definition: Lgp.h:20
Lgp::ReadError
@ ReadError
Definition: Lgp.h:44
Archive::openHeader
virtual bool openHeader()=0
Archive::file
virtual QIODevice * file(const QString &filePath)=0
Lgp::CopyError
@ CopyError
Definition: Lgp.h:54
Lgp::PositionError
@ PositionError
Definition: Lgp.h:51
Lgp::ResizeError
@ ResizeError
Definition: Lgp.h:52
Lgp::NoError
@ NoError
Definition: Lgp.h:43
Lgp::LgpIterator
friend class LgpIterator
Definition: Lgp.h:40
Archive
The Archive class is a device list in a file system or an archive file.
Definition: Archive.h:22
LgpIterator::filePath
QString filePath() const
Definition: Lgp.cpp:105
LgpToc
Definition: Lgp_p.h:103
Lgp::modifiedFile
QIODevice * modifiedFile(const QString &filePath) override
Definition: Lgp.cpp:215
Archive::setFile
virtual bool setFile(const QString &filePath, QIODevice *data)=0
Archive::fileList
virtual QStringList fileList() const =0
Archive::fileExists
virtual bool fileExists(const QString &filePath) const =0
Archive::removeFile
virtual bool removeFile(const QString &filePath)=0
Archive::isNameValid
virtual bool isNameValid(const QString &filePath) const =0
Lgp
Definition: Lgp.h:38
Lgp::LgpError
LgpError
Definition: Lgp.h:42
Lgp::AbortError
@ AbortError
Definition: Lgp.h:48
Archive::modifiedFile
virtual QIODevice * modifiedFile(const QString &filePath)=0