77#include "misc/error.h"
88#include "misc/globals.h"
99
10+ #if defined(WIN32 )
11+ #define NOMINMAX
12+ #include <Windows.h>
13+ #include <KnownFolders.h>
14+ #include <Shlobj.h>
15+ #endif
16+
1017static char cached_path_to_config_dir [2048 ] = {0 };
1118static char cached_path_to_log_file [2048 ] = {0 };
1219
@@ -15,26 +22,26 @@ paths_get_config_dir(void) {
1522 if (cached_path_to_config_dir [0 ] == 0 ) {
1623#if defined(WIN32 )
1724 PWSTR path_tmp = NULL ;
18- const HRESULT result = SHGetKnownFolderPath (FOLDERID_LocalAppData , 0 , NULL , & path_tmp );
25+ const HRESULT result = SHGetKnownFolderPath (& FOLDERID_LocalAppData , 0 , NULL , & path_tmp );
1926 if (result != S_OK ) {
2027 CoTaskMemFree (path_tmp );
2128 show_error_and_abort ("failed to query config dir path" );
2229 }
2330
2431 // Copy path and replace slashes.
2532 char path_buff [256 ] = {0 };
26- const unsigned long path_len = strlen (path_tmp );
33+ const size_t path_len = wcslen (path_tmp );
2734 if (path_len > 256 ) {
2835 show_error_and_abort ("path to AppData folder is too long" );
2936 }
30- for (unsigned long i = 0 ; i < path_len ; i ++ ) {
37+ for (size_t i = 0 ; i < path_len ; i ++ ) {
3138 if (path_tmp [i ] == '\\' ) {
3239 path_buff [i ] = '/' ;
3340 } else {
34- path_buff [i ] = path_tmp [i ];
41+ path_buff [i ] = ( char ) path_tmp [i ];
3542 }
3643 }
37- CoTaskMemFree (pPathTmp );
44+ CoTaskMemFree (path_tmp );
3845
3946 sprintf (cached_path_to_config_dir , "%s/tiny_engine/%s/config/" , & path_buff [0 ],
4047 globals_get_app_name ());
@@ -65,26 +72,26 @@ paths_get_log_file(void) {
6572 if (cached_path_to_log_file [0 ] == 0 ) {
6673#if defined(WIN32 )
6774 PWSTR path_tmp = NULL ;
68- const HRESULT result = SHGetKnownFolderPath (FOLDERID_LocalAppData , 0 , NULL , & path_tmp );
75+ const HRESULT result = SHGetKnownFolderPath (& FOLDERID_LocalAppData , 0 , NULL , & path_tmp );
6976 if (result != S_OK ) {
7077 CoTaskMemFree (path_tmp );
7178 show_error_and_abort ("failed to query config dir path" );
7279 }
7380
7481 // Copy path and replace slashes.
7582 char path_buff [256 ] = {0 };
76- const unsigned long path_len = strlen (path_tmp );
83+ const size_t path_len = wcslen (path_tmp );
7784 if (path_len > 256 ) {
7885 show_error_and_abort ("path to AppData folder is too long" );
7986 }
80- for (unsigned long i = 0 ; i < path_len ; i ++ ) {
87+ for (size_t i = 0 ; i < path_len ; i ++ ) {
8188 if (path_tmp [i ] == '\\' ) {
8289 path_buff [i ] = '/' ;
8390 } else {
84- path_buff [i ] = path_tmp [i ];
91+ path_buff [i ] = ( char ) path_tmp [i ];
8592 }
8693 }
87- CoTaskMemFree (pPathTmp );
94+ CoTaskMemFree (path_tmp );
8895
8996 sprintf (cached_path_to_log_file , "%s/tiny_engine/%s/log.txt" , & path_buff [0 ], globals_get_app_name ());
9097#elif __linux__
@@ -111,7 +118,7 @@ paths_get_log_file(void) {
111118
112119char *
113120paths_prepend_res_to_path (const char * relative_path ) {
114- const unsigned long len = strlen (relative_path );
121+ const size_t len = strlen (relative_path );
115122
116123 char * new_path = malloc (sizeof (char ) * (len + 4 + 1 ));
117124
0 commit comments