-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for browsing and saving from cat texture files
- Loading branch information
Showing
8 changed files
with
217 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "catfile.h" | ||
#include <QFile> | ||
#include <QFileInfo> | ||
#include <QMessageBox> | ||
|
||
CatFile::CatFile(QString filePath) | ||
{ | ||
location = filePath; | ||
fileName = QFileInfo(filePath).fileName(); | ||
QFile file(filePath); | ||
if(file.open(QIODevice::ReadOnly)) | ||
{ | ||
file.read((char*)&headerSize, sizeof(int)); | ||
file.read((char*)&extraData, sizeof(int)); | ||
file.seek(extraData); | ||
file.read((char*)&extraSize, sizeof(int)); | ||
file.read((char*)&fileCount, sizeof(int)); | ||
file.read((char*)&fileSize, sizeof(int)); | ||
contentOffsets = new int[fileCount]; | ||
for(int i = 0; i < fileCount; i++) | ||
{ | ||
file.read((char*)&contentOffsets[i], sizeof(int)); | ||
} | ||
} | ||
else | ||
{ | ||
QMessageBox msgBox; | ||
msgBox.setText("Unable to open " + fileName); | ||
msgBox.exec(); | ||
} | ||
file.close(); | ||
} | ||
|
||
int CatFile::getHeaderSize() | ||
{ | ||
return headerSize; | ||
} | ||
|
||
int CatFile::getFileCount() | ||
{ | ||
return fileCount; | ||
} | ||
|
||
int CatFile::getFileSize() | ||
{ | ||
return fileSize; | ||
} | ||
|
||
int CatFile::getContentOffset(int index) | ||
{ | ||
if (index <= fileCount && index > 0) | ||
{ | ||
return contentOffsets[index]; | ||
} | ||
return 0; | ||
} | ||
|
||
QString CatFile::getFileName() | ||
{ | ||
return fileName; | ||
} | ||
|
||
QString CatFile::getFileLocation() | ||
{ | ||
return location; | ||
} | ||
|
||
QByteArray CatFile::readFileData(int index) | ||
{ | ||
QFile file(location); | ||
if(file.open(QIODevice::ReadOnly)) | ||
{ | ||
file.seek(contentOffsets[index - 1] + extraData + extraSize); | ||
|
||
int size; | ||
|
||
// if this is the last file the file ends at the end of the gxt file | ||
if (index == fileCount) | ||
{ | ||
size = file.size() - contentOffsets[index - 1] - extraData - extraSize; | ||
} | ||
else | ||
{ | ||
size = contentOffsets[index] - contentOffsets[index - 1]; | ||
} | ||
return file.read(size); | ||
} | ||
return QByteArray(); | ||
} | ||
|
||
QPixmap CatFile::readDDSFile(int index) | ||
{ | ||
if (index > fileCount || index < 1) | ||
return QPixmap(); | ||
|
||
QByteArray dds = readFileData(index); | ||
QPixmap pixmap; | ||
pixmap.loadFromData(dds); | ||
|
||
return pixmap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef CATFILE_H | ||
#define CATFILE_H | ||
|
||
#include<QPixmap> | ||
#include "resourcefile.h" | ||
|
||
class CatFile : public ResourceFile | ||
{ | ||
public: | ||
CatFile(QString); | ||
int getHeaderSize(); | ||
int getFileCount(); | ||
int getFileSize(); | ||
int getContentOffset(int); | ||
QString getFileName(); | ||
QString getFileLocation(); | ||
QPixmap readDDSFile(int); | ||
QByteArray readFileData(int); | ||
private: | ||
int headerSize; | ||
int extraData; | ||
int extraSize; | ||
int fileCount; | ||
int fileSize; | ||
int* contentOffsets; | ||
QString fileName; | ||
QString location; | ||
}; | ||
|
||
#endif // CATFILE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "resourcefile.h" | ||
|
||
ResourceFile::ResourceFile() | ||
{ | ||
|
||
} | ||
|
||
ResourceFile::~ResourceFile() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef RESOURCEFILE_H | ||
#define RESOURCEFILE_H | ||
|
||
#include <QString> | ||
|
||
class ResourceFile | ||
{ | ||
public: | ||
ResourceFile(); | ||
virtual ~ResourceFile(); | ||
virtual int getHeaderSize() = 0; | ||
virtual int getFileCount() = 0; | ||
virtual int getFileSize() = 0; | ||
virtual int getContentOffset(int) = 0; | ||
virtual QString getFileName() = 0; | ||
virtual QString getFileLocation() = 0; | ||
}; | ||
|
||
#endif // RESOURCEFILE_H |