mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 20:44:49 +00:00
Misc changes
This commit is contained in:
parent
ca2252254f
commit
1a7b9c3428
3 changed files with 23 additions and 12 deletions
|
@ -129,6 +129,7 @@ namespace sts::ncm::impl {
|
|||
this->GetPath(placeholder_path, placeholder_id);
|
||||
|
||||
debug::DebugLog("Creating %s\n", placeholder_path);
|
||||
D_LOG("size: 0x%lx\n", size);
|
||||
R_TRY_CATCH(fsdevCreateFile(placeholder_path, size, FS_CREATE_BIG_FILE)) {
|
||||
R_CATCH(ResultFsPathAlreadyExists) {
|
||||
return ResultNcmPlaceHolderAlreadyExists;
|
||||
|
|
|
@ -93,6 +93,9 @@ namespace sts::ncm {
|
|||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
sts::rnd::GenerateRandomBytes(out.GetPointer(), sizeof(NcmNcaId));
|
||||
char placeholder_str[FS_MAX_PATH] = {0};
|
||||
GetStringFromPlaceHolderId(placeholder_str, *out.GetPointer());
|
||||
D_LOG("%s\n", placeholder_str);
|
||||
return ResultSuccess;
|
||||
R_DEBUG_END
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
namespace sts::ncm {
|
||||
|
||||
Result OpenFile(FILE** out, const char* path, u32 mode) {
|
||||
R_DEBUG_START
|
||||
bool has = false;
|
||||
|
||||
D_LOG("path %s\n", path);
|
||||
/* Manually check if the file already exists, so it doesn't get created automatically. */
|
||||
R_TRY(HasFile(&has, path));
|
||||
if (!has) {
|
||||
|
@ -36,18 +38,12 @@ namespace sts::ncm {
|
|||
|
||||
const char* fopen_mode = "";
|
||||
|
||||
if (mode & FS_OPEN_APPEND) {
|
||||
if (mode & FS_OPEN_READ) {
|
||||
fopen_mode = "r+b";
|
||||
} else if (mode & FS_OPEN_WRITE) {
|
||||
fopen_mode = "w+b";
|
||||
}
|
||||
} else {
|
||||
if (mode & FS_OPEN_READ) {
|
||||
fopen_mode = "rb";
|
||||
} else if (mode & FS_OPEN_WRITE) {
|
||||
fopen_mode = "wb";
|
||||
}
|
||||
/* Append is forced regardless of whether we set + as the mode.
|
||||
We do so so the file doesn't get deleted. */
|
||||
if (mode & FS_OPEN_READ) {
|
||||
fopen_mode = "r+b";
|
||||
} else if (mode & FS_OPEN_WRITE) {
|
||||
fopen_mode = "w+b";
|
||||
}
|
||||
|
||||
FILE* f = fopen(path, fopen_mode);
|
||||
|
@ -58,12 +54,23 @@ namespace sts::ncm {
|
|||
|
||||
*out = f;
|
||||
return ResultSuccess;
|
||||
R_DEBUG_END
|
||||
}
|
||||
|
||||
Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) {
|
||||
R_DEBUG_START
|
||||
D_LOG("Writing 0x%llx to offset 0x%llx\n", size, offset);
|
||||
|
||||
if (fseek(f, 0, SEEK_END) != 0) {
|
||||
return fsdevGetLastResult();
|
||||
}
|
||||
size_t existing_size = ftell(f);
|
||||
|
||||
if (offset + size > existing_size) {
|
||||
D_LOG("offset: 0x%lx, size: 0x%lx, existing_size: 0x%lx\n", offset, size, existing_size);
|
||||
return ResultFsFileExtensionWithoutOpenModeAllowAppend;
|
||||
}
|
||||
|
||||
if (fseek(f, offset, SEEK_SET) != 0) {
|
||||
return fsdevGetLastResult();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue