2020-04-14 00:07:37 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-04-14 00:07:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "erpt_srv_attachment_impl.hpp"
|
|
|
|
#include "erpt_srv_attachment.hpp"
|
|
|
|
|
|
|
|
namespace ams::erpt::srv {
|
|
|
|
|
|
|
|
AttachmentFileName Attachment::FileName(AttachmentId attachment_id) {
|
|
|
|
char uuid_str[AttachmentFileNameLength];
|
|
|
|
attachment_id.uuid.ToString(uuid_str, sizeof(uuid_str));
|
|
|
|
|
|
|
|
AttachmentFileName attachment_name;
|
2021-01-12 10:59:41 +00:00
|
|
|
util::SNPrintf(attachment_name.name, sizeof(attachment_name.name), "%s:/%s.att", ReportStoragePath, uuid_str);
|
2020-04-14 00:07:37 +00:00
|
|
|
return attachment_name;
|
|
|
|
}
|
|
|
|
|
2021-10-10 07:14:06 +00:00
|
|
|
Attachment::Attachment(JournalRecord<AttachmentInfo> *r) : m_record(r) {
|
|
|
|
m_record->AddReference();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Attachment::~Attachment() {
|
|
|
|
this->CloseStream();
|
2021-10-10 07:14:06 +00:00
|
|
|
if (m_record->RemoveReference()) {
|
2020-04-14 00:07:37 +00:00
|
|
|
this->DeleteStream(this->FileName().name);
|
2021-10-10 07:14:06 +00:00
|
|
|
delete m_record;
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 19:13:35 +00:00
|
|
|
AttachmentFileName Attachment::FileName() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return FileName(m_record->m_info.attachment_id);
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Attachment::Open(AttachmentOpenType type) {
|
|
|
|
switch (type) {
|
2022-03-26 21:48:33 +00:00
|
|
|
case AttachmentOpenType_Create: R_RETURN(this->OpenStream(this->FileName().name, StreamMode_Write, AttachmentStreamBufferSize));
|
|
|
|
case AttachmentOpenType_Read: R_RETURN(this->OpenStream(this->FileName().name, StreamMode_Read, AttachmentStreamBufferSize));
|
2022-03-26 07:14:36 +00:00
|
|
|
default: R_THROW(erpt::ResultInvalidArgument());
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Attachment::Read(u32 *out_read_count, u8 *dst, u32 dst_size) {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(this->ReadStream(out_read_count, dst, dst_size));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Attachment::Delete() {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(this->DeleteStream(this->FileName().name));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Attachment::Close() {
|
|
|
|
return this->CloseStream();
|
|
|
|
}
|
|
|
|
|
2020-12-03 19:13:35 +00:00
|
|
|
Result Attachment::GetFlags(AttachmentFlagSet *out) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
*out = m_record->m_info.flags;
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Attachment::SetFlags(AttachmentFlagSet flags) {
|
2021-10-10 07:14:06 +00:00
|
|
|
if (((~m_record->m_info.flags) & flags).IsAnySet()) {
|
|
|
|
m_record->m_info.flags |= flags;
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(Journal::Commit());
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 19:13:35 +00:00
|
|
|
Result Attachment::GetSize(s64 *out) const {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(this->GetStreamSize(out));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|