feat: Implement Oodle logging
The `verbosity` parameter hadn't worked before because there is a callback that needs to be set. Since the tool runs under Wine, the Windows default behaviour applied, which logged to the Event Viewer. To get output to stdout/stderr, a custom logging handler needs to be provided.
This commit is contained in:
parent
a615ae0354
commit
36edf93538
2 changed files with 69 additions and 17 deletions
|
@ -22,6 +22,9 @@ const LPCWSTR LIB_NAME = L"oo2core_8_win64";
|
||||||
// It's not like this is going to change often.
|
// It's not like this is going to change often.
|
||||||
const char* LIB_FILE = "oo2core_8_win64.dll";
|
const char* LIB_FILE = "oo2core_8_win64.dll";
|
||||||
|
|
||||||
|
typedef decltype(OodleLZ_Decompress)* decompress_func;
|
||||||
|
typedef decltype(OodleCore_Plugins_SetPrintf)* setprintf_func;
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
std::cerr <<
|
std::cerr <<
|
||||||
"Usage: oodle-cli [OPTIONS] [--] <in_file> <out_file> <uncompressed_size>\n"
|
"Usage: oodle-cli [OPTIONS] [--] <in_file> <out_file> <uncompressed_size>\n"
|
||||||
|
@ -36,6 +39,27 @@ void usage() {
|
||||||
" DLL_SEARCH_PATH: A color (':') separated list of directories to search for the Oodle library. May be relative to the current working directory.\n";
|
" DLL_SEARCH_PATH: A color (':') separated list of directories to search for the Oodle library. May be relative to the current working directory.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printf_callback(int verboseLevel, const char* file, int line, const char* fmt, ...) {
|
||||||
|
std::cout << "[OODLE] ";
|
||||||
|
|
||||||
|
// For some reason, this doesn't actually map to the config value.
|
||||||
|
switch (verboseLevel) {
|
||||||
|
case 0:
|
||||||
|
std::cout << "EXTRAORDINARILY IMPORTANT: ";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
std::cout << "EXTERMELY IMPORTANT: ";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
std::cout << "VERY IMPORTANT: ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
vfprintf(stdout, fmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int verbosity = 0;
|
int verbosity = 0;
|
||||||
|
@ -124,6 +148,15 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
std::cout << "INFO: Attempting to decompress from '" << in_name << "' to '" << out_name << "' (" << raw_buffer_size << " bytes).\n";
|
std::cout << "INFO: Attempting to decompress from '" << in_name << "' to '" << out_name << "' (" << raw_buffer_size << " bytes).\n";
|
||||||
|
|
||||||
|
if (verbosity > 0) {
|
||||||
|
auto fn = reinterpret_cast<setprintf_func>(GetProcAddress((HMODULE)hDLL, "OodleCore_Plugins_SetPrintf"));
|
||||||
|
if (fn == NULL) {
|
||||||
|
std::cerr << "ERROR: The library is incompatible!\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
reinterpret_cast<void*>(fn(printf_callback));
|
||||||
|
}
|
||||||
|
|
||||||
std::ifstream in_file(in_name, std::ios::binary | std::ios::ate);
|
std::ifstream in_file(in_name, std::ios::binary | std::ios::ate);
|
||||||
if (!in_file) {
|
if (!in_file) {
|
||||||
std::cerr << "ERROR: Failed to open compressed file!\n";
|
std::cerr << "ERROR: Failed to open compressed file!\n";
|
||||||
|
|
29
oodle2.h
29
oodle2.h
|
@ -11,8 +11,6 @@
|
||||||
#define OODLE2_VERSION_MINOR 14
|
#define OODLE2_VERSION_MINOR 14
|
||||||
|
|
||||||
// OodleVersion string is 1 . MAJOR . MINOR
|
// OodleVersion string is 1 . MAJOR . MINOR
|
||||||
// don't make it from macros cuz the doc tool has to parse the string literal
|
|
||||||
|
|
||||||
#define OodleVersion "2.8.14"
|
#define OodleVersion "2.8.14"
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +47,6 @@ typedef enum OodleLZ_Compressor {
|
||||||
} OodleLZ_Compressor;
|
} OodleLZ_Compressor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum OodleLZ_CheckCRC {
|
typedef enum OodleLZ_CheckCRC {
|
||||||
OodleLZ_CheckCRC_No = 0,
|
OodleLZ_CheckCRC_No = 0,
|
||||||
OodleLZ_CheckCRC_Yes = 1,
|
OodleLZ_CheckCRC_Yes = 1,
|
||||||
|
@ -163,7 +160,7 @@ typedef enum OodleLZ_FuzzSafe {
|
||||||
seek chunk boundaries are relative to _dictionaryBase_, not to _rawBuf_.
|
seek chunk boundaries are relative to _dictionaryBase_, not to _rawBuf_.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
int OodleLZ_Compress(
|
extern "C" intptr_t __stdcall OodleLZ_Compress(
|
||||||
OodleLZ_Compressor compressor,
|
OodleLZ_Compressor compressor,
|
||||||
const void* raw_buffer,
|
const void* raw_buffer,
|
||||||
size_t raw_len,
|
size_t raw_len,
|
||||||
|
@ -250,7 +247,7 @@ int OodleLZ_Compress(
|
||||||
Use of OodleLZ_FuzzSafe_No is deprecated.
|
Use of OodleLZ_FuzzSafe_No is deprecated.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
int OodleLZ_Decompress(
|
extern "C" intptr_t __stdcall OodleLZ_Decompress(
|
||||||
const void* compressed_buffer,
|
const void* compressed_buffer,
|
||||||
size_t compressed_length,
|
size_t compressed_length,
|
||||||
void* raw_buffer,
|
void* raw_buffer,
|
||||||
|
@ -266,3 +263,25 @@ int OodleLZ_Decompress(
|
||||||
size_t decoder_memory_size, // Default: 0
|
size_t decoder_memory_size, // Default: 0
|
||||||
OodleLZ_Decode_ThreadPhase thread_phase // Default: OodleLZ_Decode_Unthreaded
|
OodleLZ_Decode_ThreadPhase thread_phase // Default: OodleLZ_Decode_Unthreaded
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/* Function pointer to Oodle Core printf
|
||||||
|
$:verboseLevel verbosity of the message; 0-2 ; lower = more important
|
||||||
|
$:file C file that sent the message
|
||||||
|
$:line C line that sent the message
|
||||||
|
$:fmt vararg printf format string
|
||||||
|
The logging function installed here must parse varargs like printf.
|
||||||
|
_verboseLevel_ may be used to omit verbose messages.
|
||||||
|
*/
|
||||||
|
extern "C" typedef void(__stdcall t_fp_OodleCore_Plugin_Printf)(int verboseLevel, const char* file, int line, const char* fmt, ...);
|
||||||
|
|
||||||
|
/* Install the callback used by Oodle Core for logging
|
||||||
|
$:fp_rrRawPrintf function pointer to your log function; may be NULL to disable all logging
|
||||||
|
$:return returns the previous function pointer
|
||||||
|
Use this function to install your own printf for Oodle Core.
|
||||||
|
The default implementation in debug builds, if you install nothing, uses the C stdio printf for logging.
|
||||||
|
On Microsoft platforms, it uses OutputDebugString and not stdio.
|
||||||
|
To disable all logging, call OodleCore_Plugins_SetPrintf(NULL)
|
||||||
|
WARNING : this function is NOT thread safe! It should be done only once and done in a place where the caller can guarantee thread safety.
|
||||||
|
In the debug build of Oodle, you can install OodleCore_Plugin_Printf_Verbose to get more verbose logging
|
||||||
|
*/
|
||||||
|
t_fp_OodleCore_Plugin_Printf* __stdcall OodleCore_Plugins_SetPrintf(t_fp_OodleCore_Plugin_Printf* fp_rrRawPrintf);
|
Reference in a new issue