Skip to content

Commit

Permalink
Refactor check updates
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Sep 1, 2024
1 parent d6ca317 commit f0d05a7
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 39 deletions.
4 changes: 4 additions & 0 deletions v2rayN/ServiceLib/Common/DownloaderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public async Task DownloadFileAsync(IWebProxy? webProxy, string url, string file
{
progress.Report(101);
}
else if (value.Error != null)
{
throw value.Error;
}
}
};

Expand Down
2 changes: 2 additions & 0 deletions v2rayN/ServiceLib/Enums/EViewAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public enum EViewAction
DispatcherReload,
DispatcherRefreshServersBiz,
DispatcherRefreshIcon,
DispatcherCheckUpdate,
DispatcherCheckUpdateFinished,
}
}
23 changes: 14 additions & 9 deletions v2rayN/ServiceLib/Handler/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void CheckUpdateGuiN(Config config, Action<bool, string> update, bool pre
downloadHandle.Error += (sender2, args) =>
{
_updateFunc(false, args.GetException().Message);
_updateFunc(false, "");
};
AbsoluteCompleted += (sender2, args) =>
{
Expand All @@ -61,19 +62,20 @@ public void CheckUpdateGuiN(Config config, Action<bool, string> update, bool pre
url = args.Url;
AskToDownload(downloadHandle, url, true).ContinueWith(task =>
{
_updateFunc(false, url);
_updateFunc(false, "");
});
}
else
{
_updateFunc(false, args.Msg);
_updateFunc(false, "");
}
};
_updateFunc(false, string.Format(ResUI.MsgStartUpdating, ECoreType.v2rayN));
CheckUpdateAsync(ECoreType.v2rayN, preRelease);
CheckUpdateAsync(downloadHandle, ECoreType.v2rayN, preRelease);
}

public void CheckUpdateCore(ECoreType type, Config config, Action<bool, string> update, bool preRelease)
public async void CheckUpdateCore(ECoreType type, Config config, Action<bool, string> update, bool preRelease)
{
_config = config;
_updateFunc = update;
Expand Down Expand Up @@ -103,7 +105,8 @@ public void CheckUpdateCore(ECoreType type, Config config, Action<bool, string>
};
downloadHandle.Error += (sender2, args) =>
{
_updateFunc(true, args.GetException().Message);
_updateFunc(false, args.GetException().Message);
_updateFunc(false, "");
};

AbsoluteCompleted += (sender2, args) =>
Expand All @@ -116,16 +119,17 @@ public void CheckUpdateCore(ECoreType type, Config config, Action<bool, string>
url = args.Url;
AskToDownload(downloadHandle, url, true).ContinueWith(task =>
{
_updateFunc(false, url);
_updateFunc(false, "");
});
}
else
{
_updateFunc(false, args.Msg);
_updateFunc(false, "");
}
};
_updateFunc(false, string.Format(ResUI.MsgStartUpdating, type));
CheckUpdateAsync(type, preRelease);
CheckUpdateAsync(downloadHandle, type, preRelease);
}

public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, Action<bool, string> update)
Expand Down Expand Up @@ -267,6 +271,7 @@ public void UpdateGeoFileAll(Config config, Action<bool, string> update)
{
await UpdateGeoFile("geosite", _config, update);
await UpdateGeoFile("geoip", _config, update);
_updateFunc(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo"));
});
}

Expand All @@ -282,14 +287,14 @@ public void RunAvailabilityCheck(Action<bool, string> update)

#region private

private async void CheckUpdateAsync(ECoreType type, bool preRelease)
private async void CheckUpdateAsync(DownloadHandler downloadHandle, ECoreType type, bool preRelease)
{
try
{
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(type);
string url = coreInfo.coreReleaseApiUrl;

var result = await (new DownloadHandler()).DownloadStringAsync(url, true, Global.AppName);
var result = await downloadHandle.DownloadStringAsync(url, true, Global.AppName);
if (!Utils.IsNullOrEmpty(result))
{
ResponseHandler(type, result, preRelease);
Expand Down Expand Up @@ -483,7 +488,7 @@ private async Task AskToDownload(DownloadHandler downloadHandle, string url, boo
//}
//if (blDownload)
//{
await downloadHandle.DownloadFileAsync(url, true, 600);
await downloadHandle.DownloadFileAsync(url, true, 60);
//}
}

Expand Down
17 changes: 17 additions & 0 deletions v2rayN/ServiceLib/Models/CheckUpdateItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServiceLib.Models
{
public class CheckUpdateItem
{
public bool? isSelected { get; set; }
public string coreType { get; set; }
public string? remarks { get; set; }
public string? fileName { get; set; }
public bool? isFinished { get; set; }
}
}
Loading

0 comments on commit f0d05a7

Please sign in to comment.