From 5d2c2b27a6323e2666378b986129b2a7c2c39e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 6 Feb 2022 16:04:24 +0100 Subject: New upstream version 5.2.2GA --- app/wlib/mswlib/mswpref.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'app/wlib/mswlib/mswpref.c') diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c index 201171a..55fedb4 100644 --- a/app/wlib/mswlib/mswpref.c +++ b/app/wlib/mswlib/mswpref.c @@ -5,7 +5,6 @@ #include #include #include -#include "misc.h" #include "mswint.h" #include #include @@ -40,13 +39,15 @@ const char * wGetAppLibDir( void ) *cp = '\0'; #ifdef XTRKCAD_CMAKE_BUILD - strcpy(appLibDirName, module_name); - strcat(appLibDirName, "\\..\\share\\xtrkcad"); + strncpy(appLibDirName, module_name, sizeof(appLibDirName)); + size_t len = sizeof(appLibDirName)-strlen(appLibDirName)-1; + strncat(appLibDirName, "\\..\\share\\xtrkcad", len); _fullpath( appLibDirName, appLibDirName, MAX_PATH ); return appLibDirName; #endif - strcpy(appLibDirName, module_name); + strncpy(appLibDirName, module_name, sizeof(appLibDirName)); + appLibDirName[sizeof(appLibDirName)-1] = '\0'; return appLibDirName; } @@ -73,11 +74,12 @@ const char * wGetAppWorkDir( void ) return appWorkDirName; } wGetAppLibDir(); - sprintf( mswTmpBuff, "%s\\xtrkcad0.ini", appLibDirName ); + snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName ); rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, sizeof appWorkDirName, mswTmpBuff ); if ( rc!=0 ) { if ( stricmp( appWorkDirName, "installdir" ) == 0 ) { - strcpy( appWorkDirName, appLibDirName ); + strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) ); + appWorkDirName[sizeof(appWorkDirName)-1] = '\0'; } else { cp = &appWorkDirName[strlen(appWorkDirName)-1]; while (cp>appWorkDirName && *cp == '\\') *cp-- = 0; @@ -89,7 +91,7 @@ const char * wGetAppWorkDir( void ) wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL ); wExit(0); } else { - sprintf( appWorkDirName, "%s\\%s", mswTmpBuff, "XTrackCad" ); + snprintf( appWorkDirName, sizeof(appWorkDirName), "%s\\%s", mswTmpBuff, "XTrackCad" ); if( !PathIsDirectory( appWorkDirName )) { if( !CreateDirectory( appWorkDirName, NULL )) { wNoticeEx( NT_ERROR, "Cannot create user's profile directory", "Exit", NULL ); @@ -125,7 +127,8 @@ typedef struct { BOOL_T dirty; char * val; } prefs_t; -dynArr_t prefs_da; + +static dynArr_t prefs_da; #define prefs(N) DYNARR_N(prefs_t,prefs_da,N) void wPrefSetString( const char * section, const char * name, const char * sval ) @@ -149,6 +152,17 @@ void wPrefSetString( const char * section, const char * name, const char * sval p->val = mswStrdup(sval); } +void wPrefsLoad(char * name) { + prefs_t *p; + for (int i= 0; isection, p->name, "", mswTmpBuff, sizeof mswTmpBuff, name ); + if (rc==0) + continue; + p->val = mswStrdup(mswTmpBuff); + } +} char * wPrefGetStringBasic( const char * section, const char * name ) { @@ -160,6 +174,7 @@ char * wPrefGetStringBasic( const char * section, const char * name ) return p->val; } } + rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff, mswProfileFile ); if (rc==0) return NULL; @@ -177,7 +192,7 @@ void wPrefSetInteger( const char * section, const char * name, long lval ) { char tmp[20]; - sprintf( tmp, "%ld", lval ); + snprintf( tmp, sizeof(tmp), "%ld", lval ); wPrefSetString( section, name, tmp ); } @@ -214,7 +229,7 @@ void wPrefSetFloat( { char tmp[20]; - sprintf(tmp, "%0.6f", lval ); + snprintf(tmp, sizeof(tmp), "%0.6f", lval ); wPrefSetString( section, name, tmp ); } @@ -244,15 +259,20 @@ wBool_t wPrefGetFloatBasic( } -void wPrefFlush( void ) +void wPrefFlush( char * name ) { prefs_t * p; for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if ( p->dirty ) + if (name && name[0]) + WritePrivateProfileString( p->section, p->name, p->val, name ); + else if (p->dirty) WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile ); } - WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); + if (name && name[0]) + WritePrivateProfileString( NULL, NULL, NULL, name ); + else + WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); } @@ -273,3 +293,4 @@ void wPrefReset( } prefs_da.cnt = 0; } + -- cgit v1.2.3