2010-01-06 18:11:16 -06:00
|
|
|
//
|
|
|
|
// MGMReporter.m
|
|
|
|
// GeckoReporter
|
|
|
|
//
|
|
|
|
// Created by Mr. Gecko on 12/27/09.
|
2011-08-30 15:02:29 -05:00
|
|
|
// Copyright (c) 2011 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
|
|
// with or without fee is hereby granted, provided that the above copyright notice
|
|
|
|
// and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
|
|
|
|
// OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
// ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2010-01-06 18:11:16 -06:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "MGMReporter.h"
|
|
|
|
#import "MGMReportWindow.h"
|
|
|
|
#import "MGMSender.h"
|
|
|
|
#import "MGMSystemInfo.h"
|
|
|
|
#import "MGMLog.h"
|
|
|
|
|
2011-08-30 15:02:29 -05:00
|
|
|
NSString * const MGMCopyright = @"Copyright (c) 2011 Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/";
|
2010-08-12 12:00:31 -05:00
|
|
|
|
2010-01-06 18:11:16 -06:00
|
|
|
NSString * const MGMReportsPath = @"~/Library/Logs/CrashReporter";
|
|
|
|
NSString * const MGMGRDoneNotification = @"MGMGRDoneNotification";
|
|
|
|
NSString * const MGMGRUserEmail = @"MGMGRUserEmail";
|
|
|
|
NSString * const MGMGRUserName = @"MGMGRUserName";
|
|
|
|
NSString * const MGMGRLastCrashDate = @"MGMGRLastCrashDate";
|
|
|
|
NSString * const MGMGRSendAll = @"MGMGRSendAll";
|
|
|
|
NSString * const MGMGRIgnoreAll = @"MGMGRIgnoreAll";
|
|
|
|
|
|
|
|
@implementation MGMReporter
|
|
|
|
+ (id)sharedReporter {
|
2010-01-12 08:05:09 -06:00
|
|
|
return [[self alloc] init];
|
2010-01-06 18:11:16 -06:00
|
|
|
}
|
|
|
|
- (id)init {
|
2011-08-30 15:02:29 -05:00
|
|
|
if ((self = [super init])) {
|
2010-01-06 18:11:16 -06:00
|
|
|
foundReport = NO;
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(done:) name:MGMGRDoneNotification object:nil];
|
|
|
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([userDefaults objectForKey:MGMGRIgnoreAll]==nil || ![[userDefaults objectForKey:MGMGRIgnoreAll] boolValue]) {
|
|
|
|
NSFileManager *manager = [NSFileManager defaultManager];
|
2010-08-12 12:00:31 -05:00
|
|
|
NSString *applicationName = [[MGMSystemInfo info] applicationEXECName];
|
2011-08-30 15:02:29 -05:00
|
|
|
[lastDate release];
|
2010-01-06 18:11:16 -06:00
|
|
|
lastDate = [[userDefaults objectForKey:MGMGRLastCrashDate] retain];
|
|
|
|
NSDirectoryEnumerator *crashFiles = [manager enumeratorAtPath:[MGMReportsPath stringByExpandingTildeInPath]];
|
|
|
|
NSString *crashFile = nil;
|
|
|
|
NSString *lastCrashFile = nil;
|
2011-08-30 15:02:29 -05:00
|
|
|
while ((crashFile = [crashFiles nextObject])) {
|
2010-01-06 18:11:16 -06:00
|
|
|
if ([crashFile hasPrefix:applicationName]) {
|
|
|
|
NSString *file = [[MGMReportsPath stringByAppendingPathComponent:crashFile] stringByResolvingSymlinksInPath];
|
|
|
|
BOOL readable = [manager isReadableFileAtPath:file];
|
|
|
|
NSDictionary *attributes = [crashFiles fileAttributes];
|
2010-08-12 12:00:31 -05:00
|
|
|
NSDate *modifiedDate = [attributes objectForKey:NSFileModificationDate];
|
|
|
|
if (readable && (lastDate==nil || (![lastDate isEqual:modifiedDate] && [lastDate laterDate:modifiedDate]==modifiedDate))) {
|
2011-08-30 15:02:29 -05:00
|
|
|
[lastDate release];
|
2010-08-12 12:00:31 -05:00
|
|
|
lastDate = [modifiedDate retain];
|
2010-01-06 18:11:16 -06:00
|
|
|
lastCrashFile = file;
|
|
|
|
foundReport = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (foundReport) {
|
|
|
|
MGMLog(@"Latest Crash Report %@, %@", lastDate, lastCrashFile);
|
|
|
|
if ([userDefaults objectForKey:MGMGRSendAll]!=nil && [[userDefaults objectForKey:MGMGRSendAll] boolValue]) {
|
|
|
|
if (mailSender==nil) {
|
2010-01-12 08:05:09 -06:00
|
|
|
mailSender = [MGMSender new];
|
2010-01-06 18:11:16 -06:00
|
|
|
[mailSender sendReport:lastCrashFile reportDate:lastDate userReport:@"User set to send all." delegate:self];
|
|
|
|
}
|
|
|
|
} else {
|
2010-01-12 08:05:09 -06:00
|
|
|
[MGMReportWindow sharedWindowWithReport:lastCrashFile reportDate:lastDate];
|
2010-01-06 18:11:16 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:MGMGRDoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], MGMSaveLastDate, nil]];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:MGMGRDoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], MGMSaveLastDate, nil]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2010-05-05 17:09:21 -05:00
|
|
|
#if MGMGRReleaseDebug
|
2010-01-06 18:11:16 -06:00
|
|
|
MGMLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
#endif
|
2011-08-30 15:02:29 -05:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
[lastDate release];
|
|
|
|
[mailSender release];
|
2010-01-06 18:11:16 -06:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
- (void)done:(NSNotification *)note {
|
|
|
|
if ([[note userInfo] objectForKey:MGMSaveLastDate]!=nil && [[[note userInfo] objectForKey:MGMSaveLastDate] boolValue]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:lastDate forKey:MGMGRLastCrashDate];
|
|
|
|
}
|
|
|
|
[self release];
|
|
|
|
self = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendError:(NSError *)error {
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:MGMGRDoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], MGMSaveLastDate, nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendFinished:(NSString *)received {
|
|
|
|
MGMLog(@"%@", received);
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:MGMGRDoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], MGMSaveLastDate, nil]];
|
|
|
|
}
|
|
|
|
@end
|