ff7tk  0.02
Toolkit for making FF7 Tools
Lgp.h
Go to the documentation of this file.
1 /****************************************************************************
2  ** Makou Reactor Final Fantasy VII Field Script Editor
3  ** Copyright (C) 2009-2012 Arzel Jérôme <myst6re@gmail.com>
4  **
5  ** This program is free software: you can redistribute it and/or modify
6  ** it under the terms of the GNU General Public License as published by
7  ** the Free Software Foundation, either version 3 of the License, or
8  ** (at your option) any later version.
9  **
10  ** This program is distributed in the hope that it will be useful,
11  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  ** GNU General Public License for more details.
14  **
15  ** You should have received a copy of the GNU General Public License
16  ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17  ****************************************************************************/
18 /*
19  * This file may contains some code (especially the conflict part)
20  * inspired from LGP/UnLGP tool written by Aali.
21  * http://forums.qhimm.com/index.php?topic=8641.0
22  */
23 #ifndef LGP_H
24 #define LGP_H
25 
26 #include <QtCore>
27 #include "Archive.h"
28 
29 class LgpHeaderEntry;
30 class LgpToc;
31 class Lgp;
32 
34 {
35  friend class Lgp;
36 public:
37  explicit LgpIterator(const Lgp &lgp);
38  bool hasNext() const;
39  bool hasPrevious() const;
40  void next();
41  void previous();
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;
49 private:
50  LgpIterator(LgpToc *toc, QFile *lgp);
51  QHashIterator<quint16, LgpHeaderEntry *> it;
52  QFile *_lgp;
53 };
54 
55 class Lgp : public Archive
56 {
57  friend class LgpIterator;
58 public:
59  enum LgpError {
72  FileNotFoundError
73  };
74 
75  Lgp();
76  explicit Lgp(const QString &name);
77  explicit Lgp(QFile *device);
78  virtual ~Lgp();
79  void clear();
80  QStringList fileList() const;
81  int fileCount() const;
82  LgpIterator iterator();
83  bool fileExists(const QString &filePath) const;
84  QIODevice *file(const QString &filePath);
85  QIODevice *modifiedFile(const QString &filePath);
86  bool setFile(const QString &filePath, QIODevice *data);
87  bool addFile(const QString &filePath, QIODevice *data);
88  bool removeFile(const QString &filePath);
89  bool isNameValid(const QString &filePath) const;
90  bool renameFile(const QString &filePath, const QString &newFilePath);
91  const QString &companyName();
92  void setCompanyName(const QString &companyName);
93  const QString &productName();
94  void setProductName(const QString &productName);
95  bool pack(const QString &destination=QString(), ArchiveObserver *observer=NULL);
96  LgpError error() const;
97  void unsetError();
98 private:
99  Q_DISABLE_COPY(Lgp)
100  bool openHeader();
101  bool openCompanyName();
102  bool openProductName();
103  LgpHeaderEntry *headerEntry(const QString &filePath) const;
104  void setError(LgpError error, const QString &errorString=QString());
105 
106  QString _companyName;
107  LgpToc *_files;
108  QString _productName;
109  LgpError _error;
110 
111 };
112 
113 #endif // LGP_H
void next()
Advances the iterator by one position.
Definition: Lgp.cpp:66
friend class Lgp
Definition: Lgp.h:35
bool hasPrevious() const
Returns true if there is at least one item behind the iterator, i.e.
Definition: Lgp.cpp:55
void toBack()
Moves the iterator to the back of the container (after the last item).
Definition: Lgp.cpp:86
Definition: Lgp_p.h:70
QFile * _lgp
Definition: Lgp.h:52
void toFront()
Moves the iterator to the front of the container (before the first item).
Definition: Lgp.cpp:95
const QString & fileName() const
Returns the current file name (without the directory).
Definition: Lgp.cpp:122
QHashIterator< quint16, LgpHeaderEntry * > it
Definition: Lgp.h:51
QIODevice * modifiedFile()
Returns the current modified file.
Definition: Lgp.cpp:113
LgpError
Definition: Lgp.h:59
LgpIterator(const Lgp &lgp)
Definition: Lgp.cpp:35
Definition: Lgp.h:55
const QString & fileDir() const
Returns the current file directory (without the file name).
Definition: Lgp.cpp:131
The Archive class is a device list in a file system or an archive file.
Definition: Archive.h:31
QIODevice * file()
Returns the current file.
Definition: Lgp.cpp:104
QString filePath() const
Returns the current full file path (dir + name).
Definition: Lgp.cpp:140
void previous()
Moves the iterator back by one position.
Definition: Lgp.cpp:77
Definition: Lgp_p.h:117
bool hasNext() const
Returns true if there is at least one item ahead of the iterator, i.e.
Definition: Lgp.cpp:45