From fe04a7523a1f06f62fc1cb2337d7718664aaae2f Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Wed, 11 Oct 2023 18:41:56 -0600 Subject: service: caps: Fix GetAlbumFileList3AaeAruid and GetAlbumFileList0AafeAruidDeprecated --- src/core/hle/service/caps/caps.cpp | 2 +- src/core/hle/service/caps/caps_manager.cpp | 86 ++++++++++++++++++++++-------- src/core/hle/service/caps/caps_manager.h | 9 +++- src/core/hle/service/caps/caps_types.h | 14 ++--- src/core/hle/service/caps/caps_u.cpp | 74 +++++++++++++++++-------- 5 files changed, 134 insertions(+), 51 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/caps/caps.cpp b/src/core/hle/service/caps/caps.cpp index 286f9fd10..31dd98140 100644 --- a/src/core/hle/service/caps/caps.cpp +++ b/src/core/hle/service/caps/caps.cpp @@ -16,7 +16,7 @@ namespace Service::Capture { void LoopProcess(Core::System& system) { auto server_manager = std::make_unique(system); - auto album_manager = std::make_shared(); + auto album_manager = std::make_shared(system); server_manager->RegisterNamedService( "caps:a", std::make_shared(system, album_manager)); diff --git a/src/core/hle/service/caps/caps_manager.cpp b/src/core/hle/service/caps/caps_manager.cpp index 2df6a930a..2b4e3f076 100644 --- a/src/core/hle/service/caps/caps_manager.cpp +++ b/src/core/hle/service/caps/caps_manager.cpp @@ -8,12 +8,15 @@ #include "common/fs/file.h" #include "common/fs/path_util.h" #include "common/logging/log.h" +#include "core/core.h" #include "core/hle/service/caps/caps_manager.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 { -AlbumManager::AlbumManager() {} +AlbumManager::AlbumManager(Core::System& system_) : system{system_} {} AlbumManager::~AlbumManager() = default; @@ -83,6 +86,34 @@ Result AlbumManager::GetAlbumFileList(std::vector& out_entries, Albu } Result AlbumManager::GetAlbumFileList(std::vector& out_entries, + ContentType contex_type, s64 start_posix_time, + s64 end_posix_time, u64 aruid) const { + if (!is_mounted) { + return ResultIsNotMounted; + } + + std::vector 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& out_entries, ContentType contex_type, AlbumFileDateTime start_date, AlbumFileDateTime end_date, u64 aruid) const { if (!is_mounted) { @@ -93,31 +124,25 @@ Result AlbumManager::GetAlbumFileList(std::vector& ou if (file_id.type != contex_type) { continue; } - if (file_id.date > start_date) { continue; } - if (file_id.date < end_date) { continue; } - if (out_entries.size() >= SdAlbumFileLimit) { break; } const auto entry_size = Common::FS::GetSize(path); - ApplicationAlbumFileEntry entry{.entry = - { - .size = entry_size, - .hash{}, - .datetime = file_id.date, - .storage = file_id.storage, - .content = contex_type, - .unknown = 1, - }, - .datetime = file_id.date, - .unknown = {}}; + ApplicationAlbumEntry entry{ + .size = entry_size, + .hash{}, + .datetime = file_id.date, + .storage = file_id.storage, + .content = contex_type, + .unknown = 1, + }; out_entries.push_back(entry); } @@ -274,12 +299,12 @@ Result AlbumManager::GetAlbumEntry(AlbumEntry& out_entry, const std::filesystem: .application_id = static_cast(std::stoll(application, 0, 16)), .date = { - .year = static_cast(std::stoi(year)), - .month = static_cast(std::stoi(month)), - .day = static_cast(std::stoi(day)), - .hour = static_cast(std::stoi(hour)), - .minute = static_cast(std::stoi(minute)), - .second = static_cast(std::stoi(second)), + .year = static_cast(std::stoi(year)), + .month = static_cast(std::stoi(month)), + .day = static_cast(std::stoi(day)), + .hour = static_cast(std::stoi(hour)), + .minute = static_cast(std::stoi(minute)), + .second = static_cast(std::stoi(second)), .unique_id = 0, }, .storage = AlbumStorage::Sd, @@ -339,4 +364,23 @@ Result AlbumManager::LoadImage(std::span out_image, const std::filesystem::p 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 diff --git a/src/core/hle/service/caps/caps_manager.h b/src/core/hle/service/caps/caps_manager.h index 8337c655c..f65eb12c1 100644 --- a/src/core/hle/service/caps/caps_manager.h +++ b/src/core/hle/service/caps/caps_manager.h @@ -37,7 +37,7 @@ namespace Service::Capture { class AlbumManager { public: - explicit AlbumManager(); + explicit AlbumManager(Core::System& system_); ~AlbumManager(); Result DeleteAlbumFile(const AlbumFileId& file_id); @@ -45,6 +45,9 @@ public: Result GetAlbumFileList(std::vector& out_entries, AlbumStorage storage, u8 flags) const; Result GetAlbumFileList(std::vector& out_entries, + ContentType contex_type, s64 start_posix_time, s64 end_posix_time, + u64 aruid) const; + Result GetAlbumFileList(std::vector& out_entries, ContentType contex_type, AlbumFileDateTime start_date, AlbumFileDateTime end_date, u64 aruid) const; Result GetAutoSavingStorage(bool& out_is_autosaving) const; @@ -65,8 +68,12 @@ private: Result LoadImage(std::span out_image, const std::filesystem::path& path, int width, int height, ScreenShotDecoderFlag flag) const; + AlbumFileDateTime ConvertToAlbumDateTime(u64 posix_time) const; + bool is_mounted{}; std::unordered_map album_files; + + Core::System& system; }; } // namespace Service::Capture diff --git a/src/core/hle/service/caps/caps_types.h b/src/core/hle/service/caps/caps_types.h index bf6061273..7fd357954 100644 --- a/src/core/hle/service/caps/caps_types.h +++ b/src/core/hle/service/caps/caps_types.h @@ -41,13 +41,13 @@ enum class ScreenShotDecoderFlag : u64 { // This is nn::capsrv::AlbumFileDateTime struct AlbumFileDateTime { - u16 year{}; - u8 month{}; - u8 day{}; - u8 hour{}; - u8 minute{}; - u8 second{}; - u8 unique_id{}; + s16 year{}; + s8 month{}; + s8 day{}; + s8 hour{}; + s8 minute{}; + s8 second{}; + s8 unique_id{}; friend constexpr bool operator==(const AlbumFileDateTime&, const AlbumFileDateTime&) = default; friend constexpr bool operator>(const AlbumFileDateTime& a, const AlbumFileDateTime& b) { diff --git a/src/core/hle/service/caps/caps_u.cpp b/src/core/hle/service/caps/caps_u.cpp index 260f25490..b6b33fb2f 100644 --- a/src/core/hle/service/caps/caps_u.cpp +++ b/src/core/hle/service/caps/caps_u.cpp @@ -50,22 +50,35 @@ void IAlbumApplicationService::SetShimLibraryVersion(HLERequestContext& ctx) { void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto pid{rp.Pop()}; - const auto content_type{rp.PopEnum()}; - const auto start_posix_time{rp.Pop()}; - const auto end_posix_time{rp.Pop()}; - const auto applet_resource_user_id{rp.Pop()}; + struct Parameters { + ContentType content_type; + INSERT_PADDING_BYTES(7); + s64 start_posix_time; + s64 end_posix_time; + u64 applet_resource_user_id; + }; + static_assert(sizeof(Parameters) == 0x20, "Parameters has incorrect size."); + + const auto parameters{rp.PopRaw()}; LOG_WARNING(Service_Capture, - "(STUBBED) called. pid={}, content_type={}, start_posix_time={}, " - "end_posix_time={}, applet_resource_user_id={}", - pid, content_type, start_posix_time, end_posix_time, applet_resource_user_id); + "(STUBBED) called. 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 entries; - const Result result = - manager->GetAlbumFileList(entries, content_type, {}, {}, applet_resource_user_id); + if (result.IsSuccess()) { + result = manager->GetAlbumFileList(entries, parameters.content_type, + parameters.start_posix_time, parameters.end_posix_time, + parameters.applet_resource_user_id); + } if (!entries.empty()) { ctx.WriteBuffer(entries); @@ -78,19 +91,38 @@ void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestCo void IAlbumApplicationService::GetAlbumFileList3AaeAruid(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto pid{rp.Pop()}; - const auto content_type{rp.PopEnum()}; - const auto start_date_time{rp.PopRaw()}; - const auto end_date_time{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; + struct Parameters { + ContentType content_type; + INSERT_PADDING_BYTES(1); + AlbumFileDateTime start_date_time; + 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()}; LOG_WARNING(Service_Capture, - "(STUBBED) called. pid={}, content_type={}, applet_resource_user_id={}", pid, - content_type, applet_resource_user_id); + "(STUBBED) called. content_type={}, start_date={}/{}/{}, " + "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 entries; - const Result result = manager->GetAlbumFileList(entries, content_type, start_date_time, - end_date_time, applet_resource_user_id); + Result result = ResultSuccess; + + if (result.IsSuccess()) { + result = manager->IsAlbumMounted(AlbumStorage::Sd); + } + + std::vector 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()) { ctx.WriteBuffer(entries); -- cgit v1.2.3