src/platform/qt/SaveConverter.h (view raw)
1/* Copyright (c) 2013-2021 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#pragma once
7
8#include <QDialog>
9
10#include "CoreController.h"
11#include "utils.h"
12
13#ifdef M_CORE_GBA
14#include <mgba/gba/core.h>
15#include <mgba/internal/gba/savedata.h>
16#endif
17#ifdef M_CORE_GB
18#include <mgba/gb/core.h>
19#include <mgba/gb/interface.h>
20#endif
21
22#include <mgba/core/serialize.h>
23
24#include "ui_SaveConverter.h"
25
26struct VFile;
27
28namespace QGBA {
29
30class SaveConverter : public QDialog {
31Q_OBJECT
32
33public:
34 SaveConverter(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
35
36 static mPlatform getStatePlatform(VFile*);
37 static QByteArray getState(VFile*, mPlatform);
38 static QByteArray getExtdata(VFile*, mPlatform, mStateExtdataTag);
39
40public slots:
41 void convert();
42
43private slots:
44 void refreshInputTypes();
45 void refreshOutputTypes();
46 void checkCanConvert();
47
48private:
49#ifdef M_CORE_GBA
50 struct GBASave {
51 SavedataType type;
52 };
53#endif
54#ifdef M_CORE_GB
55 struct GBSave {
56 GBMemoryBankControllerType type;
57 };
58#endif
59 struct AnnotatedSave {
60 AnnotatedSave();
61 AnnotatedSave(mPlatform, std::shared_ptr<VFileDevice>, Endian = Endian::NONE);
62#ifdef M_CORE_GBA
63 AnnotatedSave(SavedataType, std::shared_ptr<VFileDevice>, Endian = Endian::NONE);
64#endif
65#ifdef M_CORE_GB
66 AnnotatedSave(GBMemoryBankControllerType, std::shared_ptr<VFileDevice>, Endian = Endian::NONE);
67#endif
68
69 AnnotatedSave asRaw() const;
70 operator QString() const;
71 bool operator==(const AnnotatedSave&) const;
72
73 QList<AnnotatedSave> possibleConversions() const;
74 QByteArray convertTo(const AnnotatedSave&) const;
75
76 bool savestate;
77 mPlatform platform;
78 ssize_t size;
79 std::shared_ptr<VFileDevice> backing;
80 Endian endianness;
81 union {
82#ifdef M_CORE_GBA
83 GBASave gba;
84#endif
85#ifdef M_CORE_GB
86 GBSave gb;
87#endif
88 };
89 };
90
91 void detectFromSavestate(VFile*);
92 void detectFromSize(std::shared_ptr<VFileDevice>);
93 void detectFromHeaders(std::shared_ptr<VFileDevice>);
94
95 Ui::SaveConverter m_ui;
96
97 std::shared_ptr<CoreController> m_controller;
98 QList<AnnotatedSave> m_validSaves;
99 QList<AnnotatedSave> m_validOutputs;
100};
101
102}