-
Notifications
You must be signed in to change notification settings - Fork 0
/
title_manager.cpp
164 lines (151 loc) · 4.01 KB
/
title_manager.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
#include <array>
#include <cache.hpp>
#include <card_slot.hpp>
#include <string>
#include <title_manager.hpp>
static bool isValidId(u64 id) {
// check for invalid titles.
switch ((u32)id) {
// Instruction Manual
case 0x00008602:
case 0x00009202:
case 0x00009B02:
case 0x0000A402:
case 0x0000AC02:
case 0x0000B402:
// Internet Browser
case 0x00008802:
case 0x00009402:
case 0x00009D02:
case 0x0000A602:
case 0x0000AE02:
case 0x0000B602:
case 0x20008802:
case 0x20009402:
case 0x20009D02:
case 0x2000AE02:
// Garbage
case 0x00021A00:
return false;
}
// Exclude Update Titles.
u32 high = id >> 32;
if (high == 0x0004000E) {
return false;
}
// Exclude Home Menu Themes and also DLC's? Homebrews and game Titles are
// smaller than 0x00040080. Basically exclude everything, which is larger than
// 0x00040080.
if (high >= 0x00040080) {
return false;
}
return true;
}
namespace D7MC {
void TitleManager::ScanSD(const std::string &appmaindir) {
Result res = 0;
u32 count = 0;
sdtitles.clear();
if (!Cache::Read(TitleManager::sdtitles, appmaindir + "cache/sd", false)) {
amInit();
res = AM_GetTitleCount(MEDIATYPE_SD, &count);
if (R_FAILED(res)) {
return;
}
titlecount = (int)count;
std::vector<u64> ids(count);
u64 *p = ids.data();
res = AM_GetTitleList(NULL, MEDIATYPE_SD, count, p);
if (R_FAILED(res)) {
return;
}
for (u32 i = 0; i < count; i++) {
currenttitle = i;
if (isValidId(ids[i])) {
auto title = std::make_shared<Title>();
if (title->load(ids[i], MEDIATYPE_SD)) {
sdtitles.push_back(title);
}
}
}
amExit();
std::sort(sdtitles.begin(), sdtitles.end(),
[](std::shared_ptr<Title> &l, std::shared_ptr<Title> &r) {
return l->name() < r->name();
});
Cache::Create(sdtitles, appmaindir + "cache/sd", (int)count);
}
}
void TitleManager::ScanCard(void) {
amInit();
Result res = 0;
u32 count = 0;
// clear title list if filled previously
gamecard.clear();
res = AM_GetTitleCount(MEDIATYPE_GAME_CARD, &count);
if (R_FAILED(res)) {
return;
}
CardSlot::Update();
if (CardSlot::Satus() == "NotInserted") {
return;
}
if (CardSlot::Type() == "TWL") {
return;
}
// get title list and check if a title matches the ids we want
std::vector<u64> ids(count);
u64 *p = ids.data();
res = AM_GetTitleList(NULL, MEDIATYPE_GAME_CARD, count, p);
if (R_FAILED(res)) {
return;
}
amExit();
for (u32 i = 0; i < count; i++) {
auto title = std::make_shared<Title>();
if (title->load(ids[i], MEDIATYPE_GAME_CARD)) {
gamecard.push_back(title);
}
}
// sort the list alphabetically
std::sort(gamecard.begin(), gamecard.end(),
[](std::shared_ptr<Title> &l, std::shared_ptr<Title> &r) {
return l->id() < r->id();
});
sdtitles.insert(sdtitles.begin(), gamecard[0]);
}
void TitleManager::ScanNand(const std::string &appmaindir) {
Result res = 0;
u32 count = 0;
nandtitles.clear();
if (!Cache::Read(nandtitles, appmaindir + "cache/nand", true)) {
amInit();
res = AM_GetTitleCount(MEDIATYPE_NAND, &count);
if (R_FAILED(res)) {
return;
}
titlecount = (int)count;
std::vector<u64> ids(count);
u64 *p = ids.data();
res = AM_GetTitleList(NULL, MEDIATYPE_NAND, count, p);
if (R_FAILED(res)) {
return;
}
for (u32 i = 0; i < count; i++) {
currenttitle = i;
if (isValidId(ids[i])) {
auto title = std::make_shared<Title>();
if (title->load(ids[i], MEDIATYPE_NAND)) {
nandtitles.push_back(title);
}
}
}
amExit();
std::sort(nandtitles.begin(), nandtitles.end(),
[](std::shared_ptr<Title> &l, std::shared_ptr<Title> &r) {
return l->name() < r->name();
});
Cache::Create(nandtitles, appmaindir + "cache/nand", (int)count);
}
}
} // namespace D7MC