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.
|
||||
const char* LIB_FILE = "oo2core_8_win64.dll";
|
||||
|
||||
typedef decltype(OodleLZ_Decompress)* decompress_func;
|
||||
typedef decltype(OodleCore_Plugins_SetPrintf)* setprintf_func;
|
||||
|
||||
void usage() {
|
||||
std::cerr <<
|
||||
"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";
|
||||
}
|
||||
|
||||
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 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";
|
||||
|
||||
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);
|
||||
if (!in_file) {
|
||||
std::cerr << "ERROR: Failed to open compressed file!\n";
|
||||
|
|
53
oodle2.h
53
oodle2.h
|
@ -7,12 +7,10 @@
|
|||
// the DLL is incompatible when MAJOR is bumped
|
||||
// MINOR is for internal revs and bug fixes that don't affect API compatibility
|
||||
// TODO: Check if the DLL gives a minor version
|
||||
#define OODLE2_VERSION_MAJOR 8
|
||||
#define OODLE2_VERSION_MINOR 14
|
||||
#define OODLE2_VERSION_MAJOR 8
|
||||
#define OODLE2_VERSION_MINOR 14
|
||||
|
||||
// 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"
|
||||
|
||||
|
||||
|
@ -49,7 +47,6 @@ typedef enum OodleLZ_Compressor {
|
|||
} OodleLZ_Compressor;
|
||||
|
||||
|
||||
|
||||
typedef enum OodleLZ_CheckCRC {
|
||||
OodleLZ_CheckCRC_No = 0,
|
||||
OodleLZ_CheckCRC_Yes = 1,
|
||||
|
@ -163,16 +160,16 @@ typedef enum OodleLZ_FuzzSafe {
|
|||
seek chunk boundaries are relative to _dictionaryBase_, not to _rawBuf_.
|
||||
|
||||
*/
|
||||
int OodleLZ_Compress(
|
||||
extern "C" intptr_t __stdcall OodleLZ_Compress(
|
||||
OodleLZ_Compressor compressor,
|
||||
const void* raw_buffer,
|
||||
const void* raw_buffer,
|
||||
size_t raw_len,
|
||||
void* compressed_buffer,
|
||||
void* compressed_buffer,
|
||||
OodleLZ_CompressionLevel level,
|
||||
void* options, // Default: null
|
||||
void* options, // Default: null
|
||||
size_t dictionary_base, // Default: null
|
||||
const void* lrm, // Default: null
|
||||
void* scratch_memory, // Default: null
|
||||
const void* lrm, // Default: null
|
||||
void* scratch_memory, // Default: null
|
||||
size_t scratch_size // Default: null
|
||||
);
|
||||
|
||||
|
@ -250,19 +247,41 @@ int OodleLZ_Compress(
|
|||
Use of OodleLZ_FuzzSafe_No is deprecated.
|
||||
|
||||
*/
|
||||
int OodleLZ_Decompress(
|
||||
extern "C" intptr_t __stdcall OodleLZ_Decompress(
|
||||
const void* compressed_buffer,
|
||||
size_t compressed_length,
|
||||
void* raw_buffer,
|
||||
void* raw_buffer,
|
||||
size_t raw_length,
|
||||
OodleLZ_FuzzSafe fuzz_safe, // Default: OodleLZ_FuzzSafe_Yes
|
||||
OodleLZ_CheckCRC check_crc, // Default: OodleLZ_CheckCRC_No
|
||||
OodleLZ_Verbosity verbosity, // Default: OodleLZ_Verbosity_None
|
||||
void* decBufBase, // Default: null
|
||||
void* decBufBase, // Default: null
|
||||
size_t decBufSize, // Default: 0
|
||||
void* callback, // Default: null
|
||||
void* callback_user_data, // Default: null
|
||||
void* decoder_memory, // Default: null
|
||||
void* callback, // Default: null
|
||||
void* callback_user_data, // Default: null
|
||||
void* decoder_memory, // Default: null
|
||||
size_t decoder_memory_size, // Default: 0
|
||||
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