Skip to content

Commit

Permalink
Moved config file to Application Support folder for Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
kroyee committed Sep 9, 2017
1 parent c982857 commit 1ad881e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/resources/ResourcePath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
///
////////////////////////////////////////////////////////////
std::string resourcePath(void);
std::string applicationSupportFolder(void);

#endif
23 changes: 22 additions & 1 deletion src/resources/ResourcePath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,25 @@
[pool drain];

return rpath;
}
}

std::string applicationSupportFolder(void) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSFileManager* sharedFM = [NSFileManager defaultManager];
NSArray* possibleURLs = [sharedFM URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];
NSURL* appSupportDir = nil;

if ([possibleURLs count] >= 1) {
// Use the first directory (if multiple are returned)
appSupportDir = [possibleURLs objectAtIndex:0];
}
NSString* path = [NSString stringWithFormat:@"%@%@", appSupportDir.absoluteString, @"SpeedBlocks/"];
std::string dir = [path UTF8String];
dir.replace(dir.find("%20"), 3, " ");
dir.erase(0,7);

[pool drain];
return dir;
}
14 changes: 9 additions & 5 deletions src/resources/optionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ using std::ofstream;

#ifdef __APPLE__
#include "ResourcePath.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#elif __WIN32
#include "EmptyResourcePath.h"
#include <windows.h>
#include <shlobj.h>
#include <stdlib.h>
#else
#include "EmptyResourcePath.h"
#endif


Expand Down Expand Up @@ -108,8 +107,10 @@ void optionSet::loadOptions() {
CoTaskMemFree(appdataW);

ifstream file (appdataFolder + "options.cfg");
#elif __APPLE__
ifstream file (applicationSupportFolder() + "options.cfg");
#else
ifstream file (resourcePath() + "options.cfg");
ifstream file ("options.cfg");
#endif

int countset = 0;
Expand Down Expand Up @@ -199,8 +200,11 @@ void optionSet::saveOptions() {
CoTaskMemFree(appdataW);

ofstream file(appdataFolder + "options.cfg");
#elif __APPLE__
mkdir(applicationSupportFolder().c_str(), 0755);
ifstream file (applicationSupportFolder() + "options.cfg");
#else
ofstream file(resourcePath() + "options.cfg");
ofstream file("options.cfg");
#endif
sf::Color col;

Expand Down

0 comments on commit 1ad881e

Please sign in to comment.