+ while (fname = [direnum nextObject])
+ {
+ [direnum skipDescendents];
+ if([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"])
+ {
+ NSArray * compo = [fname componentsSeparatedByString:@"_"];
+ if( [compo count] < 3 ) continue;
+ compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
+ if( [compo count] < 4 ) continue;
+
+ // Dooh. ugly.
+ if( year < [[compo objectAtIndex:0] intValue] ||
+ (year ==[[compo objectAtIndex:0] intValue] &&
+ (month < [[compo objectAtIndex:1] intValue] ||
+ (month ==[[compo objectAtIndex:1] intValue] &&
+ (day < [[compo objectAtIndex:2] intValue] ||
+ (day ==[[compo objectAtIndex:2] intValue] &&
+ hours < [[compo objectAtIndex:3] intValue] ))))))
+ {
+ year = [[compo objectAtIndex:0] intValue];
+ month = [[compo objectAtIndex:1] intValue];
+ day = [[compo objectAtIndex:2] intValue];
+ hours = [[compo objectAtIndex:3] intValue];
+ latestLog = [crashReporter stringByAppendingPathComponent:fname];
+ }
+ }
+ }
+
+ if(!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
+ return nil;
+
+ if( !previouslySeen )
+ {
+ [[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"LatestCrashReportYear"];
+ [[NSUserDefaults standardUserDefaults] setInteger:month forKey:@"LatestCrashReportMonth"];
+ [[NSUserDefaults standardUserDefaults] setInteger:day forKey:@"LatestCrashReportDay"];
+ [[NSUserDefaults standardUserDefaults] setInteger:hours forKey:@"LatestCrashReportHours"];
+ }
+ return latestLog;
+}
+
+- (NSString *)latestCrashLogPath
+{
+ return [self latestCrashLogPathPreviouslySeen:YES];
+}
+
+- (void)lookForCrashLog
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
+ BOOL areCrashLogsTooOld = ![[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"];
+ NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
+ if( latestLog && !areCrashLogsTooOld )
+ [self performSelectorOnMainThread:@selector(notifyCrashLogToUser:) withObject:latestLog waitUntilDone:NO];
+
+ [pool release];
+}
+
+- (void)notifyCrashLogToUser:(NSString *)crashLogPath
+{
+ int ret = NSRunInformationalAlertPanel(_NS("VLC has previously crashed"),
+ _NS("VLC has previously crashed, do you want to send an email with the crash to VLC's team?"),
+ _NS("Send"), _NS("Don't Send"), nil, nil);
+ if( ret == NSAlertDefaultReturn )
+ {
+ [self mailCrashLog:[NSString stringWithContentsOfFile:crashLogPath] withUserComment:_NS("<Explain here what you were doing when VLC crashed, with possibly a link to the failing video>")];
+ }
+}