diff --git a/include/util.h b/include/util.h index 24eb184..ac5e3ed 100644 --- a/include/util.h +++ b/include/util.h @@ -1,6 +1,8 @@ #ifndef __UTIL_H__ #define __UTIL_H__ +void remove_name_in_path(char *szPath); void replace_multiple_space_with_one(char *s, size_t len); +char *version_as_string(char *, long v, int n); #endif /* __UTIL_H__ */ \ No newline at end of file diff --git a/src/cdll.c b/src/cdll.c index 0d346cb..47288ec 100644 --- a/src/cdll.c +++ b/src/cdll.c @@ -1,6 +1,7 @@ #include #include #include "cdll.h" +#include "util.h" /*******************************************************************************/ /** GET VOICEMEETER DIRECTORY **/ @@ -12,18 +13,6 @@ #define KEY_WOW64_32KEY 0x0200 #endif -void remove_name_in_path(char *szPath) -{ - char *p = szPath; - - while (*p++) - ; - while (p > szPath && *p != '\\') - p--; - if (*p == '\\') - *p = '\0'; -} - bool __cdecl registry_get_voicemeeter_folder(char *szDir) { char szKey[256]; diff --git a/src/util.c b/src/util.c index 52a7d4d..e6999f6 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,18 @@ #include +#include +#include "util.h" + +void remove_name_in_path(char *szPath) +{ + char *p = szPath; + + while (*p++) + ; + while (p > szPath && *p != '\\') + p--; + if (*p == '\\') + *p = '\0'; +} void replace_multiple_space_with_one(char *s, size_t len) { @@ -32,4 +46,14 @@ void replace_multiple_space_with_one(char *s, size_t len) } } s[j] = '\0'; +} + +char *version_as_string(char *s, long v, int n) +{ + long v1 = (v & 0xFF000000) >> 24, + v2 = (v & 0x00FF0000) >> 16, + v3 = (v & 0x0000FF00) >> 8, + v4 = (v & 0x000000FF); + snprintf(s, n, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4); + return s; } \ No newline at end of file diff --git a/src/vmr.c b/src/vmr.c index 3ba426b..771ef32 100644 --- a/src/vmr.c +++ b/src/vmr.c @@ -3,6 +3,9 @@ #include #include "vmr.h" #include "log.h" +#include "util.h" + +#define VERSION_STR_LEN 128 long login(T_VBVMR_INTERFACE *vmr, int kind) { @@ -43,13 +46,10 @@ long login(T_VBVMR_INTERFACE *vmr, int kind) if (rep == 0) { version(vmr, &v); - long v1 = (v & 0xFF000000) >> 24, - v2 = (v & 0x00FF0000) >> 16, - v3 = (v & 0x0000FF00) >> 8, - v4 = (v & 0x000000FF); - char version_s[128]; - sprintf(version_s, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4); - log_info("Successfully logged into the Voicemeeter API v%s", version_s); + char version_s[VERSION_STR_LEN]; + log_info( + "Successfully logged into the Voicemeeter API v%s", + version_as_string(version_s, v, VERSION_STR_LEN)); clear_dirty(vmr); } return rep;