Skip to content
Browse files

Change default log file path.

It is now ~/Library/Application Support/com.tlphn.Telephone/Telephone.log.

Closes #48.
  • Loading branch information...
1 parent afe79b2 commit 2371ec2fa0aa3a8ac2c12c947aa749a672c40688 @eofster committed Feb 23, 2012
Showing with 39 additions and 10 deletions.
  1. +39 −10 Classes/AppController.m
View
49 Classes/AppController.m
@@ -100,6 +100,10 @@ - (void)setupGrowl;
// Installs a callback to monitor system DNS servers changes.
- (void)installDNSChangesCallback;
+// Creates directory for file at the specified path. Also creates intermediate
+// directories.
+- (void)createDirectoryForFileAtPath:(NSString *)path;
+
@end
@@ -254,16 +258,19 @@ + (void)initialize {
forKey:kVoiceActivityDetection];
[defaultsDict setObject:[NSNumber numberWithBool:NO] forKey:kUseICE];
- NSArray *libraryPaths
- = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
- NSUserDomainMask,
- NO);
- if ([libraryPaths count] > 0) {
- NSString *logPath
- = [[libraryPaths objectAtIndex:0]
- stringByAppendingPathComponent:@"Logs/Telephone.log"];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ NSArray *applicationSupportURLs
+ = [fileManager URLsForDirectory:NSApplicationSupportDirectory
+ inDomains:NSUserDomainMask];
+
+ if ([applicationSupportURLs count] > 0) {
+ NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
+ NSURL *applicationSupportURL = [applicationSupportURLs objectAtIndex:0];
+ NSURL *logURL
+ = [applicationSupportURL URLByAppendingPathComponent:bundleIdentifier];
+ logURL = [logURL URLByAppendingPathComponent:@"Telephone.log"];
- [defaultsDict setObject:logPath
+ [defaultsDict setObject:[logURL path]
forKey:kLogFileName];
}
@@ -991,6 +998,24 @@ - (void)installDNSChangesCallback {
CFRelease(dynamicStore);
}
+- (void)createDirectoryForFileAtPath:(NSString *)path {
+ NSString *directoryPath = [path stringByDeletingLastPathComponent];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ BOOL exists = [fileManager fileExistsAtPath:directoryPath
+ isDirectory:NULL];
+ if (!exists) {
+ NSError *error = nil;
+ BOOL created = [fileManager createDirectoryAtPath:directoryPath
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error];
+ if (!created) {
+ NSLog(@"Error creating directory %@. %@",
+ directoryPath, [error localizedDescription]);
+ }
+ }
+}
+
- (BOOL)installAddressBookPlugInsAndReturnError:(NSError **)error {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *plugInsPath = [mainBundle builtInPlugInsPath];
@@ -1801,7 +1826,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[self userAgent] setUserAgentString:[NSString stringWithFormat:@"%@ %@",
bundleName, bundleShortVersion]];
- [[self userAgent] setLogFileName:[defaults stringForKey:kLogFileName]];
+ NSString *logFileName = [defaults stringForKey:kLogFileName];
+ if ([logFileName length] > 0) {
+ [self createDirectoryForFileAtPath:logFileName];
+ [[self userAgent] setLogFileName:logFileName];
+ }
[[self userAgent] setLogLevel:[defaults integerForKey:kLogLevel]];

0 comments on commit 2371ec2

Please sign in to comment.
Something went wrong with that request. Please try again.