using TH1_Core.Events; using Logic.CrashSight; using TH1_Logic.Config; using TH1_Logic.Oss; #if STEAM_CHANNEL || STEAMWORKS_NET using Steamworks; #endif using TH1_UI.Controller.Base; using TH1_UI.View.Global; namespace TH1_UI.Controller.Global { public class UIGlobalBugReportController : ViewController { private bool _isUploading; public UIGlobalBugReportController() { } protected override void RegisterEventCallback() { base.RegisterEventCallback(); if (WindowScript != null) { WindowScript.OnBtnCloseClick += _OnBtnCloseClick; WindowScript.OnBtnSubmitClick += _OnBtnSubmitClick; } } protected override void UnregisterEventCallback() { if (WindowScript != null) { WindowScript.OnBtnCloseClick = null; WindowScript.OnBtnSubmitClick = null; } base.UnregisterEventCallback(); } protected override void OnOpen() { base.OnOpen(); if (_openParameter is ShowUIGlobalBugReport evt) { WindowScript?.SetContent(evt); } } public override bool Close() { WindowScript?.CloseView(); _isUploading = false; return base.Close(); } void _OnBtnCloseClick() { Close(); } void _OnBtnSubmitClick() { if (_isUploading || WindowScript == null) return; _ = SubmitBugReportAsync(); } private async System.Threading.Tasks.Task SubmitBugReportAsync() { if (WindowScript == null) return; _isUploading = true; WindowScript.SetUploading(true); WindowScript.SetStatusText(Table.Instance.TextDataAssets.BugReportUploadingHint); try { if (!TryGetSteamId(out var steamId)) { WindowScript.SetStatusText(Table.Instance.TextDataAssets.BugReportUploadingFailedHint); return; } string version = PlayerBugReportService.GetCurrentVersion(); string description = WindowScript.GetDescription(); bool includeArchives = WindowScript.ShouldUploadRecord(); var package = PlayerBugReportService.BuildPackage(steamId, description, version, includeArchives, includeArchives, includeArchives); if (package.Data.Length > PlayerBugReportService.MaxBugReportUploadBytes) { LogSystem.LogError($"PlayerBugReport upload failed: package size {package.Data.Length} exceeds {PlayerBugReportService.MaxBugReportUploadBytes}"); WindowScript.SetStatusText(Table.Instance.TextDataAssets.BugReportUploadingFailedHint); return; } var result = await OssManager.Instance.UploadPlayerBugReportAsync(steamId, package.Data, package.Manifest.version); if (result.success) { WindowScript.SetStatusText(Table.Instance.TextDataAssets.BugReportUploadingSuccessHint); WindowScript.ShowInsideNotify(Table.Instance.TextDataAssets.BugReportUploadingSuccessNotify, true); } else { WindowScript.SetStatusText(Table.Instance.TextDataAssets.BugReportUploadingFailedHint); } } catch (System.Exception ex) { LogSystem.LogError($"PlayerBugReport submit exception: {ex}"); WindowScript?.SetStatusText(Table.Instance.TextDataAssets.BugReportUploadingFailedHint); } finally { _isUploading = false; WindowScript?.SetUploading(false); } } private static bool TryGetSteamId(out string steamId) { steamId = ""; #if STEAM_CHANNEL || STEAMWORKS_NET try { if (!SteamUser.BLoggedOn()) return false; var id = SteamUser.GetSteamID().m_SteamID; if (id == 0) return false; steamId = id.ToString(); return true; } catch (System.Exception ex) { LogSystem.LogWarning($"PlayerBugReport SteamID unavailable: {ex.Message}"); return false; } #else return false; #endif } } }