summaryrefslogtreecommitdiff
path: root/app/wlib/mswlib/mswpref.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/mswlib/mswpref.c')
-rw-r--r--app/wlib/mswlib/mswpref.c47
1 files changed, 34 insertions, 13 deletions
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 <commdlg.h>
#include <math.h>
#include <stdio.h>
-#include "misc.h"
#include "mswint.h"
#include <shlobj.h>
#include <Shlwapi.h>
@@ -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; i<prefs_da.cnt; i++) {
+ p = &prefs(i);
+ if (!name || !name[0]) name = mswProfileFile;
+ int rc = GetPrivateProfileString( p->section, 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;
}
+