-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
135 lines (114 loc) · 3.85 KB
/
mainwindow.cpp
File metadata and controls
135 lines (114 loc) · 3.85 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
#include "mainwindow.h"
#include <QFileDialog>
#include <QMenuBar>
#include <QJsonArray>
#include <QJsonObject>
#include <QSettings>
extern "C"
{
#include <cl_main.h>
};
#include <Pleasant.h>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
auto action_load = new QAction(tr("&Load core and content"), this);
connect(action_load, SIGNAL(triggered()), this, SLOT(createRetroDialog()));
auto menu_file = menuBar()->addMenu(tr("&File"));
QSettings settings(QDir::currentPath() + "/history.ini", QSettings::IniFormat);
auto history = settings.value("history").toJsonArray();
auto menu_history = menu_file->addMenu(tr("History"));
for (const auto history_entry : history)
{
if (history_entry.isObject())
{
const QJsonObject& entry = history_entry.toObject();
QString core = entry.value("core_path").toString();
QString content = entry.value("content_path").toString();
QString core_name = entry.value("core_name").toString();
QString item_text = tr("%1 (%2)").arg(QFileInfo(content).baseName(), core_name);
QAction* history_action = new QAction(item_text, menu_history);
menu_history->addAction(history_action);
connect(history_action, &QAction::triggered, [=]() { createRetro(core, content); });
}
}
menu_file->addAction(action_load);
}
MainWindow::~MainWindow()
{
}
void MainWindow::onFrame(void)
{
cl_run();
}
int MainWindow::createRetro(const QString& core, const QString& content)
{
Pleasant *retro = new Pleasant();
QSettings settings(QDir::currentPath() + "/history.ini", QSettings::IniFormat);
auto classicslive = settings.value("classicslive", true).toBool();
auto history = settings.value("history").toJsonArray();
retro->username()->setFromApplication();
retro->directories()->set(QRetroDirectories::System, "D:\\RetroArch\\system");
if (!retro->loadCore(core.toStdString().c_str()))
return 1;
if (!content.isEmpty() && !retro->loadContent(content.toStdString().c_str()))
return 2;
if (!retro->startCore())
return 3;
retro->setTitle(retro->core()->system_info.library_name);
retro->show();
QJsonObject history_entry;
history_entry["core_path"] = core;
history_entry["content_path"] = content;
history_entry["core_name"] = retro->core()->system_info.library_name;
bool new_content = true;
for (const auto entry : history)
{
if (entry.toObject().value("content_path").toString() == content)
{
new_content = false;
break;
}
}
if (new_content)
{
history.append(history_entry);
settings.setValue("history", history);
settings.sync();
}
if (classicslive)
{
cl_game_identifier_t identifier;
memset(&identifier, 0, sizeof(identifier));
snprintf(identifier.filename, sizeof(identifier.filename), "%s", content.toStdString().c_str());
identifier.type = CL_GAMEIDENTIFIER_FILE_HASH;
cl_login_and_start(identifier);
connect(retro, SIGNAL(onFrame(void)), this, SLOT(onFrame(void)));
}
return 0;
}
#include <QString>
#include <QDebug>
int MainWindow::createRetroDialog(void)
{
QFileDialog core_dialog(this);
QFileDialog content_dialog(this);
QString core, content = "";
core_dialog.setFileMode(QFileDialog::ExistingFile);
#ifdef _WIN32
core_dialog.setNameFilter(tr("libretro cores (*.dll)"));
#else
core_dialog.setNameFilter(tr("libretro cores (*.so)"));
#endif
core_dialog.exec();
if (!core_dialog.selectedFiles().size())
return 1;
core = core_dialog.selectedFiles()[0];
content_dialog.setDirectory(core);
content_dialog.setNameFilter(tr("Any content file (*)"));
content_dialog.exec();
if (!content_dialog.selectedFiles().size())
content = "";
else
content = content_dialog.selectedFiles()[0];
return createRetro(core, content);
}