2018-05-14 06:52:41 +00:00
|
|
|
/*
|
2019-05-06 20:51:09 +00:00
|
|
|
* This file is part of Checkpoint
|
|
|
|
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
|
|
* author attributions in that material or in the Appropriate Legal
|
|
|
|
* Notices displayed by works containing it.
|
|
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
|
|
* or requiring that modified versions of such material be marked in
|
|
|
|
* reasonable ways as different from the original version.
|
|
|
|
*/
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
#include "smdh.hpp"
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2018-12-27 14:35:43 +00:00
|
|
|
smdh_s* loadSMDH(u32 low, u32 high, u8 media)
|
2017-09-29 07:45:56 +00:00
|
|
|
{
|
2018-05-14 06:52:41 +00:00
|
|
|
Handle fileHandle;
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2019-05-06 20:51:09 +00:00
|
|
|
u32 archPath[] = {low, high, media, 0x0};
|
2018-05-14 06:52:41 +00:00
|
|
|
static const u32 filePath[] = {0x0, 0x0, 0x2, 0x6E6F6369, 0x0};
|
2019-05-06 20:51:09 +00:00
|
|
|
smdh_s* smdh = new smdh_s;
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
FS_Path binArchPath = {PATH_BINARY, 0x10, archPath};
|
|
|
|
FS_Path binFilePath = {PATH_BINARY, 0x14, filePath};
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
Result res = FSUSER_OpenFileDirectly(&fileHandle, ARCHIVE_SAVEDATA_AND_CONTENT, binArchPath, binFilePath, FS_OPEN_READ, 0);
|
2019-05-06 20:51:09 +00:00
|
|
|
if (R_SUCCEEDED(res)) {
|
2018-05-14 06:52:41 +00:00
|
|
|
u32 read;
|
|
|
|
FSFILE_Read(fileHandle, &read, 0, smdh, sizeof(smdh_s));
|
|
|
|
}
|
2019-05-06 20:51:09 +00:00
|
|
|
else {
|
2018-05-14 06:52:41 +00:00
|
|
|
delete smdh;
|
|
|
|
smdh = NULL;
|
|
|
|
}
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
FSFILE_Close(fileHandle);
|
|
|
|
return smdh;
|
2018-12-27 14:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
smdh_s* loadSMDH(const std::string& path)
|
|
|
|
{
|
2019-04-24 22:13:46 +00:00
|
|
|
FILE* f = fopen(path.c_str(), "rb");
|
2019-05-06 20:51:09 +00:00
|
|
|
if (f != NULL) {
|
2018-12-27 14:35:43 +00:00
|
|
|
smdh_s* smdh = new smdh_s;
|
2019-04-24 22:13:46 +00:00
|
|
|
fread(smdh, 1, sizeof(smdh_s), f);
|
|
|
|
fclose(f);
|
2018-12-27 14:35:43 +00:00
|
|
|
return smdh;
|
|
|
|
}
|
|
|
|
return NULL;
|
2017-09-29 07:45:56 +00:00
|
|
|
}
|