diff options
author | Jesse Talavera-Greenberg <jesse@jesse.tg> | 2023-08-18 16:50:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-18 22:50:57 +0200 |
commit | ee5567708630441d8d3210e81d6e03d028fb7bbd (patch) | |
tree | ab92234123b16ec414d6c0da9bb0716c1b798229 /src/ARCodeFile.cpp | |
parent | f454eba3c3243b095f0e6b9ddde3e68b095c5d8d (diff) |
Assorted portability enhancements (#1800)
* Introduce some Platform calls for managing dynamic libraries
* Add Platform::WriteFATSectors
* Introduce some Platform calls for managing dynamic libraries
* Add Platform::WriteFATSectors
* Change includes of "../types.h" to "types.h"
- Makes it easier to directly include these headers in downstream projects
* Change an include of "../Wifi.h" to "Wifi.h"
* Allow CommonFuncs.cpp to compile on Android
* Tidy up some logging calls
- Use Platform::Log in LAN_Socket.cpp
- Soften some warnings to Debug logs (since they don't necessarily represent problems)
* Add Platform::EnterGBAMode
- Gracefully stop the emulator if trying to enter GBA mode
* Soften some logs that most players won't care about
* Soften some more logs
* Introduce Platform wrappers for file operations
* Fix pointer spacing
* Fix more style nits
* Log the errno when ftruncate fails
* Fix FileSeek offset argument
- With an s32 offset, we couldn't access files larger than 2GB
* Revise Platform::StopEmu to address feedback
- Remove Platform::EnterGBAMode in favor of adding a reason to Platform::StopEmu
- Also rename Platform::StopEmu to Platform::SignalStop
- Add an optional argument to NDS::Stop
- Use the new argument everywhere that the console stops itself
* Rename FileGetString to FileReadLine
- It conveys the meaning better
* Rename FileSeekOrigin::Set to Start
- It conveys the meaning better
* Change definition of FileGetString to FileReadLine
- Oops, almost forgot it
* Rename FlushFile to FileFlush
- To remain consistent with the other File functions
* Add a FileType usage
* Fix line break in FileSeekOrigin
* Document Platform::DeInit
* Clarify that StopReason::Unknown doesn't always mean an error
* Move and document FileType::HostFile
* Remove Platform::OpenDataFile
- Nothing currently uses it
* Refactor Platform::OpenFile and Platform::OpenLocalFile to accept a FileMode enum instead of a string
- The enum is converted to fopen flags under the hood
- The file type is used to decide whether to add the "b" flag
- Some helper functions are exposed for the benefit of consistent behavior among frontends
- Equivalent behavior is maintained
* Fix a tab that should be spaces
* Use Windows' 64-bit implementations of fseek/ftell
* Move Platform::IsBinaryFile to Platform.cpp
- It could vary by frontend
* Remove an unused FileType
* Rename an enum constant
* Document various Platform items
* Use Platform::DynamicLibrary to load libandroid
- And clean it up at the end
* Fix a typo
* Pass the correct filetype to FATStorage
- Since it can be used for DSI NAND images or for SD cards
* Remove Platform::FileType
Diffstat (limited to 'src/ARCodeFile.cpp')
-rw-r--r-- | src/ARCodeFile.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/ARCodeFile.cpp b/src/ARCodeFile.cpp index 45583ca..79c582d 100644 --- a/src/ARCodeFile.cpp +++ b/src/ARCodeFile.cpp @@ -21,8 +21,7 @@ #include "ARCodeFile.h" #include "Platform.h" -using Platform::Log; -using Platform::LogLevel; +using namespace Platform; // TODO: import codes from other sources (usrcheat.dat, ...) // TODO: more user-friendly error reporting @@ -47,7 +46,7 @@ ARCodeFile::~ARCodeFile() bool ARCodeFile::Load() { - FILE* f = Platform::OpenFile(Filename, "r"); + FileHandle* f = OpenFile(Filename, FileMode::ReadText); if (!f) return true; Categories.clear(); @@ -59,9 +58,9 @@ bool ARCodeFile::Load() ARCode curcode; char linebuf[1024]; - while (!feof(f)) + while (!IsEndOfFile(f)) { - if (fgets(linebuf, 1024, f) == nullptr) + if (!FileReadLine(linebuf, 1024, f)) break; linebuf[1023] = '\0'; @@ -82,7 +81,7 @@ bool ARCodeFile::Load() if (ret < 1) { Log(LogLevel::Error, "AR: malformed CAT line: %s\n", start); - fclose(f); + CloseFile(f); return false; } @@ -105,14 +104,14 @@ bool ARCodeFile::Load() if (ret < 2) { Log(LogLevel::Error, "AR: malformed CODE line: %s\n", start); - fclose(f); + CloseFile(f); return false; } if (!isincat) { Log(LogLevel::Error, "AR: encountered CODE line with no category started\n"); - fclose(f); + CloseFile(f); return false; } @@ -131,21 +130,21 @@ bool ARCodeFile::Load() if (ret < 2) { Log(LogLevel::Error, "AR: malformed data line: %s\n", start); - fclose(f); + CloseFile(f); return false; } if (!isincode) { Log(LogLevel::Error, "AR: encountered data line with no code started\n"); - fclose(f); + CloseFile(f); return false; } if (curcode.CodeLen >= 2*64) { Log(LogLevel::Error, "AR: code too long!\n"); - fclose(f); + CloseFile(f); return false; } @@ -159,36 +158,36 @@ bool ARCodeFile::Load() if (isincode) curcat.Codes.push_back(curcode); if (isincat) Categories.push_back(curcat); - fclose(f); + CloseFile(f); return true; } bool ARCodeFile::Save() { - FILE* f = Platform::OpenFile(Filename, "w"); + FileHandle* f = Platform::OpenFile(Filename, FileMode::WriteText); if (!f) return false; for (ARCodeCatList::iterator it = Categories.begin(); it != Categories.end(); it++) { ARCodeCat& cat = *it; - if (it != Categories.begin()) fprintf(f, "\r\n"); - fprintf(f, "CAT %s\r\n\r\n", cat.Name.c_str()); + if (it != Categories.begin()) FileWriteFormatted(f, "\r\n"); + FileWriteFormatted(f, "CAT %s\r\n\r\n", cat.Name.c_str()); for (ARCodeList::iterator jt = cat.Codes.begin(); jt != cat.Codes.end(); jt++) { ARCode& code = *jt; - fprintf(f, "CODE %d %s\r\n", code.Enabled, code.Name.c_str()); + FileWriteFormatted(f, "CODE %d %s\r\n", code.Enabled, code.Name.c_str()); for (u32 i = 0; i < code.CodeLen; i+=2) { - fprintf(f, "%08X %08X\r\n", code.Code[i], code.Code[i+1]); + FileWriteFormatted(f, "%08X %08X\r\n", code.Code[i], code.Code[i + 1]); } - fprintf(f, "\r\n"); + FileWriteFormatted(f, "\r\n"); } } - fclose(f); + CloseFile(f); return true; } |