private void StartLogUpload(bool isPreviousCrashLog = false) { UploadingLog = true; TopText = M3L.GetString(M3L.string_collectingLogInformation); NamedBackgroundWorker bw = new NamedBackgroundWorker(@"LogUpload"); bw.DoWork += (a, b) => { void updateStatusCallback(string status) { CollectionStatusMessage = status; } StringBuilder logUploadText = new StringBuilder(); if (SelectedDiagnosticTarget != null && SelectedDiagnosticTarget.Game > Mod.MEGame.Unknown) { Debug.WriteLine(@"Selected game target: " + SelectedDiagnosticTarget.TargetPath); logUploadText.Append("[MODE]diagnostics\n"); logUploadText.Append(LogCollector.PerformDiagnostic(SelectedDiagnosticTarget, TextureCheck /*&& SelectedDiagnosticTarget.TextureModded*/, updateStatusCallback)); logUploadText.Append("\n"); } if (SelectedLog != null && SelectedLog.Selectable) { Debug.WriteLine(@"Selected log: " + SelectedLog.filepath); logUploadText.Append("[MODE]logs\n"); logUploadText.AppendLine(LogCollector.CollectLogs(SelectedLog.filepath)); logUploadText.Append("\n"); } var logtext = logUploadText.ToString(); if (logtext != null) { CollectionStatusMessage = "Compressing for upload"; var lzmalog = SevenZipHelper.LZMA.CompressToLZMAFile(Encoding.UTF8.GetBytes(logtext)); try { //this doesn't need to technically be async, but library doesn't have non-async method. //DEBUG ONLY!!! CollectionStatusMessage = "Uploading to ME3Tweaks"; #if DEBUG string responseString = @"https://me3tweaks.com/modmanager/logservice/logupload2.php".PostUrlEncodedAsync(new { LogData = Convert.ToBase64String(lzmalog), ModManagerVersion = App.BuildNumber, CrashLog = isPreviousCrashLog }).ReceiveString().Result; #else string responseString = @"https://me3tweaks.com/modmanager/logservice/logupload.php".PostUrlEncodedAsync(new { LogData = Convert.ToBase64String(lzmalog), ModManagerVersion = App.BuildNumber, CrashLog = isPreviousCrashLog }).ReceiveString().Result; #endif Uri uriResult; bool result = Uri.TryCreate(responseString, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (result) { //should be valid URL. //diagnosticsWorker.ReportProgress(0, new ThreadCommand(SET_DIAGTASK_ICON_GREEN, Image_Upload)); //e.Result = responseString; Log.Information(@"Result from server for log upload: " + responseString); b.Result = responseString; return; } else { Log.Error(@"Error uploading log. The server responded with: " + responseString); b.Result = M3L.GetString(M3L.string_interp_serverRejectedTheUpload, responseString); } } catch (AggregateException e) { Exception ex = e.InnerException; string exmessage = ex.Message; b.Result = M3L.GetString(M3L.string_interp_logWasUnableToUpload, exmessage); } catch (FlurlHttpTimeoutException) { // FlurlHttpTimeoutException derives from FlurlHttpException; catch here only // if you want to handle timeouts as a special case Log.Error(@"Request timed out while uploading log."); b.Result = M3L.GetString(M3L.string_interp_requestTimedOutUploading); } catch (Exception ex) { // ex.Message contains rich details, inclulding the URL, verb, response status, // and request and response bodies (if available) Log.Error(@"Handled error uploading log: " + App.FlattenException(ex)); string exmessage = ex.Message; var index = exmessage.IndexOf(@"Request body:"); if (index > 0) { exmessage = exmessage.Substring(0, index); } b.Result = M3L.GetString(M3L.string_interp_logWasUnableToUpload, exmessage); } } else { //Log pull failed } }; bw.RunWorkerCompleted += (a, b) => { if (b.Result is string response) { if (response.StartsWith(@"http")) { Utilities.OpenWebpage(response); } else { OnClosing(DataEventArgs.Empty); var res = M3L.ShowDialog(Window.GetWindow(this), response, M3L.GetString(M3L.string_logUploadFailed), MessageBoxButton.OK, MessageBoxImage.Error); return; } } OnClosing(DataEventArgs.Empty); }; bw.RunWorkerAsync(); }