mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Improved FileSetData() function
This commit is contained in:
parent
fc35bed752
commit
3a59f37fc9
@ -195,13 +195,13 @@ bool GetTempFileName(char* path) {
|
||||
return (cc - tempname < 8) ? true : false;
|
||||
}
|
||||
|
||||
bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset) {
|
||||
bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset, bool create) {
|
||||
if (!CheckWritePermissions(path)) return false;
|
||||
if (PathToNumFS(path) >= 0) {
|
||||
UINT bytes_written = 0;
|
||||
FIL file;
|
||||
if (!CheckWritePermissions(path)) return false;
|
||||
if (f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS) != FR_OK)
|
||||
if (f_open(&file, path, FA_WRITE | (create ? FA_CREATE_ALWAYS : FA_OPEN_ALWAYS)) != FR_OK)
|
||||
return false;
|
||||
f_lseek(&file, foffset);
|
||||
f_write(&file, data, size, &bytes_written);
|
||||
@ -738,7 +738,7 @@ void CreateScreenshot() {
|
||||
for (u32 x = 0; x < 320; x++)
|
||||
for (u32 y = 0; y < 240; y++)
|
||||
memcpy(buffer + (y*400 + x + 40) * 3, BOT_SCREEN + (x*240 + y) * 3, 3);
|
||||
FileSetData(filename, MAIN_BUFFER, 54 + (400 * 240 * 3 * 2), 0);
|
||||
FileSetData(filename, MAIN_BUFFER, 54 + (400 * 240 * 3 * 2), 0, true);
|
||||
}
|
||||
|
||||
void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
|
||||
|
@ -48,7 +48,7 @@ bool SetWritePermissions(u32 perm, bool add_perm);
|
||||
u32 GetWritePermissions();
|
||||
|
||||
/** Create / open file and write the provided data to it **/
|
||||
bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset);
|
||||
bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset, bool create);
|
||||
|
||||
/** Read data from file@offset **/
|
||||
size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset);
|
||||
|
@ -325,7 +325,7 @@ u32 HexViewer(const char* path) {
|
||||
u32 diffs = 0;
|
||||
for (u32 i = 0; i < edit_bsize; i++) if (edit_buffer[i] != edit_buffer_cpy[i]) diffs++;
|
||||
if (diffs && ShowPrompt(true, "You made edits in %i place(s).\nWrite changes to file?", diffs))
|
||||
if (!FileSetData(path, edit_buffer, min(edit_bsize, (fsize - edit_start)), edit_start))
|
||||
if (!FileSetData(path, edit_buffer, min(edit_bsize, (fsize - edit_start)), edit_start, false))
|
||||
ShowPrompt(false, "Failed writing to file!");
|
||||
data = WORK_BUFFER;
|
||||
last_offset = (u32) -1; // force reload from file
|
||||
@ -479,7 +479,7 @@ u32 GodMode() {
|
||||
(memcmp(sha256, sha256_prev, 32) == 0) ? "\n \nIdentical with previous file:\n" : "",
|
||||
(memcmp(sha256, sha256_prev, 32) == 0) ? pathstr_prev : "",
|
||||
(write_sha) ? "\n \nWrite .SHA file?" : "") && !have_sha) {
|
||||
FileSetData(sha_path, sha256, 32, 0);
|
||||
FileSetData(sha_path, sha256, 32, 0, true);
|
||||
GetDirContents(current_dir, current_path);
|
||||
}
|
||||
strncpy(pathstr_prev, pathstr, 32 + 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user