-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config now lives in ~/Library/Preferences/com.tashcan.startrekpatch
- Loading branch information
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
namespace fm | ||
{ | ||
enum { | ||
NSApplicationDirectory = 1, | ||
NSDemoApplicationDirectory, | ||
NSDeveloperApplicationDirectory, | ||
NSAdminApplicationDirectory, | ||
NSLibraryDirectory, | ||
NSDeveloperDirectory, | ||
NSUserDirectory, | ||
NSDocumentationDirectory, | ||
NSDocumentDirectory, | ||
NSCoreServiceDirectory, | ||
NSAutosavedInformationDirectory = 11, | ||
NSDesktopDirectory = 12, | ||
NSCachesDirectory = 13, | ||
NSApplicationSupportDirectory = 14, | ||
NSDownloadsDirectory = 15, | ||
NSInputMethodsDirectory = 16, | ||
NSMoviesDirectory = 17, | ||
NSMusicDirectory = 18, | ||
NSPicturesDirectory = 19, | ||
NSPrinterDescriptionDirectory = 20, | ||
NSSharedPublicDirectory = 21, | ||
NSPreferencePanesDirectory = 22, | ||
NSApplicationScriptsDirectory = 23, | ||
NSItemReplacementDirectory = 99, | ||
NSAllApplicationsDirectory = 100, | ||
NSAllLibrariesDirectory = 101, | ||
NSTrashDirectory = 102 | ||
}; | ||
typedef unsigned long SearchPathDirectory; | ||
|
||
enum { | ||
NSUserDomainMask = 1, // user's home directory --- place to install user's personal items (~) | ||
NSLocalDomainMask = | ||
2, // local to the current machine --- place to install items available to everyone on this machine (/Library) | ||
NSNetworkDomainMask = 4, // publically available location in the local area network --- place to install items | ||
// available on the network (/Network) | ||
NSSystemDomainMask = 8, // provided by Apple, unmodifiable (/System) | ||
NSAllDomainsMask = 0x0ffff // all domains: all of the above and future items | ||
}; | ||
typedef unsigned long SearchPathDomainMask; | ||
|
||
class FolderManager | ||
{ | ||
public: | ||
static const char *pathForDirectory(SearchPathDirectory directory, SearchPathDomainMask domainMask); | ||
static const char *pathForDirectoryAppropriateForItemAtPath(SearchPathDirectory directory, | ||
SearchPathDomainMask domainMask, const char *itemPath, | ||
bool create = false); | ||
}; | ||
}; // namespace fm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "folder_manager.h" | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
using namespace fm; | ||
|
||
const char * FolderManager::pathForDirectory(SearchPathDirectory directory, SearchPathDomainMask domainMask) { | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSArray *URLs = [fileManager URLsForDirectory:(NSSearchPathDirectory)directory inDomains:domainMask]; | ||
if (URLs.count == 0) return NULL; | ||
|
||
NSURL *URL = [URLs objectAtIndex:0]; | ||
NSString *path = URL.path; | ||
|
||
// `fileSystemRepresentation` on an `NSString` gives a path suitable for POSIX APIs | ||
return path.fileSystemRepresentation; | ||
} | ||
|
||
const char * FolderManager::pathForDirectoryAppropriateForItemAtPath(SearchPathDirectory directory, | ||
SearchPathDomainMask domainMask, const char *itemPath, bool create) { | ||
|
||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSString *nsPath = [fileManager stringWithFileSystemRepresentation:itemPath length:strlen(itemPath)]; | ||
NSURL *itemURL = (nsPath ? [NSURL fileURLWithPath:nsPath] : nil); | ||
|
||
NSURL *URL = [fileManager URLForDirectory:(NSSearchPathDirectory)directory | ||
inDomain:domainMask | ||
appropriateForURL:itemURL | ||
create:create error:NULL]; | ||
return URL.path.fileSystemRepresentation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters