Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: allowed to download pdb file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 14, 2023
1 parent 44ec205 commit 483b813
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,55 +37,63 @@ public static async void GetAllCustomRotations()

foreach (var url in libs)
{
try
{
var valid = Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
if (!valid) continue;
}
catch
{
continue;
}
try
{
hasDownload |= await DownloadOneUrlAsync(url, relayFolder, client);
var pdbUrl = Path.ChangeExtension(url, ".pdb");
await DownloadOneUrlAsync(pdbUrl, relayFolder, client);

var fileName = url.Split('/').LastOrDefault();
if (string.IsNullOrEmpty(fileName)) continue;
if (Path.GetExtension(fileName) != ".dll") continue;
var filePath = Path.Combine(relayFolder, fileName);
if(!Service.Config.AutoUpdateRotations && File.Exists(filePath)) continue;
}
}

//Download
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (File.Exists(filePath))
{
if (new FileInfo(filePath).Length == response.Content.Headers.ContentLength)
{
continue;
}
File.Delete(filePath);
}
if (hasDownload) LoadRotationsFromLocal(relayFolder);
}

using(var stream = new FileStream(filePath, File.Exists(filePath)
? FileMode.Open : FileMode.CreateNew))
{
await response.Content.CopyToAsync(stream);
}
private static async Task<bool> DownloadOneUrlAsync(string url, string relayFolder, HttpClient client)
{
try
{
var valid = Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
if (!valid) return false;
}
catch
{
return false;
}
try
{
var fileName = url.Split('/').LastOrDefault();
if (string.IsNullOrEmpty(fileName)) return false;
//if (Path.GetExtension(fileName) != ".dll") continue;
var filePath = Path.Combine(relayFolder, fileName);
if (!Service.Config.AutoUpdateRotations && File.Exists(filePath)) return false;

//Download
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (File.Exists(filePath))
{
if (new FileInfo(filePath).Length == response.Content.Headers.ContentLength)
{
return false;
}

hasDownload = true;
PluginLog.Log($"Successfully download the {filePath}");
File.Delete(filePath);
}
catch (Exception ex)

using (var stream = new FileStream(filePath, File.Exists(filePath)
? FileMode.Open : FileMode.CreateNew))
{
PluginLog.LogError(ex, $"failed to download from {url}");
await response.Content.CopyToAsync(stream);
}
}
}

if (hasDownload) LoadRotationsFromLocal(relayFolder);
PluginLog.Log($"Successfully download the {filePath}");
return true;
}
catch (Exception ex)
{
PluginLog.LogError(ex, $"failed to download from {url}");
}
return false;
}

private static Assembly LoadOne(string filePath)
Expand Down

0 comments on commit 483b813

Please sign in to comment.