Skip to content

Commit

Permalink
Version bump, better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Jan 5, 2023
1 parent 97bc091 commit eff2fc4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- Fixed Exporting Game Data button for modders
- Added `application/x-msdos-program` as an allowed download content type for the Mod Browser
- Increased the default mod browser download limit from 50 MB to 75 MB
- Added a more descriptive error message for mods that are too big
- Fixed some upgrade screen UI glitches
19 changes: 15 additions & 4 deletions Shared/Api/ModHelperGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Il2CppAssets.Scripts.Unity.UI_New.Popups;
Expand Down Expand Up @@ -34,7 +35,7 @@ internal static class ModHelperGithub
private const string ZipContentType = "application/zip";
private const string ZipContentType2 = "application/x-zip-compressed";

private const string Sorry =
private const string GenericSorry =
"Please try again at a later time. If issues stil persist for this mod and not others, contact the mod developer.";

public static List<ModHelperData> Mods { get; private set; } = new();
Expand Down Expand Up @@ -138,7 +139,7 @@ public static async Task DownloadLatest(ModHelperData mod, bool bypassPopup = fa
latestCommit = mod.LatestCommit ?? await mod.GetLatestCommit();
if (latestCommit == null)
{
const string errorMessage = $"Failed to get latest commit from the GitHub API. {Sorry}";
const string errorMessage = $"Failed to get latest commit from the GitHub API. {GenericSorry}";
ModHelper.Error(errorMessage);
if (!bypassPopup)
{
Expand All @@ -153,7 +154,7 @@ public static async Task DownloadLatest(ModHelperData mod, bool bypassPopup = fa
latestRelease = mod.LatestRelease ?? await mod.GetLatestRelease();
if (latestRelease == null)
{
const string errorMessage = $"Failed to get latest release from the GitHub API. {Sorry}";
const string errorMessage = $"Failed to get latest release from the GitHub API. {GenericSorry}";
ModHelper.Error(errorMessage);
if (!bypassPopup)
{
Expand Down Expand Up @@ -217,6 +218,7 @@ private static string ParseReleaseMessage(string body) =>
private static async Task Download(ModHelperData mod, Action<string> callback, Release latestRelease,
bool showPopup)
{
Exception exception = null;
try
{
var asset = mod.SubPath == null
Expand All @@ -239,9 +241,18 @@ private static async Task Download(ModHelperData mod, Action<string> callback, R
catch (Exception e)
{
ModHelper.Warning(e);
exception = e;
}
exception ??= ModHelperHttp.LastException;

const string errorMessage = $"Failed to download asset. {Sorry}";
var errorMessage = "Failed to download asset. ";
errorMessage += exception switch
{
HttpRequestException httpRequestException when httpRequestException.Message.Contains("maximum buffer") =>
$"Size exceeded the current limit of {(int) MelonMain.ModRequestLimitMb} MB. " +
"This limit can be increased in the Mod Helper's settings menu under the Mod Browser section.",
_ => GenericSorry
};
ModHelper.Error(errorMessage);
PopupScreen.instance.SafelyQueue(screen => screen.ShowOkPopup(errorMessage));
}
Expand Down
6 changes: 6 additions & 0 deletions Shared/Api/ModHelperHttp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class ModHelperHttp
/// </summary>
public static HttpClient Client { get; private set; }

internal static Exception LastException { get; private set; }

/// <summary>
/// Initializes the HttpClient
/// </summary>
Expand All @@ -42,6 +44,7 @@ public static void Init()
/// <returns>Whether it was sucessful</returns>
public static async Task<bool> DownloadFile(string url, string filePath)
{
LastException = null;
try
{
if (!ModHelper.IsNet6)
Expand All @@ -57,6 +60,7 @@ public static async Task<bool> DownloadFile(string url, string filePath)
catch (Exception e)
{
ModHelper.Warning(e);
LastException = e;
}
finally
{
Expand Down Expand Up @@ -106,6 +110,7 @@ public static async Task<ZipArchive> GetZip(string url)
/// <returns>Enumeration of extracted file paths, or null</returns>
public static async Task<DirectoryInfo> DownloadZip(string url, string path = null)
{
LastException = null;
try
{
if (path == null)
Expand All @@ -129,6 +134,7 @@ public static async Task<DirectoryInfo> DownloadZip(string url, string path = nu
catch (Exception e)
{
ModHelper.Warning(e);
LastException = e;
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion Shared/Api/UI/ModMenuData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BTD_Mod_Helper.Api;
/// <summary>
/// Class to be passed in to the Open methods of Screens
/// </summary>
[RegisterTypeInIl2Cpp]
[RegisterTypeInIl2Cpp(false)]
public class ModMenuData : Object
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Shared/ModHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class ModHelper
#region ModHelperData for the Mod Helper

internal const string Name = "BloonsTD6 Mod Helper";
internal const string Version = "3.1.1";
internal const string Version = "3.1.2";
internal const string RepoOwner = "gurrenm3";
internal const string RepoName = "BTD-Mod-Helper";
internal const string Description = "A powerful and easy to use API for modding BTD6. Also the mod that is allowing all of this UI to happen right now :P";
Expand Down

0 comments on commit eff2fc4

Please sign in to comment.