[XAM] Added space reporting from "content" storage drive.

Fixed warning related to uninitialized license
This commit is contained in:
Gliniak 2025-04-27 14:03:55 +02:00
parent b8296a9bc9
commit 03571ac4c1
3 changed files with 45 additions and 7 deletions

View File

@ -15,6 +15,7 @@
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h"
#include "xenia/base/string.h"
#include "xenia/emulator.h"
#include "xenia/kernel/kernel_state.h"
@ -39,7 +40,9 @@ ContentPackage::ContentPackage(KernelState* kernel_state,
const std::string_view root_name,
const XCONTENT_AGGREGATE_DATA& data,
const std::filesystem::path& package_path)
: kernel_state_(kernel_state), root_name_(root_name) {
: kernel_state_(kernel_state),
root_name_(root_name),
license_(cvars::license_mask) {
device_path_ = fmt::format("\\Device\\Content\\{0}\\", ++content_device_id_);
content_data_ = data;
@ -59,8 +62,6 @@ ContentPackage::~ContentPackage() {
void ContentPackage::LoadPackageLicenseMask(
const std::filesystem::path header_path) {
license_ = cvars::license_mask;
if (!std::filesystem::exists(header_path)) {
return;
}
@ -540,6 +541,28 @@ void ContentManager::CloseOpenedFilesFromContent(
}
}
uint64_t ContentManager::GetContentTotalSpace() const {
std::error_code ec;
const auto drive_stats = std::filesystem::space(root_path_, ec);
if (ec) {
XELOGW("{}: {} (:08X)", __func__, ec.message(), ec.value());
return 0;
}
return drive_stats.capacity;
}
uint64_t ContentManager::GetContentFreeSpace() const {
std::error_code ec;
const auto drive_stats = std::filesystem::space(root_path_, ec);
if (ec) {
XELOGW("{}: {} (:08X)", __func__, ec.message(), ec.value());
return 0;
}
return drive_stats.free;
}
} // namespace xam
} // namespace kernel
} // namespace xe

View File

@ -185,6 +185,9 @@ class ContentManager {
bool IsContentOpen(const XCONTENT_AGGREGATE_DATA& data) const;
void CloseOpenedFilesFromContent(const std::string_view root_name);
uint64_t GetContentTotalSpace() const;
uint64_t GetContentFreeSpace() const;
private:
std::filesystem::path ResolvePackageRoot(
const uint64_t xuid, const uint32_t title_id,

View File

@ -137,8 +137,14 @@ dword_result_t XamContentGetDeviceData_entry(
device_data.Zero();
device_data->device_id = static_cast<uint32_t>(device_info->device_id);
device_data->device_type = static_cast<uint32_t>(device_info->device_type);
device_data->total_bytes = device_info->total_bytes;
device_data->free_bytes = device_info->free_bytes;
device_data->total_bytes =
device_info->device_type == DeviceType::HDD
? kernel_state()->content_manager()->GetContentTotalSpace()
: device_info->total_bytes;
device_data->free_bytes =
device_info->device_type == DeviceType::HDD
? kernel_state()->content_manager()->GetContentFreeSpace()
: device_info->free_bytes;
xe::string_util::copy_and_swap_truncating(
device_data->name_chars, device_info->name,
xe::countof(device_data->name_chars));
@ -172,8 +178,14 @@ dword_result_t XamContentCreateDeviceEnumerator_entry(dword_t content_type,
device_data->device_id = static_cast<uint32_t>(device_info->device_id);
device_data->device_type =
static_cast<uint32_t>(device_info->device_type);
device_data->total_bytes = device_info->total_bytes;
device_data->free_bytes = device_info->free_bytes;
device_data->total_bytes =
device_info->device_type == DeviceType::HDD
? kernel_state()->content_manager()->GetContentTotalSpace()
: device_info->total_bytes;
device_data->free_bytes =
device_info->device_type == DeviceType::HDD
? kernel_state()->content_manager()->GetContentFreeSpace()
: device_info->free_bytes;
xe::string_util::copy_and_swap_truncating(
device_data->name_chars, device_info->name,
xe::countof(device_data->name_chars));