service: caps: Fix GetAlbumFileList3AaeAruid and GetAlbumFileList0AafeAruidDeprecated

This commit is contained in:
Narr the Reg 2023-10-11 18:41:56 -06:00
parent da6824d9fd
commit fe04a7523a
5 changed files with 134 additions and 51 deletions

View File

@ -16,7 +16,7 @@ namespace Service::Capture {
void LoopProcess(Core::System& system) { void LoopProcess(Core::System& system) {
auto server_manager = std::make_unique<ServerManager>(system); auto server_manager = std::make_unique<ServerManager>(system);
auto album_manager = std::make_shared<AlbumManager>(); auto album_manager = std::make_shared<AlbumManager>(system);
server_manager->RegisterNamedService( server_manager->RegisterNamedService(
"caps:a", std::make_shared<IAlbumAccessorService>(system, album_manager)); "caps:a", std::make_shared<IAlbumAccessorService>(system, album_manager));

View File

@ -8,12 +8,15 @@
#include "common/fs/file.h" #include "common/fs/file.h"
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/service/caps/caps_manager.h" #include "core/hle/service/caps/caps_manager.h"
#include "core/hle/service/caps/caps_result.h" #include "core/hle/service/caps/caps_result.h"
#include "core/hle/service/time/time_manager.h"
#include "core/hle/service/time/time_zone_content_manager.h"
namespace Service::Capture { namespace Service::Capture {
AlbumManager::AlbumManager() {} AlbumManager::AlbumManager(Core::System& system_) : system{system_} {}
AlbumManager::~AlbumManager() = default; AlbumManager::~AlbumManager() = default;
@ -83,6 +86,34 @@ Result AlbumManager::GetAlbumFileList(std::vector<AlbumEntry>& out_entries, Albu
} }
Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries, Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries,
ContentType contex_type, s64 start_posix_time,
s64 end_posix_time, u64 aruid) const {
if (!is_mounted) {
return ResultIsNotMounted;
}
std::vector<ApplicationAlbumEntry> album_entries;
const auto start_date = ConvertToAlbumDateTime(start_posix_time);
const auto end_date = ConvertToAlbumDateTime(end_posix_time);
const auto result = GetAlbumFileList(album_entries, contex_type, start_date, end_date, aruid);
if (result.IsError()) {
return result;
}
for (const auto& album_entry : album_entries) {
ApplicationAlbumFileEntry entry{
.entry = album_entry,
.datetime = album_entry.datetime,
.unknown = {},
};
out_entries.push_back(entry);
}
return ResultSuccess;
}
Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_entries,
ContentType contex_type, AlbumFileDateTime start_date, ContentType contex_type, AlbumFileDateTime start_date,
AlbumFileDateTime end_date, u64 aruid) const { AlbumFileDateTime end_date, u64 aruid) const {
if (!is_mounted) { if (!is_mounted) {
@ -93,31 +124,25 @@ Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& ou
if (file_id.type != contex_type) { if (file_id.type != contex_type) {
continue; continue;
} }
if (file_id.date > start_date) { if (file_id.date > start_date) {
continue; continue;
} }
if (file_id.date < end_date) { if (file_id.date < end_date) {
continue; continue;
} }
if (out_entries.size() >= SdAlbumFileLimit) { if (out_entries.size() >= SdAlbumFileLimit) {
break; break;
} }
const auto entry_size = Common::FS::GetSize(path); const auto entry_size = Common::FS::GetSize(path);
ApplicationAlbumFileEntry entry{.entry = ApplicationAlbumEntry entry{
{
.size = entry_size, .size = entry_size,
.hash{}, .hash{},
.datetime = file_id.date, .datetime = file_id.date,
.storage = file_id.storage, .storage = file_id.storage,
.content = contex_type, .content = contex_type,
.unknown = 1, .unknown = 1,
}, };
.datetime = file_id.date,
.unknown = {}};
out_entries.push_back(entry); out_entries.push_back(entry);
} }
@ -274,12 +299,12 @@ Result AlbumManager::GetAlbumEntry(AlbumEntry& out_entry, const std::filesystem:
.application_id = static_cast<u64>(std::stoll(application, 0, 16)), .application_id = static_cast<u64>(std::stoll(application, 0, 16)),
.date = .date =
{ {
.year = static_cast<u16>(std::stoi(year)), .year = static_cast<s16>(std::stoi(year)),
.month = static_cast<u8>(std::stoi(month)), .month = static_cast<s8>(std::stoi(month)),
.day = static_cast<u8>(std::stoi(day)), .day = static_cast<s8>(std::stoi(day)),
.hour = static_cast<u8>(std::stoi(hour)), .hour = static_cast<s8>(std::stoi(hour)),
.minute = static_cast<u8>(std::stoi(minute)), .minute = static_cast<s8>(std::stoi(minute)),
.second = static_cast<u8>(std::stoi(second)), .second = static_cast<s8>(std::stoi(second)),
.unique_id = 0, .unique_id = 0,
}, },
.storage = AlbumStorage::Sd, .storage = AlbumStorage::Sd,
@ -339,4 +364,23 @@ Result AlbumManager::LoadImage(std::span<u8> out_image, const std::filesystem::p
return ResultSuccess; return ResultSuccess;
} }
AlbumFileDateTime AlbumManager::ConvertToAlbumDateTime(u64 posix_time) const {
Time::TimeZone::CalendarInfo calendar_date{};
const auto& time_zone_manager =
system.GetTimeManager().GetTimeZoneContentManager().GetTimeZoneManager();
time_zone_manager.ToCalendarTimeWithMyRules(posix_time, calendar_date);
return {
.year = calendar_date.time.year,
.month = calendar_date.time.month,
.day = calendar_date.time.day,
.hour = calendar_date.time.hour,
.minute = calendar_date.time.minute,
.second = calendar_date.time.second,
.unique_id = 0,
};
}
} // namespace Service::Capture } // namespace Service::Capture

View File

@ -37,7 +37,7 @@ namespace Service::Capture {
class AlbumManager { class AlbumManager {
public: public:
explicit AlbumManager(); explicit AlbumManager(Core::System& system_);
~AlbumManager(); ~AlbumManager();
Result DeleteAlbumFile(const AlbumFileId& file_id); Result DeleteAlbumFile(const AlbumFileId& file_id);
@ -45,6 +45,9 @@ public:
Result GetAlbumFileList(std::vector<AlbumEntry>& out_entries, AlbumStorage storage, Result GetAlbumFileList(std::vector<AlbumEntry>& out_entries, AlbumStorage storage,
u8 flags) const; u8 flags) const;
Result GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries, Result GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries,
ContentType contex_type, s64 start_posix_time, s64 end_posix_time,
u64 aruid) const;
Result GetAlbumFileList(std::vector<ApplicationAlbumEntry>& out_entries,
ContentType contex_type, AlbumFileDateTime start_date, ContentType contex_type, AlbumFileDateTime start_date,
AlbumFileDateTime end_date, u64 aruid) const; AlbumFileDateTime end_date, u64 aruid) const;
Result GetAutoSavingStorage(bool& out_is_autosaving) const; Result GetAutoSavingStorage(bool& out_is_autosaving) const;
@ -65,8 +68,12 @@ private:
Result LoadImage(std::span<u8> out_image, const std::filesystem::path& path, int width, Result LoadImage(std::span<u8> out_image, const std::filesystem::path& path, int width,
int height, ScreenShotDecoderFlag flag) const; int height, ScreenShotDecoderFlag flag) const;
AlbumFileDateTime ConvertToAlbumDateTime(u64 posix_time) const;
bool is_mounted{}; bool is_mounted{};
std::unordered_map<AlbumFileId, std::filesystem::path> album_files; std::unordered_map<AlbumFileId, std::filesystem::path> album_files;
Core::System& system;
}; };
} // namespace Service::Capture } // namespace Service::Capture

