diff --git a/ModLoader/Activity1.cs b/ModLoader/Activity1.cs index edb54b31..a88a0c58 100644 --- a/ModLoader/Activity1.cs +++ b/ModLoader/Activity1.cs @@ -128,6 +128,7 @@ namespace ModLoader private readonly Mutex _working = new Mutex(false); public static Activity1 Instance { get; private set; } + private readonly HttpClient _httpClient = new HttpClient(); private static readonly Dictionary MessageHandler = new Dictionary(); @@ -150,10 +151,29 @@ namespace ModLoader protected override void OnCreate(Bundle bundle) { Instance = this; - Type[] services = { typeof(Analytics), typeof(Crashes) }; - AppCenter.Start("b8eaba94-d276-4c97-9953-0c91e7357e21", services); base.OnCreate(bundle); this.RequestWindowFeature(WindowFeatures.NoTitle); + if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.N) + { + StrictMode.SetVmPolicy(new StrictMode.VmPolicy.Builder().Build()); + } + try { + File errorLog = this.FilesDir.ListFiles().FirstOrDefault(f => f.IsDirectory && f.Name == "error")?.ListFiles().FirstOrDefault(f => f.Name.EndsWith(".dat")); + if (errorLog != null) + { + string errorLogPath = Path.Combine(this.ExternalCacheDir.AbsolutePath, "error.dat"); + StreamToFile(new FileStream(errorLog.AbsolutePath, FileMode.Open), errorLogPath); + ShowConfirmDialog(this, Resource.String.Error, Resource.String.CrashReportMessage, Resource.String.View, Resource.String.Dismiss, () => { OpenTextFile(this, errorLogPath); }); + } + Type[] services = { typeof(Analytics), typeof(Crashes) }; + AppCenter.Start("b8eaba94-d276-4c97-9953-0c91e7357e21", services); + IEnumerable errorLogs = this.FilesDir.ListFiles().FirstOrDefault(f => f.IsDirectory && f.Name == "error")?.ListFiles().ToList().FindAll(f => f.Name.EndsWith(".dat") || f.Name.EndsWith(".throwable")); + if (errorLogs != null) foreach (var file in errorLogs) file.Delete(); + } + catch (Exception) + { + // ignored + } if (Build.VERSION.SdkInt >= BuildVersionCodes.P) { this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges; @@ -169,13 +189,18 @@ namespace ModLoader private void OnCreatePartTwo() { - if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.N) - { - StrictMode.SetVmPolicy(new StrictMode.VmPolicy.Builder().Build()); - } - - new PgyUpdateManager.Builder().SetForced(false).SetUserCanRetry(true).SetDeleteHistroyApk(true).Register(); + if (GetConfig(this, "compatCheck", "true") == "false") + Constants.CompatCheck = false; + if (GetConfig(this, "upgradeCheck", "true") == "false") + Constants.UpgradeCheck = false; + else + new PgyUpdateManager.Builder().SetForced(false).SetUserCanRetry(true).SetDeleteHistroyApk(true).Register(); this.InitEnvironment(); + this.FindViewById