ff7tk  0.02
Toolkit for making FF7 Tools
Lgp_p.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_P_H
24 #define LGP_P_H
25 
26 #include <QtCore>
27 
28 #define LGP_COMPANY_NAME_SIZE 12
29 #define LGP_PRODUCT_NAME_SIZE 14
30 
31 #define LOOKUP_VALUE_MAX 30
32 #define LOOKUP_TABLE_ENTRIES LOOKUP_VALUE_MAX * LOOKUP_VALUE_MAX
33 
34 #define MAX_CONFLICTS 4096
35 
36 #ifdef _MSC_VER
37 # define PACK(structure) \
38  __pragma(pack(push, 1)) \
39  structure \
40  __pragma(pack(pop))
41 #else
42 # define PACK(structure) structure Q_PACKED
43 #endif
44 
45 PACK(
46 struct LgpLookupTableEntry
47 {
48  quint16 tocOffset;
49  quint16 fileCount;
50 });
51 
53 {
54  LgpConflictEntry() : fileDir(QString()), tocIndex(0) {}
55  LgpConflictEntry(const QString &fileDir, quint16 tocIndex=0) :
56  fileDir(fileDir), tocIndex(tocIndex) {}
57  QString fileDir;
58  quint16 tocIndex;
59 };
60 
62 {
63  LgpTocEntry() : conflict(0), tocIndex(0) {}
64  LgpTocEntry(quint16 tocIndex, quint16 conflict=0) :
65  conflict(conflict), tocIndex(tocIndex) {}
66  quint16 conflict;
67  quint16 tocIndex;
68 };
69 
71 {
72 public:
73  LgpHeaderEntry(const QString &fileName, quint32 filePosition);
74  virtual ~LgpHeaderEntry();
75  const QString &fileName() const;
76  const QString &fileDir() const;
77  QString filePath() const;
78  quint32 filePosition() const;
79  qint64 fileSize() const;
80  void setFileName(const QString &fileName);
81  void setFileDir(const QString &fileDir);
82  void setFilePath(const QString &filePath);
83  void setFilePosition(quint32 filePosition);
84  void setFileSize(quint32 fileSize);
85  QIODevice *file(QIODevice *lgp);
86  QIODevice *modifiedFile(QIODevice *lgp);
87  void setFile(QIODevice *io);
88  void setModifiedFile(QIODevice *io);
89 private:
90  QIODevice *createFile(QIODevice *lgp);
91  QString _fileName;
92  QString _fileDir;
93  quint32 _filePosition;
94  quint32 _fileSize;
96  QIODevice *_io;
97  QIODevice *_newIO;
98 };
99 
100 class LgpIO : public QIODevice
101 {
102 public:
103  LgpIO(QIODevice *lgp, const LgpHeaderEntry *header, QObject *parent=0);
104  bool open(OpenMode mode);
105  qint64 size() const;
106  bool canReadLine() const;
107 protected:
108  qint64 readData(char *data, qint64 maxSize);
109  qint64 writeData(const char *data, qint64 maxSize);
110 private:
111  QIODevice *_lgp;
113 };
114 
115 class LgpIterator;
116 
117 class LgpToc
118 {
119 public:
120  LgpToc();
121  LgpToc(const LgpToc &other);
122  virtual ~LgpToc();
123  bool addEntry(LgpHeaderEntry *entry);
124  LgpHeaderEntry *entry(const QString &filePath) const;
125  QList<LgpHeaderEntry *> entries(quint16 id) const;
126  const QMultiHash<quint16, LgpHeaderEntry *> &table() const;
127  bool hasEntries(quint16 id) const;
128  bool removeEntry(const QString &filePath);
129  static bool isNameValid(const QString &filePath);
130  bool renameEntry(const QString &filePath, const QString &newFilePath);
131  bool contains(const QString &filePath) const;
132  void clear();
133  bool isEmpty() const;
134  int size() const;
135  QList<const LgpHeaderEntry *> filesSortedByPosition() const;
136  LgpToc &operator=(const LgpToc &other);
137 private:
138  LgpHeaderEntry *entry(const QString &filePath, quint16 id) const;
139  static qint32 lookupValue(const QString &filePath);
140  static quint8 lookupValue(const QChar &qc);
141  QMultiHash<quint16, LgpHeaderEntry *> _header;
142 };
143 
144 #endif // LGP_P_H
LgpTocEntry()
Definition: Lgp_p.h:63
#define PACK(structure)
Definition: Lgp_p.h:42
QMultiHash< quint16, LgpHeaderEntry * > _header
Definition: Lgp_p.h:141
quint16 tocIndex
Definition: Lgp_p.h:58
Definition: Lgp_p.h:52
LgpConflictEntry(const QString &fileDir, quint16 tocIndex=0)
Definition: Lgp_p.h:55
quint16 conflict
Definition: Lgp_p.h:66
Definition: Lgp_p.h:70
QString _fileName
Definition: Lgp_p.h:91
bool _hasFileSize
Definition: Lgp_p.h:95
QString fileDir
Definition: Lgp_p.h:57
quint32 _fileSize
Definition: Lgp_p.h:94
QIODevice * _io
Definition: Lgp_p.h:96
LgpConflictEntry()
Definition: Lgp_p.h:54
quint32 _filePosition
Definition: Lgp_p.h:93
QIODevice * _newIO
Definition: Lgp_p.h:97
const LgpHeaderEntry * _header
Definition: Lgp_p.h:112
LgpTocEntry(quint16 tocIndex, quint16 conflict=0)
Definition: Lgp_p.h:64
Definition: Lgp_p.h:61
quint16 tocIndex
Definition: Lgp_p.h:67
Definition: Lgp_p.h:100
QIODevice * _lgp
Definition: Lgp_p.h:111
Definition: Lgp_p.h:117
QString _fileDir
Definition: Lgp_p.h:92