+#pragma mark -
+#pragma mark Crash Log
+- (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
+{
+ NSString *urlStr = @"http://jones.videolan.org/crashlog/sendcrashreport.php";
+ NSURL *url = [NSURL URLWithString:urlStr];
+
+ NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
+ [req setHTTPMethod:@"POST"];
+
+ NSString * email;
+ if( [o_crashrep_includeEmail_ckb state] == NSOnState )
+ {
+ ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
+ ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
+ email = [emails valueAtIndex:[emails indexForIdentifier:
+ [emails primaryIdentifier]]];
+ }
+ else
+ email = [NSString string];
+
+ NSString *postBody;
+ postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
+ [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+ [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+ [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+
+ [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
+
+ /* Released from delegate */
+ crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)connection
+{
+ NSRunInformationalAlertPanel(_NS("Crash Report successfully sent"),
+ _NS("Thanks for your report!"),
+ _NS("OK"), nil, nil, nil);
+ [crashLogURLConnection release];
+ crashLogURLConnection = nil;
+}
+
+- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
+{
+ NSRunCriticalAlertPanel(_NS("Error when sending the Crash Report"), [error localizedDescription], @"OK", nil, nil);
+ [crashLogURLConnection release];
+ crashLogURLConnection = nil;
+}
+
+- (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
+{
+ NSString * crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
+ NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
+ NSString *fname;
+ NSString * latestLog = nil;
+ int year = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"] : 0;
+ int month = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportMonth"]: 0;
+ int day = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportDay"] : 0;
+ int hours = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportHours"]: 0;
+
+ 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 *o_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 )
+ [NSApp runModalForWindow: o_crashrep_win];
+ [o_pool release];
+}
+
+- (IBAction)crashReporterAction:(id)sender