From 475f42ac11362538b25f7f66509e530991db10da Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 26 Aug 2021 18:43:36 +0200 Subject: [PATCH] winamp: print logs --- winamp/in_config.c | 109 ++++++++++++++++++++++++++++++++++++++++++ winamp/in_vgmstream.c | 4 ++ winamp/in_vgmstream.h | 10 ++++ winamp/resource.h | 1 + winamp/resource.rc | 12 +++-- 5 files changed, 131 insertions(+), 5 deletions(-) diff --git a/winamp/in_config.c b/winamp/in_config.c index b7afe594..720aa20a 100644 --- a/winamp/in_config.c +++ b/winamp/in_config.c @@ -347,6 +347,36 @@ INT_PTR CALLBACK configDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara break; } + case IDC_LOG_BUTTON: { /* shows log */ + TCHAR wbuf[257*32]; + char buf[257*32]; + size_t buf_size = 257*32; + int i, max = 0; + const char** lines = logger_get_lines(&max); + + /* could use some nice scrollable text but I don't know arcane Windows crap */ + if (lines == NULL) { + snprintf(buf, 257, "%s\n", "couldn't read log"); + } + else if (max == 0) { + snprintf(buf, 257, "%s\n", "(empty)"); + } + else { + //todo improve + char* tmp = buf; + for (i = 0; i < max; i++) { + int done = snprintf(tmp, 256, "%s", lines[i]); + if (done < 0 || done >= 256) + break; + tmp += (done); // + 1 + } + } + + cfg_char_to_wchar(wbuf, buf_size, buf); + MessageBox(hDlg, buf, TEXT("vgmstream log"), MB_OK); + break; + } + default: return FALSE; } @@ -370,3 +400,82 @@ INT_PTR CALLBACK configDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara return TRUE; } + + +/* ************************************* */ +/* IN_LOG */ +/* ************************************* */ + +/* could just write to file but to avoid leaving temp crap just log to memory and print what when requested */ + +winamp_log_t* walog; +#define WALOG_MAX_LINES 32 +#define WALOG_MAX_CHARS 256 + +struct winamp_log_t { + char data[WALOG_MAX_LINES * WALOG_MAX_CHARS]; + int logged; + const char* lines[WALOG_MAX_LINES]; +} ; + +void logger_init() { + walog = malloc(sizeof(winamp_log_t)); + if (!walog) return; + + walog->logged = 0; +} + +void logger_free() { + free(walog); + walog = NULL; +} + +/* logs to data as a sort of circular buffer. example if max_lines is 6: + * - log 0 = "msg1" + * ... + * - log 5 = "msg5" > limit reached, next will overwrite 0 + * - log 0 = "msg6" (max 6 logs, but can only write las 6) + * - when requested lines should go from current to: 1,2,3,4,5,0 +*/ +void logger_callback(int level, const char* str) { + char* buf; + int pos; + if (!walog) + return; + + pos = (walog->logged % WALOG_MAX_LINES) * WALOG_MAX_CHARS; + buf = &walog->data[pos]; + snprintf(buf, WALOG_MAX_CHARS, "%s", str); + + walog->logged++; + + /* ??? */ + if (walog->logged >= 0x7FFFFFFF) + walog->logged = 0; +} + +const char** logger_get_lines(int* p_max) { + int i, from, max; + + if (!walog) { + *p_max = 0; + return NULL; + } + + if (walog->logged > WALOG_MAX_LINES) { + from = (walog->logged % WALOG_MAX_LINES); + max = WALOG_MAX_LINES; + } + else { + from = 0; + max = walog->logged; + } + + for (i = 0; i < max; i++) { + int pos = ((from + i) % WALOG_MAX_LINES) * WALOG_MAX_CHARS; + walog->lines[i] = &walog->data[pos]; + } + + *p_max = max; + return walog->lines; +} diff --git a/winamp/in_vgmstream.c b/winamp/in_vgmstream.c index 385215bf..be082e91 100644 --- a/winamp/in_vgmstream.c +++ b/winamp/in_vgmstream.c @@ -344,6 +344,9 @@ void winamp_Init() { settings.is_xmplay = is_xmplay(); + logger_init(); + vgmstream_set_log_callback(VGM_LOG_LEVEL_ALL, logger_callback); + /* get ini config */ load_defaults(&defaults); load_config(&input_module, &settings, &defaults); @@ -359,6 +362,7 @@ void winamp_Init() { /* called at program quit */ void winamp_Quit() { + logger_free(); } /* called before extension checks, to allow detection of mms://, etc */ diff --git a/winamp/in_vgmstream.h b/winamp/in_vgmstream.h index c9783c2c..29aede48 100644 --- a/winamp/in_vgmstream.h +++ b/winamp/in_vgmstream.h @@ -74,6 +74,16 @@ void load_config(In_Module* input_module, winamp_settings_t* settings, winamp_se INT_PTR CALLBACK configDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +/* logger */ +typedef struct winamp_log_t winamp_log_t; +void logger_init(); +void logger_free(); +void logger_callback(int level, const char* str); +const char** logger_get_lines(int* p_max); + +extern winamp_log_t* walog; + + /* ************************************* */ /* IN_UNICODE */ /* ************************************* */ diff --git a/winamp/resource.h b/winamp/resource.h index f9cdea1e..59c4f7a0 100644 --- a/winamp/resource.h +++ b/winamp/resource.h @@ -16,3 +16,4 @@ #define IDC_EXTS_UNKNOWN_ON 1015 #define IDC_EXTS_COMMON_ON 1016 #define IDC_FORCE_TITLE 1017 +#define IDC_LOG_BUTTON 1018 diff --git a/winamp/resource.rc b/winamp/resource.rc index edecdff5..c21a2dfa 100644 --- a/winamp/resource.rc +++ b/winamp/resource.rc @@ -4,7 +4,7 @@ #define IDC_STATIC -1 //elements: text, id, x, y, width, height [, style [, extended-style]] -IDD_CONFIG DIALOGEX 0, 0, 187, 196 +IDD_CONFIG DIALOGEX 0, 0, 188, 220 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "in_vgmstream configuration" FONT 8, "MS Sans Serif", 0, 0, 0x0 @@ -44,12 +44,14 @@ BEGIN LTEXT "Downmix",IDC_STATIC,7,115,48,12 EDITTEXT IDC_DOWNMIX_CHANNELS,52,112,37,14,ES_AUTOHSCROLL - CONTROL "Disable tagfile",IDC_TAGFILE_DISABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,131,87,10 + CONTROL "Disable tagfile",IDC_TAGFILE_DISABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,132,87,10 - CONTROL "Force internal title",IDC_FORCE_TITLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,147,87,10 + CONTROL "Force internal title",IDC_FORCE_TITLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,148,87,10 - CONTROL "Enable unknown exts",IDC_EXTS_UNKNOWN_ON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,163,87,10 + CONTROL "Enable unknown exts",IDC_EXTS_UNKNOWN_ON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,164,87,10 - CONTROL "Enable common exts",IDC_EXTS_COMMON_ON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,179,87,10 + CONTROL "Enable common exts",IDC_EXTS_COMMON_ON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,180,87,10 + + PUSHBUTTON "Open Log",IDC_LOG_BUTTON,7,196,50,14 END