forked from higan-emu/higan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicarus.cpp
177 lines (146 loc) · 4.62 KB
/
icarus.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "icarus.hpp"
namespace icarus {
vector<shared_pointer<Media>> media;
auto locate(string name) -> string {
string location = {Path::program(), name};
if(inode::exists(location)) return location;
directory::create({Path::userData(), "icarus/"});
return {Path::userData(), "icarus/", name};
}
auto operator+=(string& lhs, const string& rhs) -> string& {
lhs.append(rhs);
return lhs;
}
#include "settings/settings.cpp"
#include "media/media.cpp"
#include "cartridge/cartridge.cpp"
#include "compact-disc/compact-disc.cpp"
#include "floppy-disk/floppy-disk.cpp"
#include "program/program.cpp"
auto construct() -> void {
media.append(new BSMemory);
media.append(new ColecoVision);
media.append(new Famicom);
media.append(new FamicomDisk);
media.append(new GameBoy);
media.append(new GameBoyAdvance);
media.append(new GameBoyColor);
media.append(new GameGear);
media.append(new MasterSystem);
media.append(new MegaCD);
media.append(new MegaDrive);
media.append(new MSX);
media.append(new MSX2);
media.append(new NeoGeoPocket);
media.append(new NeoGeoPocketColor);
media.append(new PCEngine);
media.append(new PCEngineCD);
media.append(new PocketChallengeV2);
media.append(new SC3000);
media.append(new SG1000);
media.append(new SufamiTurbo);
media.append(new SuperFamicom);
media.append(new SuperGrafx);
media.append(new WonderSwan);
media.append(new WonderSwanColor);
for(auto& medium : media) medium->construct();
}
auto medium(const string& name) -> shared_pointer<Media> {
for(auto& medium : media) {
if(medium->name() == name) return medium;
}
return {};
}
auto identify(const string& filename) -> string {
auto extension = Location::suffix(filename).trimLeft(".", 1L).downcase();
if(extension == "zip") {
Decode::ZIP archive;
if(archive.open(filename)) {
for(auto& file : archive.file) {
auto match = Location::suffix(file.name).trimLeft(".", 1L).downcase();
for(auto& medium : media) {
if(medium->extensions().find(match)) {
extension = match;
}
}
}
}
}
for(auto& medium : media) {
if(medium->extensions().find(extension)) {
if(auto manifest = medium->manifest(filename)) {
return medium->name();
}
}
}
return {}; //unable to identify
}
auto main(Arguments arguments) -> void {
Application::setName("icarus");
construct();
if(auto document = file::read({Path::userSettings(), "icarus/settings.bml"})) {
settings.unserialize(document);
}
if(arguments.take("--name")) {
return print("icarus");
}
if(string filename; arguments.take("--identify", filename)) {
return print(identify(filename), "\n");
}
if(string system; arguments.take("--system", system)) {
for(auto& medium : media) {
if(medium->name() != system) continue;
if(string manifest; arguments.take("--manifest", manifest)) {
if(auto result = medium->manifest(manifest)) return print(result);
if(medium->extensions().find("cue")) {
//audio CD-ROM fallback
string result;
result.append("game\n");
result.append(" name: ", medium->name(manifest), "\n");
result.append(" label: ", medium->name(manifest), "\n");
return print(result);
}
return;
}
if(string import; arguments.take("--import", import)) {
return (void)medium->import(import);
}
if(arguments.take("--import")) {
if(auto import = BrowserDialog()
.setTitle({"Import ", system, " Game"})
.setPath(settings.recent)
.setAlignment(Alignment::Center)
.openFile()
) {
if(auto error = medium->import(import)) {
MessageDialog()
.setTitle("Error")
.setAlignment(Alignment::Center)
.setText({"Failed to import: ", Location::file(import), "\n\nError: ", error, "."})
.error();
}
}
return;
}
}
}
Instances::programWindow.construct();
#if defined(PLATFORM_MACOS)
Application::Cocoa::onAbout([&] { programWindow.aboutAction.doActivate(); });
Application::Cocoa::onPreferences([&] {});
Application::Cocoa::onQuit([&] { Application::quit(); });
#endif
programWindow.setVisible();
Application::run();
directory::create({Path::userSettings(), "icarus/"});
file::write({Path::userSettings(), "icarus/settings.bml"}, settings.serialize());
Instances::programWindow.destruct();
}
}
#if !defined(MIA_LIBRARY)
#include <higan/resource/resource.cpp>
#include <nall/main.hpp>
auto nall::main(Arguments arguments) -> void {
icarus::main(arguments);
}
#endif