-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
138 lines (105 loc) · 4.07 KB
/
mainwindow.cpp
File metadata and controls
138 lines (105 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QDataStream>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "BigRedEditor", "Settings");
ui->setupUi(this);
setWindowTitle("BigRedEditor");
editor = new MainEditorWidget();
setCentralWidget(editor);
ui->actionSave->setDisabled(true);
ui->actionSaveAs->setDisabled(true);
editor->setDisabled(true);
QString iconPath = QCoreApplication::applicationDirPath() + "/data/icons/";
ui->actionOpen->setIcon(QIcon(iconPath + "open.png"));
ui->actionSave->setIcon(QIcon(iconPath + "save.png"));
ui->actionSaveAs->setIcon(QIcon(iconPath + "saveAs.png"));
}
MainWindow::~MainWindow()
{
delete editor;
delete settings;
delete ui;
}
void MainWindow::on_actionOpen_triggered()
{
QString previousPath = settings->value("LastOpenPath").value<QString>();
if (previousPath == "")
previousPath = QCoreApplication::applicationDirPath();
QString openPath = QFileDialog::getOpenFileName(this, "BigRedEditor - Open", previousPath, "NSMB2 Savefile (*.dat);;All Files (*.*)");
if (openPath.isEmpty() || openPath.isNull())
return;
settings->setValue("LastOpenPath", openPath);
QFile file(openPath);
if (!file.open(QFile::ReadOnly))
{
QMessageBox::information(this, "BigRedEditor", "Could not open " + openPath + "!", QMessageBox::Ok);
return;
}
if (file.size() != 0x2838)
{
QMessageBox::information(this, "BigRedEditor", "Incorrect filesize!", QMessageBox::Ok);
return;
}
saveFile = new BigRedSave();
QDataStream inStream(&file);
inStream.setByteOrder(QDataStream::LittleEndian);
inStream.readRawData(reinterpret_cast<char*>(saveFile), sizeof(BigRedSave));
file.close();
if (saveFile->magic != 0x00000020)
{
QMessageBox::information(this, "BigRedEditor", "Invalid File!", QMessageBox::Ok);
delete saveFile;
return;
}
editor->loadFile(saveFile);
ui->statusBar->showMessage("Opened Successfully", 4000);
setWindowTitle("NSMB2SaveEdit - " + openPath);
ui->actionSave->setDisabled(false);
ui->actionSaveAs->setDisabled(false);
editor->setDisabled(false);
}
void MainWindow::on_actionSave_triggered()
{
QString currentFile = settings->value("LastOpenPath").value<QString>();
QFile file(currentFile);
if (!file.open(QFile::WriteOnly))
{
QMessageBox::information(this, "BigRedEditor", "Could not save " + currentFile + "!", QMessageBox::Ok);
return;
}
QDataStream outStream(&file);
outStream.setByteOrder(QDataStream::LittleEndian);
outStream.writeRawData(reinterpret_cast<char*>(saveFile), sizeof(BigRedSave));
file.close();
ui->statusBar->showMessage("Saved Successfully", 4000);
}
void MainWindow::on_actionSaveAs_triggered()
{
QString previousPath = settings->value("LastSavePath").value<QString>();
if (previousPath == "")
previousPath = QCoreApplication::applicationDirPath();
QString savePath = QFileDialog::getSaveFileName(this, "BigRedEditor - Save", previousPath, "NSMB2 Savefile (*.dat);;All Files (*.*)");
if (savePath.isEmpty() || savePath.isNull())
return;
settings->setValue("LastSavePath", savePath);
QFile file(savePath);
if (!file.open(QFile::WriteOnly))
{
QMessageBox::information(this, "BigRedEditor", "Could not save " + savePath + "!", QMessageBox::Ok);
return;
}
QDataStream outStream(&file);
outStream.setByteOrder(QDataStream::LittleEndian);
outStream.writeRawData(reinterpret_cast<char*>(saveFile), sizeof(BigRedSave));
file.close();
ui->statusBar->showMessage("Saved Successfully", 4000);
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::information(this, "BigRedEditor - About", "BigRedEditor v1.0 by Explos\n"
"This software is freeware", QMessageBox::Ok);
}