ff7tk 0.80.25
Work with Final Fantasy 7 game data
Archive.h
Go to the documentation of this file.
1/****************************************************************************/
2// copyright 2009 - 2021 Arzel Jérôme <myst6re@gmail.com> //
3// copyright 2019 Chris Rizzitello <sithlord48@gmail.com> //
4// //
5// This file is part of FF7tk //
6// //
7// FF7tk is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// FF7tk is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16/****************************************************************************/
17#pragma once
18
19#include <QBuffer>
20#include <QByteArray>
21#include <QFile>
22#include <QDebug>
23#include "ff7tkformats_export.h"
24
25struct FF7TKFORMATS_EXPORT ArchiveObserver {
27 virtual ~ArchiveObserver();
28 virtual bool observerWasCanceled() const = 0;
29 virtual void setObserverMaximum(unsigned int max) = 0;
30 virtual void setObserverValue(int value) = 0;
31 virtual bool observerRetry(const QString &message) = 0;
32};
33
34class FF7TKFORMATS_EXPORT Archive
35{
36public:
50 FileNotFoundError
51 };
52
53 Archive();
54 explicit Archive(const QString &filename);
55 explicit Archive(QFile *device);
56 virtual ~Archive();
57 virtual inline void clear() {}
58 virtual QStringList fileList() const = 0;
59 virtual int fileCount() const = 0;
60 virtual bool fileExists(const QString &filePath) const = 0;
61 virtual QIODevice *file(const QString &filePath) = 0;
62 QByteArray fileData(const QString &filePath);
63 virtual QIODevice *modifiedFile(const QString &filePath) = 0;
64 QByteArray modifiedFileData(const QString &filePath);
65 virtual bool setFile(const QString &filePath, QIODevice *data) = 0;
66 bool setFileData(const QString &filePath, const QByteArray &data);
67 virtual bool addFile(const QString &filePath, QIODevice *data) = 0;
68 bool addFileData(const QString &filePath, const QByteArray &data);
69 virtual bool removeFile(const QString &filePath) = 0;
70 virtual bool isNameValid(const QString &filePath) const = 0;
71 virtual bool renameFile(const QString &filePath, const QString &newFilePath) = 0;
72 virtual bool open();
73 virtual bool isOpen() const;
74 virtual void close();
75 QString fileName() const;
76 void setFileName(const QString &fileName);
77 virtual bool pack(const QString &destination = QString(), ArchiveObserver *observer = nullptr) = 0;
78 ArchiveError error() const;
79 QString errorString() const;
80protected:
81 virtual bool openHeader() = 0;
82 inline void setErrorString(const QString &errorString)
83 {
84 _errorString = errorString;
85 }
86 void setError(ArchiveError error, const QString &errorString = QString());
87 inline QFile *archiveIO() const
88 {
89 return _archiveIO;
90 }
91
92private:
93 Q_DISABLE_COPY(Archive)
94 QString _errorString;
95 ArchiveError _error;
96 QFile *_archiveIO;
97};
The Archive class is a device list in a file system or an archive file.
Definition: Archive.h:35
ArchiveError
Definition: Archive.h:37
@ ReadError
Definition: Archive.h:39
@ AbortError
Definition: Archive.h:42
@ RenameError
Definition: Archive.h:44
@ NoError
Definition: Archive.h:38
@ OpenError
Definition: Archive.h:41
@ CopyError
Definition: Archive.h:48
@ RemoveError
Definition: Archive.h:43
@ ResizeError
Definition: Archive.h:46
@ InvalidError
Definition: Archive.h:49
@ WriteError
Definition: Archive.h:40
@ PositionError
Definition: Archive.h:45
@ PermissionsError
Definition: Archive.h:47
virtual bool addFile(const QString &filePath, QIODevice *data)=0
virtual QIODevice * file(const QString &filePath)=0
QFile * archiveIO() const
Definition: Archive.h:87
void setErrorString(const QString &errorString)
Definition: Archive.h:82
virtual bool openHeader()=0
virtual bool isNameValid(const QString &filePath) const =0
virtual QStringList fileList() const =0
virtual int fileCount() const =0
virtual bool fileExists(const QString &filePath) const =0
virtual bool removeFile(const QString &filePath)=0
virtual bool pack(const QString &destination=QString(), ArchiveObserver *observer=nullptr)=0
virtual void clear()
Definition: Archive.h:57
virtual bool renameFile(const QString &filePath, const QString &newFilePath)=0
virtual bool setFile(const QString &filePath, QIODevice *data)=0
virtual QIODevice * modifiedFile(const QString &filePath)=0
Definition: Archive.h:25
virtual bool observerWasCanceled() const =0
virtual bool observerRetry(const QString &message)=0
ArchiveObserver()
Definition: Archive.h:26
virtual void setObserverMaximum(unsigned int max)=0
virtual void setObserverValue(int value)=0