View File

@ -41,13 +41,13 @@ enum class ScreenShotDecoderFlag : u64 {
// This is nn::capsrv::AlbumFileDateTime // This is nn::capsrv::AlbumFileDateTime
struct AlbumFileDateTime { struct AlbumFileDateTime {
u16 year{}; s16 year{};
u8 month{}; s8 month{};
u8 day{}; s8 day{};
u8 hour{}; s8 hour{};
u8 minute{}; s8 minute{};
u8 second{}; s8 second{};
u8 unique_id{}; s8 unique_id{};
friend constexpr bool operator==(const AlbumFileDateTime&, const AlbumFileDateTime&) = default; friend constexpr bool operator==(const AlbumFileDateTime&, const AlbumFileDateTime&) = default;
friend constexpr bool operator>(const AlbumFileDateTime& a, const AlbumFileDateTime& b) { friend constexpr bool operator>(const AlbumFileDateTime& a, const AlbumFileDateTime& b) {

View File

@ -50,22 +50,35 @@ void IAlbumApplicationService::SetShimLibraryVersion(HLERequestContext& ctx) {
void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestContext& ctx) { void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto pid{rp.Pop<s32>()}; struct Parameters {
const auto content_type{rp.PopEnum<ContentType>()}; ContentType content_type;
const auto start_posix_time{rp.Pop<s64>()}; INSERT_PADDING_BYTES(7);
const auto end_posix_time{rp.Pop<s64>()}; s64 start_posix_time;
const auto applet_resource_user_id{rp.Pop<u64>()}; s64 end_posix_time;
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x20, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_Capture, LOG_WARNING(Service_Capture,
"(STUBBED) called. pid={}, content_type={}, start_posix_time={}, " "(STUBBED) called. content_type={}, start_posix_time={}, end_posix_time={}, "
"end_posix_time={}, applet_resource_user_id={}", "applet_resource_user_id={}",
pid, content_type, start_posix_time, end_posix_time, applet_resource_user_id); parameters.content_type, parameters.start_posix_time, parameters.end_posix_time,
parameters.applet_resource_user_id);
// TODO: Translate posix to DateTime Result result = ResultSuccess;
if (result.IsSuccess()) {
result = manager->IsAlbumMounted(AlbumStorage::Sd);
}
std::vector<ApplicationAlbumFileEntry> entries; std::vector<ApplicationAlbumFileEntry> entries;
const Result result = if (result.IsSuccess()) {
manager->GetAlbumFileList(entries, content_type, {}, {}, applet_resource_user_id); result = manager->GetAlbumFileList(entries, parameters.content_type,
parameters.start_posix_time, parameters.end_posix_time,
parameters.applet_resource_user_id);
}
if (!entries.empty()) { if (!entries.empty()) {
ctx.WriteBuffer(entries); ctx.WriteBuffer(entries);
@ -78,19 +91,38 @@ void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestCo
void IAlbumApplicationService::GetAlbumFileList3AaeAruid(HLERequestContext& ctx) { void IAlbumApplicationService::GetAlbumFileList3AaeAruid(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto pid{rp.Pop<s32>()}; struct Parameters {
const auto content_type{rp.PopEnum<ContentType>()}; ContentType content_type;
const auto start_date_time{rp.PopRaw<AlbumFileDateTime>()}; INSERT_PADDING_BYTES(1);
const auto end_date_time{rp.PopRaw<AlbumFileDateTime>()}; AlbumFileDateTime start_date_time;
const auto applet_resource_user_id{rp.Pop<u64>()}; AlbumFileDateTime end_date_time;
INSERT_PADDING_BYTES(6);
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x20, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_Capture, LOG_WARNING(Service_Capture,
"(STUBBED) called. pid={}, content_type={}, applet_resource_user_id={}", pid, "(STUBBED) called. content_type={}, start_date={}/{}/{}, "
content_type, applet_resource_user_id); "end_date={}/{}/{}, applet_resource_user_id={}",
parameters.content_type, parameters.start_date_time.year,
parameters.start_date_time.month, parameters.start_date_time.day,
parameters.end_date_time.year, parameters.end_date_time.month,
parameters.end_date_time.day, parameters.applet_resource_user_id);
std::vector<ApplicationAlbumFileEntry> entries; Result result = ResultSuccess;
const Result result = manager->GetAlbumFileList(entries, content_type, start_date_time,
end_date_time, applet_resource_user_id); if (result.IsSuccess()) {
result = manager->IsAlbumMounted(AlbumStorage::Sd);
}
std::vector<ApplicationAlbumEntry> entries;
if (result.IsSuccess()) {
result =
manager->GetAlbumFileList(entries, parameters.content_type, parameters.start_date_time,
parameters.end_date_time, parameters.applet_resource_user_id);
}
if (!entries.empty()) { if (!entries.empty()) {
ctx.WriteBuffer(entries); ctx.WriteBuffer(entries);