13
by myst6re
BUG: when you save a "one-slot" file into "15-slots" file (like mcr), the 14 missing slots are not added in Hyne. |
1 |
/****************************************************************************
|
2 |
** Hyne Final Fantasy VIII Save Editor
|
|
124
by myst6re
Merging Qt5 branch in trunk: |
3 |
** Copyright (C) 2012-2013 Arzel Jérôme <myst6re@gmail.com>
|
13
by myst6re
BUG: when you save a "one-slot" file into "15-slots" file (like mcr), the 14 missing slots are not added in Hyne. |
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 |
#include "GZIP.h" |
|
134
by myst6re
Re-enabling compatibility with Qt4, but without QTaskbarButton, because it uses winextras now (available since Qt 5.2). |
19 |
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && (defined(Q_OS_WIN) || defined(Q_OS_MAC))
|
20 |
#include "zlib-1.2.7/zlib.h" |
|
21 |
#else
|
|
13
by myst6re
BUG: when you save a "one-slot" file into "15-slots" file (like mcr), the 14 missing slots are not added in Hyne. |
22 |
#include <zlib.h> |
134
by myst6re
Re-enabling compatibility with Qt4, but without QTaskbarButton, because it uses winextras now (available since Qt 5.2). |
23 |
#endif
|
124
by myst6re
Merging Qt5 branch in trunk: |
24 |
#undef compress // conflict with GZIP::compress |
13
by myst6re
BUG: when you save a "one-slot" file into "15-slots" file (like mcr), the 14 missing slots are not added in Hyne. |
25 |
|
26 |
#define BUF_SIZE 8192
|
|
27 |
||
28 |
QByteArray GZIP::decompress(const QByteArray &data, int/* decSize*/) |
|
29 |
{
|
|
30 |
QByteArray ungzip; |
|
31 |
||
32 |
QTemporaryFile temp; |
|
33 |
if(!temp.open()) { |
|
34 |
return QByteArray(); |
|
35 |
}
|
|
36 |
temp.write(data); |
|
37 |
temp.close(); |
|
38 |
gzFile file = gzopen(temp.fileName().toLatin1(), "rb"); |
|
39 |
if(!file) { |
|
40 |
return QByteArray(); |
|
41 |
}
|
|
42 |
char buffer[10000]; |
|
43 |
int r; |
|
44 |
while((r = gzread(file, buffer, 10000)) > 0) { |
|
45 |
ungzip.append(buffer, r); |
|
46 |
}
|
|
47 |
gzclose(file); |
|
48 |
||
49 |
return ungzip; |
|
50 |
}
|
|
51 |
||
52 |
QByteArray GZIP::compress(const QByteArray &ungzip) |
|
53 |
{
|
|
54 |
QString tempPath = QDir::tempPath()+"/qt_temp.gz"; |
|
55 |
||
82
by myst6re
Q_WS_WIN replaced by Q_OS_WIN. |
56 |
gzFile file2 = gzopen(tempPath.toLatin1(), "wb9"); |
13
by myst6re
BUG: when you save a "one-slot" file into "15-slots" file (like mcr), the 14 missing slots are not added in Hyne. |
57 |
if(!file2) { |
58 |
return QByteArray(); |
|
59 |
}
|
|
60 |
gzwrite(file2, ungzip.constData(), ungzip.size()); |
|
61 |
gzclose(file2); |
|
62 |
QFile finalFile(tempPath); |
|
63 |
if(!finalFile.open(QIODevice::ReadOnly)) { |
|
64 |
return QByteArray(); |
|
65 |
}
|
|
66 |
||
67 |
QByteArray data = finalFile.readAll(); |
|
68 |
finalFile.remove(); |
|
69 |
||
70 |
return data; |
|
71 |
}
|
|
72 |
||
73 |
bool GZIP::decompress(const QString &pathFrom, const QString &pathTo) |
|
74 |
{
|
|
75 |
QFile to(pathTo); |
|
76 |
if(!to.open(QIODevice::WriteOnly)) { |
|
77 |
return false; |
|
78 |
}
|
|
79 |
||
80 |
gzFile file = gzopen(pathFrom.toLatin1(), "rb"); |
|
81 |
if(!file) { |
|
82 |
return false; |
|
83 |
}
|
|
84 |
char buffer[BUF_SIZE]; |
|
85 |
int r; |
|
86 |
while((r = gzread(file, buffer, BUF_SIZE)) > 0) { |
|
87 |
to.write(buffer, r); |
|
88 |
}
|
|
89 |
gzclose(file); |
|
90 |
to.close(); |
|
91 |
||
92 |
return true; |
|
93 |
}
|
|
94 |
||
95 |
bool GZIP::compress(const QString &pathFrom, const QString &pathTo) |
|
96 |
{
|
|
97 |
QFile from(pathFrom); |
|
98 |
if(!from.open(QIODevice::ReadOnly)) { |
|
99 |
return false; |
|
100 |
}
|
|
101 |
||
82
by myst6re
Q_WS_WIN replaced by Q_OS_WIN. |
102 |
gzFile file = gzopen(pathTo.toLatin1(), "wb9"); |
13
by myst6re
BUG: when you save a "one-slot" file into "15-slots" file (like mcr), the 14 missing slots are not added in Hyne. |
103 |
if(!file) { |
104 |
return false; |
|
105 |
}
|
|
106 |
char buffer[BUF_SIZE]; |
|
107 |
int r; |
|
108 |
while((r = from.read(buffer, BUF_SIZE)) > 0) { |
|
109 |
gzwrite(file, buffer, BUF_SIZE); |
|
110 |
}
|
|
111 |
gzclose(file); |
|
112 |
from.close(); |
|
113 |
||
114 |
return true; |
|
115 |
}
|