Skip to content

Commit

Permalink
need to hack stderr for non-console build
Browse files Browse the repository at this point in the history
  • Loading branch information
Morilli committed Jul 31, 2022
1 parent 417f09e commit 15d8172
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bnk-extract/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ typedef struct {
#else
#define dprintf(...)
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
extern FILE* consoleless_stderr;
#define eprintf(...) fprintf(consoleless_stderr ? consoleless_stderr : stderr, __VA_ARGS__)
#define v_printf(level, ...) if (VERBOSE >= level) printf(__VA_ARGS__)

#ifdef __cplusplus
Expand Down
6 changes: 6 additions & 0 deletions gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "treeview_extension.h"
#include "bnk-extract/api.h"

FILE* consoleless_stderr;

// global window variables
static HINSTANCE me;
static HWND mainWindow;
Expand Down Expand Up @@ -250,6 +252,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
// redirect stderr to a temporary file, in order to be able to read it back and display later
FILE* temp_file = tmpfile();
dup2(fileno(temp_file), STDERR_FILENO);
if (fileno(stderr) == -2) { // no console, but we still want to capture stderr
consoleless_stderr = temp_file;
}
WemInformation* wemInformation = bnk_extract(onlyAudioGiven ? 3 : 7, bnk_extract_args);
free(binPath); free(audioPath); free(eventsPath);
if (wemInformation) {
Expand All @@ -268,6 +273,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
MessageBox(mainWindow, stderr_buffer, "Failed to read audio files", MB_ICONERROR);
}
fclose(temp_file);
consoleless_stderr = NULL;
// restore stderr
dup2(duped_stderr, STDERR_FILENO);
} else if ((HWND) lParam == XButton) {
Expand Down

0 comments on commit 15d8172

Please sign in to comment.