v1.3.0.1 (Epic Store release)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace DeployAll;
|
||||
|
||||
@@ -64,13 +66,16 @@ public static class Util
|
||||
DeleteDirectory(path);
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<byte> DownloadFile(string url)
|
||||
|
||||
public static IReadOnlyList<byte> DownloadFile(string url, out string finalUrl)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
finalUrl = url;
|
||||
|
||||
using var httpClient = new HttpClient();
|
||||
var response = httpClient.Send(new HttpRequestMessage(
|
||||
HttpMethod.Get,
|
||||
new Uri(url)));
|
||||
finalUrl = response.RequestMessage?.RequestUri?.AbsoluteUri ?? url;
|
||||
using var stream = response.Content.ReadAsStream();
|
||||
|
||||
using var reader = new BinaryReader(stream);
|
||||
@@ -100,6 +105,50 @@ public static class Util
|
||||
public static bool AnsweredNo(this string answer)
|
||||
=> !answer.AnsweredYes();
|
||||
|
||||
public static bool IsValidEpicCfg(this char c)
|
||||
=> char.IsDigit(c)
|
||||
|| c is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z') or '-' or '_' or '+' or '/';
|
||||
|
||||
public static bool IsValidEpicCfg(this string s)
|
||||
=> !string.IsNullOrEmpty(s) && s.All(IsValidEpicCfg);
|
||||
|
||||
public static bool TryLoadXml(string path, [NotNullWhen(returnValue: true)]out XDocument? doc)
|
||||
{
|
||||
try
|
||||
{
|
||||
doc = XDocument.Load(path);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
doc = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetAttributeOrThrow(this XElement element, string attributeName)
|
||||
{
|
||||
var attribute = element
|
||||
.Attributes()
|
||||
.FirstOrDefault(e => e.Name.LocalName.Equals(attributeName, StringComparison.OrdinalIgnoreCase));
|
||||
if (attribute != null
|
||||
&& !string.IsNullOrEmpty(attribute.Value))
|
||||
{
|
||||
return attribute.Value;
|
||||
}
|
||||
|
||||
throw new Exception($"{attributeName} is not set");
|
||||
}
|
||||
|
||||
public static string ThrowIfNullOrEmpty(this string? s, string msg)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s)) { throw new Exception(msg); }
|
||||
return s;
|
||||
}
|
||||
|
||||
public static string NormalizePathSeparators(this string s)
|
||||
=> s.Replace("\\", "/");
|
||||
|
||||
public static Process StartProcess(ProcessStartInfo info)
|
||||
=> Process.Start(info)
|
||||
?? throw new Exception($"Failed to start process \"{info.FileName}\"");
|
||||
|
||||
Reference in New Issue
Block a user