From 7111fa4d4fb77183b72b673d96cb366ad30a37d2 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Fri, 7 Nov 2014 16:21:43 +0100 Subject: [PATCH] Fix another stupid crash. --- Classes/SBAppDelegate.m | 14 +++++++++++--- Classes/SBLogger.m | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Classes/SBAppDelegate.m b/Classes/SBAppDelegate.m index 62c838a..2ad4580 100755 --- a/Classes/SBAppDelegate.m +++ b/Classes/SBAppDelegate.m @@ -26,9 +26,17 @@ [SBPrefsController registerUserDefaults]; - NSString *path = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, - NSUserDomainMask, - YES) firstObject] stringByAppendingPathComponent:@"Subler/debugLog.txt"]; + NSString *appSupportPath = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, + NSUserDomainMask, + YES) firstObject] stringByAppendingPathComponent:@"Subler"]; + + if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportPath]) { + [[NSFileManager defaultManager] createDirectoryAtPath:appSupportPath withIntermediateDirectories:YES attributes:nil error:NULL]; + } + + NSString *path = [appSupportPath stringByAppendingPathComponent:@"debugLog.txt"]; + + SBLogger *logger = [[SBLogger alloc] initWithLogFile:[NSURL fileURLWithPath:path]]; [logger clearLog]; diff --git a/Classes/SBLogger.m b/Classes/SBLogger.m index 58ee79c..26b8e13 100644 --- a/Classes/SBLogger.m +++ b/Classes/SBLogger.m @@ -43,8 +43,10 @@ - (void)writeToLog:(NSString *)string { if (self.fileURL) { FILE *f = fopen([[self.fileURL path] fileSystemRepresentation], "a"); - fprintf(f, "%s %s", [[self currentTime] UTF8String], [string UTF8String]); - fclose(f); + if (f) { + fprintf(f, "%s %s", [[self currentTime] UTF8String], [string UTF8String]); + fclose(f); + } } if (self.delegate) {