summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/settings.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/sfcave-sdl/settings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/settings.cpp98
1 files changed, 48 insertions, 50 deletions
diff --git a/noncore/games/sfcave-sdl/settings.cpp b/noncore/games/sfcave-sdl/settings.cpp
index 914c4ec..20cce4f 100644
--- a/noncore/games/sfcave-sdl/settings.cpp
+++ b/noncore/games/sfcave-sdl/settings.cpp
@@ -7,2 +7,4 @@
+// Defined in util.h
+string getHomeDir();
@@ -18,11 +20,4 @@ Settings::Settings( char * env_file, char * env_dir )
{
- char * homeDir = getenv( "HOME" );;
-
- if ( homeDir )
- {
- envFile.append(homeDir);
- envFile.append("/");
- }
- else
- printf( "Environment var HOME not set!\n" );
+ envFile = getHomeDir();
+ envFile.append("/");
@@ -44,11 +39,4 @@ Settings::Settings()
{
- char * homeDir = getenv("HOME");
-
- if ( homeDir)
- {
- envFile.append(homeDir);
- envFile.append("/");
- }
- else
- printf( "Environment var HOME not set!\n" );
+ envFile = getHomeDir();
+ envFile.append("/");
@@ -112,2 +100,14 @@ bool Settings::readSetting(const string key_str,unsigned long& result)
+bool Settings::readSetting(const string key_str,double& result)
+{
+ string Buffer;
+ if (readSetting(key_str,Buffer))
+ {
+ result = atof( Buffer.c_str() );
+ return true;
+ }
+ else
+ return false;
+}
+
bool Settings::readSetting(const string key_str,bool& result)
@@ -161,2 +161,10 @@ void Settings::writeSetting(const string key_str,const bool value)
+void Settings::writeSetting(const string key_str,const double value)
+{
+ char Buffer[30];
+
+ sprintf(Buffer,"%lf",value);
+ writeSetting(key_str,string(Buffer));
+}
+
void Settings::writeSetting(const string key_str,const int value)
@@ -197,37 +205,30 @@ void Settings::writeSetting(const string key_str,const string value)
// already exists then it will be overwritten.
-
- std::vector<string> FileEntries;
FILE *fd=NULL,*ftemp=NULL;
- char * dir_str;
- char * dir_ptr;
char buf[MAX_LINE_SIZE];
- char tempname[12];
- dir_str = strdup(envFile.c_str());
- printf( "dir = %s, file - %s\n", dir_str, envFile.c_str() );
- if (dir_str)
+ string tmp = getHomeDir() + "/tmpsfcave.dat";
+
+ // if file exists we need to save contents
+ fd = fopen( envFile.c_str(), "r" );
+ ftemp = fopen( tmp.c_str(), "w" );
+ if ( fd != NULL && ftemp != NULL )
{
- // remove file from the directory string
- dir_ptr = strrchr(dir_str, (int)'/');
- if (dir_ptr)
+ while (fgets(buf, MAX_LINE_SIZE-1, fd))
{
- *dir_ptr = 0;
-
- // make the directory path if it does not exist
-// mkdir(dir_str, 777 );
+ if ( strncmp( buf, key_str.c_str(), key_str.size() ) != 0 )
+ fprintf( ftemp, "%s", buf );
+ }
+ fclose(fd);
+ }
- // if file exists we need to save contents
- if ((fd = fopen(envFile.c_str(), "r")) != NULL)
- {
- while (fgets(buf, MAX_LINE_SIZE-1, fd))
- FileEntries.push_back(string(buf));
- fclose(fd);
- }
+ if ( ftemp != NULL )
+ {
+ fprintf(ftemp, "%s\t%s\n", key_str.c_str(),value.c_str());
+ fclose( ftemp );
- char *home = getenv( "HOME" );
- string tmp;
- if ( home )
- tmp = home + string( "/" ) + "tmpsfcave.dat";
- else
- tmp = "./tmpsfcave.dat";
+ remove(envFile.c_str());
+ rename( tmp.c_str(), envFile.c_str() );
+ }
+/*
+ string tmp = getHomeDir() + "/tmpsfcave.dat";
strcpy(tempname,tmp.c_str() );
@@ -256,6 +257,2 @@ void Settings::writeSetting(const string key_str,const string value)
fclose(ftemp);
-
- remove(envFile.c_str());
-
- rename( tempname, envFile.c_str() );
}
@@ -267,2 +264,3 @@ void Settings::writeSetting(const string key_str,const string value)
}
+*/
}