public void BeginUpload() { if (!PublisherIsReady()) { return; } Status = PublisherStatus.Uploading; ErrorMessage = null; userAborted = false; var collatedData = PrepareLogData(); #if TEST_MOCK_UPLOAD HugsLibController.Logger.Message(collatedData); HugsLibUtility.CopyToClipboard(collatedData); MockUpload(); return; #endif if (collatedData == null) { ErrorMessage = "Failed to collect data"; Status = PublisherStatus.Error; return; } Action <Exception> onRequestFailed = ex => { if (userAborted) { return; } OnRequestError(ex.Message); HugsLibController.Logger.Warning("Exception during log publishing (gist creation): " + ex); }; try { collatedData = CleanForJSON(collatedData); var payload = string.Format(GistPayloadJson, GistDescription, OutputLogFilename, collatedData); activeRequest = new UnityWebRequest(GistApiUrl, UnityWebRequest.kHttpVerbPOST); activeRequest.SetRequestHeader("Authorization", "token " + GitHubAuthToken); activeRequest.SetRequestHeader("User-Agent", RequestUserAgent); activeRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(payload)) { contentType = "application/json" }; activeRequest.downloadHandler = new DownloadHandlerBuffer(); HugsLibUtility.AwaitUnityWebResponse(activeRequest, OnUploadComplete, onRequestFailed, HttpStatusCode.Created); } catch (Exception e) { onRequestFailed(e); } }
public static void ExportConfigViaReflection(SimpleSidearms mod) { ModSettingsPack pack = HugsLibController.SettingsManager.GetModSettings(mod.ModIdentifier); if (pack == null) { return; } XElement root = new XElement("root"); pack.CallByReflection("WriteXml", root); //should only have one Log.Message("Exporting current config!"); StringBuilder builder = new StringBuilder(); foreach (XElement child in root.Elements()) { builder.AppendLine(child.ToString()); } HugsLibUtility.CopyToClipboard(builder.ToString()); }
private static void CopyMessage(LogMessage logMessage) { HugsLibUtility.CopyToClipboard(logMessage.text + "\n" + logMessage.StackTrace); }
public void CopyToClipboard() { HugsLibUtility.CopyToClipboard(PrepareLogData()); }
public override void DoWindowContents(Rect inRect) { Text.Font = GameFont.Medium; var titleRect = new Rect(inRect.x, inRect.y, inRect.width, 40); Widgets.Label(titleRect, "HugsLib_logs_publisherTitle".Translate()); Text.Font = GameFont.Small; var labelEntry = statusMessages[publisher.Status]; var statusLabelText = labelEntry.requiresEllipsis ? labelEntry.labelKey.Translate(GenText.MarchingEllipsis(Time.realtimeSinceStartup)) : labelEntry.labelKey.Translate(); if (publisher.Status == LogPublisher.PublisherStatus.Error) { statusLabelText = String.Format(statusLabelText, publisher.ErrorMessage); } var statusLabelRect = new Rect(inRect.x, inRect.y + titleRect.height, inRect.width, StatusLabelHeight); Widgets.Label(statusLabelRect, statusLabelText); if (publisher.Status == LogPublisher.PublisherStatus.Done) { var urlAreaRect = new Rect(inRect.x, statusLabelRect.y + statusLabelRect.height, inRect.width, CopyButtonSize.y); GUI.DrawTexture(urlAreaRect, UrlBackgroundTex); var urlLabelRect = new Rect(urlAreaRect.x, urlAreaRect.y, urlAreaRect.width - CopyButtonSize.x, urlAreaRect.height); Text.Font = GameFont.Medium; var prevAnchor = Text.Anchor; Text.Anchor = TextAnchor.MiddleCenter; var croppedResultUrl = publisher.ResultUrl; if (croppedResultUrl.Length > MaxResultUrlLength) { // crop the url in case shortening has failed and the original url is displayed croppedResultUrl = croppedResultUrl.Substring(0, MaxResultUrlLength) + "..."; } Widgets.Label(urlLabelRect, croppedResultUrl); Text.Anchor = prevAnchor; Text.Font = GameFont.Small; var copyBtnRect = new Rect(inRect.width - CopyButtonSize.x, urlAreaRect.y, CopyButtonSize.x, CopyButtonSize.y); if (Widgets.ButtonText(copyBtnRect, "HugsLib_logs_copy".Translate())) { HugsLibUtility.CopyToClipboard(publisher.ResultUrl); } } var bottomLeftBtnRect = new Rect(inRect.x, inRect.height - ControlButtonSize.y, ControlButtonSize.x, ControlButtonSize.y); if (publisher.Status == LogPublisher.PublisherStatus.Error) { if (Widgets.ButtonText(bottomLeftBtnRect, "HugsLib_logs_retryBtn".Translate())) { publisher.BeginUpload(); } } else if (publisher.Status == LogPublisher.PublisherStatus.Done) { if (Widgets.ButtonText(bottomLeftBtnRect, "HugsLib_logs_browseBtn".Translate())) { Application.OpenURL(publisher.ResultUrl); } } var bottomRightBtnRect = new Rect(inRect.width - ControlButtonSize.x, inRect.height - ControlButtonSize.y, ControlButtonSize.x, ControlButtonSize.y); if (publisher.Status == LogPublisher.PublisherStatus.Uploading) { if (Widgets.ButtonText(bottomRightBtnRect, "HugsLib_logs_abortBtn".Translate())) { publisher.AbortUpload(); } } else { if (Widgets.ButtonText(bottomRightBtnRect, "CloseButton".Translate())) { Close(); } } }
public void CopyToClipboard() { UpdateCustomOptionsUsage(); HugsLibUtility.CopyToClipboard(PrepareLogData()); }