mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-07 18:12:14 +02:00
Misc changes
This commit is contained in:
parent
ca2252254f
commit
1a7b9c3428
@ -129,6 +129,7 @@ namespace sts::ncm::impl {
|
|||||||
this->GetPath(placeholder_path, placeholder_id);
|
this->GetPath(placeholder_path, placeholder_id);
|
||||||
|
|
||||||
debug::DebugLog("Creating %s\n", placeholder_path);
|
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_TRY_CATCH(fsdevCreateFile(placeholder_path, size, FS_CREATE_BIG_FILE)) {
|
||||||
R_CATCH(ResultFsPathAlreadyExists) {
|
R_CATCH(ResultFsPathAlreadyExists) {
|
||||||
return ResultNcmPlaceHolderAlreadyExists;
|
return ResultNcmPlaceHolderAlreadyExists;
|
||||||
|
@ -93,6 +93,9 @@ namespace sts::ncm {
|
|||||||
R_TRY(this->EnsureEnabled());
|
R_TRY(this->EnsureEnabled());
|
||||||
|
|
||||||
sts::rnd::GenerateRandomBytes(out.GetPointer(), sizeof(NcmNcaId));
|
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;
|
return ResultSuccess;
|
||||||
R_DEBUG_END
|
R_DEBUG_END
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,10 @@
|
|||||||
namespace sts::ncm {
|
namespace sts::ncm {
|
||||||
|
|
||||||
Result OpenFile(FILE** out, const char* path, u32 mode) {
|
Result OpenFile(FILE** out, const char* path, u32 mode) {
|
||||||
|
R_DEBUG_START
|
||||||
bool has = false;
|
bool has = false;
|
||||||
|
|
||||||
|
D_LOG("path %s\n", path);
|
||||||
/* Manually check if the file already exists, so it doesn't get created automatically. */
|
/* Manually check if the file already exists, so it doesn't get created automatically. */
|
||||||
R_TRY(HasFile(&has, path));
|
R_TRY(HasFile(&has, path));
|
||||||
if (!has) {
|
if (!has) {
|
||||||
@ -36,19 +38,13 @@ namespace sts::ncm {
|
|||||||
|
|
||||||
const char* fopen_mode = "";
|
const char* fopen_mode = "";
|
||||||
|
|
||||||
if (mode & FS_OPEN_APPEND) {
|
/* 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) {
|
if (mode & FS_OPEN_READ) {
|
||||||
fopen_mode = "r+b";
|
fopen_mode = "r+b";
|
||||||
} else if (mode & FS_OPEN_WRITE) {
|
} else if (mode & FS_OPEN_WRITE) {
|
||||||
fopen_mode = "w+b";
|
fopen_mode = "w+b";
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (mode & FS_OPEN_READ) {
|
|
||||||
fopen_mode = "rb";
|
|
||||||
} else if (mode & FS_OPEN_WRITE) {
|
|
||||||
fopen_mode = "wb";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* f = fopen(path, fopen_mode);
|
FILE* f = fopen(path, fopen_mode);
|
||||||
|
|
||||||
@ -58,12 +54,23 @@ namespace sts::ncm {
|
|||||||
|
|
||||||
*out = f;
|
*out = f;
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
|
R_DEBUG_END
|
||||||
}
|
}
|
||||||
|
|
||||||
Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) {
|
Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) {
|
||||||
R_DEBUG_START
|
R_DEBUG_START
|
||||||
D_LOG("Writing 0x%llx to offset 0x%llx\n", size, offset);
|
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) {
|
if (fseek(f, offset, SEEK_SET) != 0) {
|
||||||
return fsdevGetLastResult();
|
return fsdevGetLastResult();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user