mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-25 06:01:13 +00:00
609a302e16
This implements waitable management for Events (and implements Events). It also refactors PM to use new Event/Waitable semantics, and also adds STS_ASSERT as a macro for asserting a boolean expression. The rest of stratosphere has been refactored to use STS_ASSERT whenever possible.
79 lines
No EOL
2.7 KiB
C++
79 lines
No EOL
2.7 KiB
C++
/*
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope 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/>.
|
|
*/
|
|
|
|
#include <mutex>
|
|
#include <switch.h>
|
|
|
|
#include "setsys_firmware_version.hpp"
|
|
|
|
static sts::os::Mutex g_version_mutex;
|
|
static bool g_got_version = false;
|
|
static SetSysFirmwareVersion g_ams_fw_version = {0};
|
|
static SetSysFirmwareVersion g_fw_version = {0};
|
|
|
|
void VersionManager::Initialize() {
|
|
std::scoped_lock lock(g_version_mutex);
|
|
|
|
if (g_got_version) {
|
|
return;
|
|
}
|
|
|
|
/* Mount firmware version data archive. */
|
|
R_ASSERT(romfsMountFromDataArchive(static_cast<u64>(sts::ncm::TitleId::ArchiveSystemVersion), FsStorageId_NandSystem, "sysver"));
|
|
{
|
|
ON_SCOPE_EXIT { romfsUnmount("sysver"); };
|
|
|
|
SetSysFirmwareVersion fw_ver;
|
|
|
|
/* Firmware version file must exist. */
|
|
FILE *f = fopen("sysver:/file", "rb");
|
|
STS_ASSERT(f != NULL);
|
|
ON_SCOPE_EXIT { fclose(f); };
|
|
|
|
/* Must be possible to read firmware version from file. */
|
|
STS_ASSERT(fread(&fw_ver, sizeof(fw_ver), 1, f) == 1);
|
|
|
|
g_fw_version = fw_ver;
|
|
g_ams_fw_version = fw_ver;
|
|
}
|
|
|
|
/* Modify the output firmware version. */
|
|
{
|
|
u32 major, minor, micro;
|
|
GetAtmosphereApiVersion(&major, &minor, µ, nullptr, nullptr);
|
|
const char emummc_char = IsEmummc() ? 'E' : 'S';
|
|
{
|
|
char display_version[sizeof(g_ams_fw_version.display_version)] = {0};
|
|
std::snprintf(display_version, sizeof(display_version), "%s|AMS %u.%u.%u|%c", g_ams_fw_version.display_version, major, minor, micro, emummc_char);
|
|
std::memcpy(g_ams_fw_version.display_version, display_version, sizeof(g_ams_fw_version.display_version));
|
|
}
|
|
}
|
|
|
|
g_got_version = true;
|
|
}
|
|
|
|
Result VersionManager::GetFirmwareVersion(sts::ncm::TitleId title_id, SetSysFirmwareVersion *out) {
|
|
VersionManager::Initialize();
|
|
|
|
/* Report atmosphere string to qlaunch, maintenance and nothing else. */
|
|
if (title_id == sts::ncm::TitleId::AppletQlaunch || title_id == sts::ncm::TitleId::AppletMaintenanceMenu) {
|
|
*out = g_ams_fw_version;
|
|
} else {
|
|
*out = g_fw_version;
|
|
}
|
|
|
|
return ResultSuccess;
|
|
} |