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) {
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(
"caps:a", std::make_shared<IAlbumAccessorService>(system, album_manager));

View file

@ -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<AlbumEntry>& out_entries, Albu
}
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,
AlbumFileDateTime end_date, u64 aruid) const {
if (!is_mounted) {
@ -93,31 +124,25 @@ Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& 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 =
{
ApplicationAlbumEntry entry{
.size = entry_size,
.hash{},
.datetime = file_id.date,
.storage = file_id.storage,
.content = contex_type,
.unknown = 1,
},
.datetime = file_id.date,
.unknown = {}};
};
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)),
.date =
{
.year = static_cast<u16>(std::stoi(year)),
.month = static_cast<u8>(std::stoi(month)),
.day = static_cast<u8>(std::stoi(day)),
.hour = static_cast<u8>(std::stoi(hour)),
.minute = static_cast<u8>(std::stoi(minute)),
.second = static_cast<u8>(std::stoi(second)),
.year = static_cast<s16>(std::stoi(year)),
.month = static_cast<s8>(std::stoi(month)),
.day = static_cast<s8>(std::stoi(day)),
.hour = static_cast<s8>(std::stoi(hour)),
.minute = static_cast<s8>(std::stoi(minute)),
.second = static_cast<s8>(std::stoi(second)),
.unique_id = 0,
},
.storage = AlbumStorage::Sd,
@ -339,4 +364,23 @@ Result AlbumManager::LoadImage(std::span<u8> 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

View file

@ -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<AlbumEntry>& out_entries, AlbumStorage storage,
u8 flags) const;
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,
AlbumFileDateTime end_date, u64 aruid) 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,
int height, ScreenShotDecoderFlag flag) const;
AlbumFileDateTime ConvertToAlbumDateTime(u64 posix_time) const;
bool is_mounted{};
std::unordered_map<AlbumFileId, std::filesystem::path> album_files;
Core::System& system;
};
} // namespace Service::Capture

View file

@ -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) {

View file

@ -50,22 +50,35 @@ void IAlbumApplicationService::SetShimLibraryVersion(HLERequestContext& ctx) {
void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto pid{rp.Pop<s32>()};
const auto content_type{rp.PopEnum<ContentType>()};
const auto start_posix_time{rp.Pop<s64>()};
const auto end_posix_time{rp.Pop<s64>()};
const auto applet_resource_user_id{rp.Pop<u64>()};
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<Parameters>()};
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<ApplicationAlbumFileEntry> 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<s32>()};
const auto content_type{rp.PopEnum<ContentType>()};
const auto start_date_time{rp.PopRaw<AlbumFileDateTime>()};
const auto end_date_time{rp.PopRaw<AlbumFileDateTime>()};
const auto applet_resource_user_id{rp.Pop<u64>()};
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<Parameters>()};
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<ApplicationAlbumFileEntry> 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<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()) {
ctx.WriteBuffer(entries);