Skip to content

Commit

Permalink
Temporarily switch back to opening browser for self-updating
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Apr 26, 2021
1 parent 98720d9 commit d11e4a6
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions BTD Mod Helper Core/Api/Updater/UpdaterHttp.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MelonLoader;

namespace BTD_Mod_Helper.Api.Updater
{
Expand Down Expand Up @@ -41,8 +44,24 @@ private HttpClient CreateHttpClient()

public async Task<List<GithubReleaseInfo>> GetReleaseInfoAsync(string url)
{
var releaseJson = await client.GetStringAsync(url);
return GithubReleaseInfo.FromJson(releaseJson);
var tries = 0;
while (tries < 3)
{
try
{
var releaseJson = await client.GetStringAsync(url);
return GithubReleaseInfo.FromJson(releaseJson);
}
catch (Exception e)
{
Thread.Sleep(1000);
e.ToString();
}

tries++;
}

throw new HttpRequestException("Failed to retrieve release info");
}

public async Task<string> GetMelonInfoAsync(string url)
Expand Down Expand Up @@ -134,6 +153,14 @@ private void MakeLengthEven(ref string string1, ref string string2)

public async Task<bool> Download(string modDir)
{
if (updateInfo.Name == "BloonsTD6 Mod Helper")
{
Process.Start(updateInfo.LatestURL);
MelonLogger.Msg("For the moment, the mod helper can't directly update itself");
return false;
}


string downloadURL;
if (updateInfo.GithubReleaseURL != "")
{
Expand All @@ -153,7 +180,14 @@ public async Task<bool> Download(string modDir)

if (!string.IsNullOrEmpty(updateInfo.Location))
{
File.Delete(updateInfo.Location);
try
{
File.Delete(updateInfo.Location);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

var fileName = downloadURL.Substring(downloadURL.LastIndexOf("/", StringComparison.Ordinal));
Expand Down

0 comments on commit d11e4a6

Please sign in to comment.