mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-24 21:55:57 +00:00
Write the log of a game run to logs\totk.log next to totk.exe when stderr is not a file
A player who starts totk.exe from Explorer or a shortcut had no log to attach to a report: the log went only to stderr. A game run whose stderr is not a file (a console or a pipe) now also writes logs\totk.log, keeps the four earlier runs as totk.1.log to totk.4.log, and stops the file at 64 MiB. Runs whose stderr is a file (run_game.py, 2> file) and the tool modes write no extra file. Lines from before the file opens (mem_init comes first so the CRT heap stays out of the guest address space) wait in a static buffer. Crash reports, fatal errors, IPC and SVC diagnostics, guest debug output and the boot: lines now go through rt_logf / rt_log_raw, so they reach the file too. Open log folder in the menu opens the folder of the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f4619f7b45
commit
c7b290f2b0
10 files changed
+146
-32
No files matched your search
@@ -70,6 +70,11 @@ void plat_file_delete(const char *path);
|
||||
int plat_file_truncate(const char *path, uint64_t size); // 1 on success
|
||||
int64_t plat_file_size(const char *path); // bytes of a file, -1 when missing or unreadable
|
||||
int plat_file_set_readonly(const char *path, int on); // sets or clears the read-only attribute; 1 on success
|
||||
// A file that only grows and other processes may read meanwhile: each write lands whole at its end, from any thread,
|
||||
// and reaches the file even if the process dies right after (no user-space buffer, no flush to the disk).
|
||||
typedef struct PlatAppend PlatAppend;
|
||||
PlatAppend *plat_append_open(const char *path); // creates or truncates path; NULL on failure
|
||||
int plat_append_write(PlatAppend *f, const void *data, size_t n); // 1 when all n bytes landed
|
||||
// Calls cb(name, ctx) for each file in dir whose name ends in ext (".in"); name has no directory part. cb returns 0 to
|
||||
// stop. Returns 0 when dir cannot be listed.
|
||||
int plat_file_list(const char *dir, const char *ext, int (*cb)(const char *name, void *ctx), void *ctx);
|
||||
|
||||
@@ -199,6 +199,21 @@ int plat_file_write(const char *path, const void *data, size_t n) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
PlatAppend *plat_append_open(const char *path) {
|
||||
wchar_t w[WPATH];
|
||||
if (!widen(path, w, WPATH)) return NULL;
|
||||
HANDLE h = CreateFileW(w, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
return h == INVALID_HANDLE_VALUE ? NULL : (PlatAppend *)h;
|
||||
}
|
||||
|
||||
int plat_append_write(PlatAppend *f, const void *data, size_t n) {
|
||||
// Offset and OffsetHigh all ones: WriteFile appends at the end of the file, atomically against other writers.
|
||||
OVERLAPPED o = {.Offset = 0xffffffff, .OffsetHigh = 0xffffffff};
|
||||
DWORD put = 0;
|
||||
return WriteFile((HANDLE)f, data, (DWORD)n, &put, &o) && put == n;
|
||||
}
|
||||
|
||||
int plat_file_replace(const char *from, const char *to) {
|
||||
wchar_t a[WPATH], b[WPATH];
|
||||
if (!widen(from, a, WPATH) || !widen(to, b, WPATH)) return 0;
|
||||
|
||||
Reference in new issue
Block a user