Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
don't save powder.pref in a .plist file on OS X
untested, but it didn't make sense how we were doing it anyway. Also, it was spelled wrong
  • Loading branch information
jacob1 committed Jan 24, 2016
1 parent a6f49ad commit 82dc5e1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
28 changes: 0 additions & 28 deletions src/SDLMain.m
Expand Up @@ -367,34 +367,6 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString

@end

char * readUserPreferences()
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

NSString *prefDataNSString = [prefs stringForKey:@"powder.pref"];
const char *prefData = [prefDataNSString UTF8String];
if(prefData == NULL)
prefData = "";

char *prefDataCopy = calloc([prefDataNSString length]+1, 1);
SDL_strlcpy(prefDataCopy, prefData, [prefDataNSString length]+1);

[prefDataNSString release];

return prefDataCopy;
}

void writeUserPreferences(const char * prefData)
{
NSString *prefDataNSString = [NSString stringWithUTF8String:prefData];

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:prefDataNSString forKey:@"powder.pref"];
[prefs synchronize];

[prefDataNSString release];
}

//doesn't work on OS X 10.5 or below
char * readClipboard()
{
Expand Down
26 changes: 1 addition & 25 deletions src/client/Client.cpp
Expand Up @@ -60,10 +60,6 @@ extern "C"
#else
#include <dirent.h>
#endif
#ifdef MACOSX
char * readUserPreferences();
void writeUserPreferences(const char * prefData);
#endif
}


Expand All @@ -88,15 +84,9 @@ Client::Client():
}

//Read config
#ifdef MACOSX
char * prefData = readUserPreferences();
std::stringstream configFile(prefData);
free(prefData);
#else
std::ifstream configFile;
configFile.open("powder.pref", std::ios::binary);
#endif
if(configFile)
if (configFile)
{
int fsize = configFile.tellg();
configFile.seekg(0, std::ios::end);
Expand Down Expand Up @@ -126,9 +116,7 @@ Client::Client():
std::cerr << "Error: Could not read data from prefs: " << e.what() << std::endl;
}
}
#ifndef MACOSX
configFile.close();
#endif
firstRun = false;
}
else
Expand Down Expand Up @@ -930,12 +918,8 @@ void Client::RemoveListener(ClientListener * listener)

void Client::WritePrefs()
{
#ifdef MACOSX
std::stringstream configFile;
#else
std::ofstream configFile;
configFile.open("powder.pref", std::ios::trunc);
#endif

if (configFile)
{
Expand All @@ -958,15 +942,7 @@ void Client::WritePrefs()
}
json::Writer::Write(configDocument, configFile);

#ifdef MACOSX
std::string prefString = configFile.str();

char prefData[prefString.length()+1];
std::strcpy(prefData, prefString.c_str());
writeUserPreferences(prefData);
#else
configFile.close();
#endif
}
}

Expand Down

0 comments on commit 82dc5e1

Please sign in to comment.