Skip to content

Commit

Permalink
Rework things a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelthegreat committed May 12, 2024
1 parent 7412586 commit acbc786
Show file tree
Hide file tree
Showing 24 changed files with 1,064 additions and 1,186 deletions.
122 changes: 61 additions & 61 deletions src/core/file_sys/archive_artic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "archive_artic.h"
#include "core/file_sys/archive_artic.h"

namespace FileSys {

Expand Down Expand Up @@ -46,7 +46,7 @@ ArticArchive::~ArticArchive() {
}
if (archive_handle != -1) {
auto req = client->NewRequest("FSUSER_CloseArchive");
req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
client->Send(req);
if (report_artic_event != Core::PerfStats::PerfArticEventBits::NONE) {
client->ReportArticEvent(static_cast<u64>(report_artic_event));
Expand All @@ -61,9 +61,9 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArticArchive::Open(

auto req = client->NewRequest("FSUSER_OpenArchive");

req.AddParameterS32(static_cast<s32>(archive_id));
req.AddParameter(static_cast<s32>(archive_id));
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterBuffer(path_buf);

auto resp = client->Send(req);
if (!resp.has_value() || !resp->Succeeded()) {
Expand All @@ -88,7 +88,7 @@ void ArticArchive::Close() {
}

auto req = client->NewRequest("FSUSER_CloseArchive");
req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
if (RespResult(client->Send(req)).IsSuccess()) {
archive_handle = -1;
if (report_artic_event != Core::PerfStats::PerfArticEventBits::NONE) {
Expand All @@ -112,11 +112,11 @@ ResultVal<std::unique_ptr<FileBackend>> ArticArchive::OpenFile(const Path& path,
}
auto req = client->NewRequest("FSUSER_OpenFile");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterU32(mode.hex);
req.AddParameterU32(attributes);
req.AddParameterBuffer(path_buf);
req.AddParameter(mode.hex);
req.AddParameter(attributes);

auto resp = client->Send(req);
auto res = RespResult(resp);
Expand Down Expand Up @@ -154,9 +154,9 @@ Result ArticArchive::DeleteFile(const Path& path) const {

auto req = client->NewRequest("FSUSER_DeleteFile");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterBuffer(path_buf);

return RespResult(client->Send(req));
}
Expand All @@ -175,12 +175,12 @@ Result ArticArchive::RenameFile(const Path& src_path, const Path& dest_path) con

auto req = client->NewRequest("FSUSER_RenameFile");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto src_path_buf = BuildFSPath(src_path);
req.AddParameterBuffer(src_path_buf.data(), src_path_buf.size());
req.AddParameterS64(archive_handle);
req.AddParameterBuffer(src_path_buf);
req.AddParameter(archive_handle);
auto dest_path_buf = BuildFSPath(dest_path);
req.AddParameterBuffer(dest_path_buf.data(), dest_path_buf.size());
req.AddParameterBuffer(dest_path_buf);

return RespResult(client->Send(req));
}
Expand All @@ -190,9 +190,9 @@ Result ArticArchive::DeleteDirectory(const Path& path) const {

auto req = client->NewRequest("FSUSER_DeleteDirectory");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterBuffer(path_buf);

return RespResult(client->Send(req));
}
Expand All @@ -202,9 +202,9 @@ Result ArticArchive::DeleteDirectoryRecursively(const Path& path) const {

auto req = client->NewRequest("FSUSER_DeleteDirectoryRec");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterBuffer(path_buf);

return RespResult(client->Send(req));
}
Expand All @@ -218,22 +218,22 @@ Result ArticArchive::CreateFile(const Path& path, u64 size, u32 attributes) cons

auto req = client->NewRequest("FSUSER_CreateFile");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterU32(attributes);
req.AddParameterU64(size);
req.AddParameterBuffer(path_buf);
req.AddParameter(attributes);
req.AddParameter(size);

return RespResult(client->Send(req));
}

Result ArticArchive::CreateDirectory(const Path& path, u32 attributes) const {
auto req = client->NewRequest("FSUSER_CreateDirectory");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterU32(attributes);
req.AddParameterBuffer(path_buf);
req.AddParameter(attributes);

return RespResult(client->Send(req));
}
Expand All @@ -243,22 +243,22 @@ Result ArticArchive::RenameDirectory(const Path& src_path, const Path& dest_path

auto req = client->NewRequest("FSUSER_RenameDirectory");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto src_path_buf = BuildFSPath(src_path);
req.AddParameterBuffer(src_path_buf.data(), src_path_buf.size());
req.AddParameterS64(archive_handle);
req.AddParameterBuffer(src_path_buf);
req.AddParameter(archive_handle);
auto dest_path_buf = BuildFSPath(dest_path);
req.AddParameterBuffer(dest_path_buf.data(), dest_path_buf.size());
req.AddParameterBuffer(dest_path_buf);

return RespResult(client->Send(req));
}

ResultVal<std::unique_ptr<DirectoryBackend>> ArticArchive::OpenDirectory(const Path& path) {
auto req = client->NewRequest("FSUSER_OpenDirectory");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);
auto path_buf = BuildFSPath(path);
req.AddParameterBuffer(path_buf.data(), path_buf.size());
req.AddParameterBuffer(path_buf);

auto resp = client->Send(req);
auto res = RespResult(resp);
Expand All @@ -281,7 +281,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> ArticArchive::OpenDirectory(const P
u64 ArticArchive::GetFreeBytes() const {
auto req = client->NewRequest("FSUSER_GetFreeBytes");

req.AddParameterS64(archive_handle);
req.AddParameter(archive_handle);

auto resp = client->Send(req);
auto res = RespResult(resp);
Expand All @@ -296,10 +296,10 @@ Result ArticArchive::Control(u32 action, u8* input, size_t input_size, u8* outpu
size_t output_size) {
auto req = client->NewRequest("FSUSER_ControlArchive");

req.AddParameterS64(archive_handle);
req.AddParameterU32(action);
req.AddParameterBuffer(input, input_size);
req.AddParameterU32(static_cast<u32>(output_size));
req.AddParameter(archive_handle);
req.AddParameter(action);
req.AddParameterBuffer(std::span{input, input_size});
req.AddParameter(static_cast<u32>(output_size));

auto resp = client->Send(req);
auto res = RespResult(resp);
Expand All @@ -320,19 +320,19 @@ Result ArticArchive::Control(u32 action, u8* input, size_t input_size, u8* outpu
Result ArticArchive::SetSaveDataSecureValue(u32 secure_value_slot, u64 secure_value, bool flush) {
auto req = client->NewRequest("FSUSER_SetSaveDataSecureValue");

req.AddParameterS64(archive_handle);
req.AddParameterU32(secure_value_slot);
req.AddParameterU64(secure_value);
req.AddParameterS8(flush != 0);
req.AddParameter(archive_handle);
req.AddParameter(secure_value_slot);
req.AddParameter(secure_value);
req.AddParameter(flush != 0);

return RespResult(client->Send(req));
}

ResultVal<std::tuple<bool, bool, u64>> ArticArchive::GetSaveDataSecureValue(u32 secure_value_slot) {
auto req = client->NewRequest("FSUSER_GetSaveDataSecureValue");

req.AddParameterS64(archive_handle);
req.AddParameterU32(secure_value_slot);
req.AddParameter(archive_handle);
req.AddParameter(secure_value_slot);

auto resp = client->Send(req);
auto res = RespResult(resp);
Expand Down Expand Up @@ -373,7 +373,7 @@ void ArticArchive::OpenFileReporter::OnDirectoryClosed() {
ArticFileBackend::~ArticFileBackend() {
if (file_handle != -1) {
auto req = client->NewRequest("FSFILE_Close");
req.AddParameterS32(file_handle);
req.AddParameter(file_handle);
client->Send(req);
open_reporter->OnFileClosed();
}
Expand All @@ -389,9 +389,9 @@ ResultVal<std::size_t> ArticFileBackend::Read(u64 offset, std::size_t length, u8

auto req = client->NewRequest("FSFILE_Read");

req.AddParameterS32(file_handle);
req.AddParameterU64(offset);
req.AddParameterU32(static_cast<u32>(length));
req.AddParameter(file_handle);
req.AddParameter(offset);
req.AddParameter(static_cast<u32>(length));

auto resp = client->Send(req);
auto res = ArticArchive::RespResult(resp);
Expand All @@ -417,11 +417,11 @@ ResultVal<std::size_t> ArticFileBackend::Write(u64 offset, std::size_t length, b
} else {
auto req = client->NewRequest("FSFILE_Write");

req.AddParameterS32(file_handle);
req.AddParameterU64(offset);
req.AddParameterU32(static_cast<u32>(length));
req.AddParameterU32(flags);
req.AddParameterBuffer(buffer, length);
req.AddParameter(file_handle);
req.AddParameter(offset);
req.AddParameter(static_cast<u32>(length));
req.AddParameter(flags);
req.AddParameterBuffer(std::span{buffer, length});

auto resp = client->Send(req);
auto res = ArticArchive::RespResult(resp);
Expand Down Expand Up @@ -449,7 +449,7 @@ u64 ArticFileBackend::GetSize() const {

auto req = client->NewRequest("FSFILE_GetSize");

req.AddParameterS32(file_handle);
req.AddParameter(file_handle);

auto resp = client->Send(req);
auto res = ArticArchive::RespResult(resp);
Expand All @@ -467,15 +467,15 @@ u64 ArticFileBackend::GetSize() const {
bool ArticFileBackend::SetSize(u64 size) const {
auto req = client->NewRequest("FSFILE_SetSize");

req.AddParameterS32(file_handle);
req.AddParameterU64(size);
req.AddParameter(file_handle);
req.AddParameter(size);

return ArticArchive::RespResult(client->Send(req)).IsSuccess();
}

bool ArticFileBackend::Close() {
auto req = client->NewRequest("FSFILE_Close");
req.AddParameterS32(file_handle);
req.AddParameter(file_handle);
bool ret = ArticArchive::RespResult(client->Send(req)).IsSuccess();
if (ret) {
file_handle = -1;
Expand All @@ -487,15 +487,15 @@ bool ArticFileBackend::Close() {
void ArticFileBackend::Flush() const {
auto req = client->NewRequest("FSFILE_Flush");

req.AddParameterS32(file_handle);
req.AddParameter(file_handle);

client->Send(req);
}

ArticDirectoryBackend::~ArticDirectoryBackend() {
if (dir_handle != -1) {
auto req = client->NewRequest("FSDIR_Close");
req.AddParameterS32(dir_handle);
req.AddParameter(dir_handle);
client->Send(req);
open_reporter->OnDirectoryClosed();
}
Expand All @@ -504,8 +504,8 @@ ArticDirectoryBackend::~ArticDirectoryBackend() {
u32 ArticDirectoryBackend::Read(const u32 count, Entry* entries) {
auto req = client->NewRequest("FSDIR_Read");

req.AddParameterS32(dir_handle);
req.AddParameterU32(count);
req.AddParameter(dir_handle);
req.AddParameter(count);

auto resp = client->Send(req);
auto res = ArticArchive::RespResult(resp);
Expand All @@ -524,7 +524,7 @@ u32 ArticDirectoryBackend::Read(const u32 count, Entry* entries) {

bool ArticDirectoryBackend::Close() {
auto req = client->NewRequest("FSDIR_Close");
req.AddParameterS32(dir_handle);
req.AddParameter(dir_handle);
bool ret = ArticArchive::RespResult(client->Send(req)).IsSuccess();
if (ret) {
dir_handle = -1;
Expand Down
6 changes: 3 additions & 3 deletions src/core/file_sys/archive_artic.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include "core/file_sys/file_backend.h"
#include "core/hle/service/fs/archive.h"
#include "core/perf_stats.h"
#include "network/artic_base/artic_base_client.h"
#include "network/artic_base/client.h"

namespace FileSys {

class ArticArchive : public ArchiveBackend {
public:
static std::vector<u8> BuildFSPath(const Path& path);
static Result RespResult(const std::optional<Network::ArticBase::Client::Response>& resp);
static Result RespResult(const std::optional<Network::ArticBase::Response>& resp);

explicit ArticArchive(std::shared_ptr<Network::ArticBase::Client>& _client, s64 _archive_handle,
Core::PerfStats::PerfArticEventBits _report_artic_event,
Expand Down Expand Up @@ -265,4 +265,4 @@ class ArticDirectoryBackend : public DirectoryBackend {

BOOST_CLASS_EXPORT_KEY(FileSys::ArticArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::ArticFileBackend)
BOOST_CLASS_EXPORT_KEY(FileSys::ArticDirectoryBackend)
BOOST_CLASS_EXPORT_KEY(FileSys::ArticDirectoryBackend)
22 changes: 9 additions & 13 deletions src/core/file_sys/archive_extsavedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ Result ArchiveFactory_ExtSaveData::FormatAsExtData(const Path& path,

auto req = artic_client->NewRequest("FSUSER_CreateExtSaveData");

req.AddParameterBuffer(&artic_extdata_path, sizeof(artic_extdata_path));
req.AddParameterU32(format_info.number_directories);
req.AddParameterU32(format_info.number_files);
req.AddParameterU64(total_size);
req.AddParameterBuffer(icon.data(), icon.size());
req.AddParameterBuffer(artic_extdata_path);
req.AddParameter(format_info.number_directories);
req.AddParameter(format_info.number_files);
req.AddParameter(total_size);
req.AddParameterBuffer(icon);

return ArticArchive::RespResult(artic_client->Send(req));
} else {
Expand Down Expand Up @@ -349,8 +349,7 @@ Result ArchiveFactory_ExtSaveData::DeleteExtData(Service::FS::MediaType media_ty
artic_extdata_path.save_id_high = high;

auto req = artic_client->NewRequest("FSUSER_DeleteExtSaveData");

req.AddParameterBuffer(&artic_extdata_path, sizeof(artic_extdata_path));
req.AddParameterBuffer(artic_extdata_path);

return ArticArchive::RespResult(artic_client->Send(req));
} else {
Expand Down Expand Up @@ -383,15 +382,12 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
if (IsUsingArtic()) {
auto req = artic_client->NewRequest("FSUSER_GetFormatInfo");

req.AddParameterS32(static_cast<u32>(ExtSaveDataTypeToArchiveID(type)));
req.AddParameter(ExtSaveDataTypeToArchiveID(type));
auto path_artic = ArticArchive::BuildFSPath(path);
req.AddParameterBuffer(path_artic.data(), path_artic.size());
req.AddParameterBuffer(path_artic);

auto resp = artic_client->Send(req);
Result res = ArticArchive::RespResult(resp);
if (R_FAILED(res)) {
return res;
}
R_TRY(ArticArchive::RespResult(resp));

auto info_buf = resp->GetResponseBuffer(0);
if (!info_buf.has_value() || info_buf->second != sizeof(ArchiveFormatInfo)) {
Expand Down
Loading

0 comments on commit acbc786

Please sign in to comment.