start a big rework
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Pilz.Cryptography;
|
||||
|
||||
namespace Pilz.Updating.Administration.Integrations;
|
||||
|
||||
public class GitLabSnippetConfig
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
public string GitLabUrl { get; set; }
|
||||
public SecureString PersonalAccessToken { get; set; }
|
||||
public int ProjectId { get; set; }
|
||||
public int SnippetId { get; set; }
|
||||
public string SnippetFilePath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using NGitLab;
|
||||
using NGitLab.Models;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Updating.Administration.Integrations;
|
||||
|
||||
public static class GitLabSnippetExtension
|
||||
{
|
||||
private static IGitLabClient GetClient(GitLabSnippetConfig config)
|
||||
{
|
||||
return new GitLabClient(config.GitLabUrl, config.PersonalAccessToken);
|
||||
}
|
||||
|
||||
private static bool LoadSnippet(UpdateServerManager manager)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
var glClient = GetClient(manager.Config.GitLabSnippetConfig);
|
||||
|
||||
if (glClient.Snippets.Get(manager.Config.GitLabSnippetConfig.ProjectId, manager.Config.GitLabSnippetConfig.SnippetId) is not Snippet snippet
|
||||
|| snippet.Files.FirstOrDefault(f => f.Path == manager.Config.GitLabSnippetConfig.SnippetFilePath) is not SnippetFile file
|
||||
|| httpClient.GetStringAsync(snippet.Files[1].RawUrl).Result is not string content)
|
||||
return false;
|
||||
|
||||
manager.UpdateInfo = UpdateInfo.Parse(content);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool SaveSnippet(UpdateServerManager manager)
|
||||
{
|
||||
var glClient = GetClient(manager.Config.GitLabSnippetConfig);
|
||||
|
||||
if (glClient == null)
|
||||
return false;
|
||||
|
||||
glClient.Snippets.Update(new SnippetProjectUpdate
|
||||
{
|
||||
SnippetId = manager.Config.GitLabSnippetConfig.SnippetId,
|
||||
ProjectId = manager.Config.GitLabSnippetConfig.ProjectId,
|
||||
Files = [
|
||||
new SnippetUpdateFile
|
||||
{
|
||||
Action = SnippetUpdateFileAction.Update,
|
||||
FilePath = manager.Config.GitLabSnippetConfig.SnippetFilePath,
|
||||
Content = manager.UpdateInfo.ToString(),
|
||||
}
|
||||
],
|
||||
Visibility = VisibilityLevel.Public,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Task<bool> ReadInfoFromGitLabSnippet(this UpdateServerManager manager)
|
||||
{
|
||||
return Task.Run(() => LoadSnippet(manager));
|
||||
}
|
||||
|
||||
public static Task<bool> SaveInfoToGitLabSnippet(this UpdateServerManager manager)
|
||||
{
|
||||
return Task.Run(() => SaveSnippet(manager));
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
using global::System.IO;
|
||||
using global::System.Reflection;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
using Pilz.Updating.UpdateInstaller;
|
||||
using System.Collections.Generic;
|
||||
using Z.Collections.Extensions;
|
||||
|
||||
namespace Pilz.Updating.Administration.Packaging;
|
||||
|
||||
internal class UpdatePackageManager
|
||||
{
|
||||
|
||||
// F i e l d s
|
||||
|
||||
private UpdatePackageTemplate template;
|
||||
|
||||
// P r o p e r t i e s
|
||||
|
||||
public string FilesToCopyPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return template.FilesToCopyPath;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
template.FilesToCopyPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
// C o n s t r u c o t r s
|
||||
|
||||
public UpdatePackageManager()
|
||||
{
|
||||
NewTemplate();
|
||||
}
|
||||
|
||||
// F e a t u r e s
|
||||
|
||||
public void LoadTemplate(string filePath)
|
||||
{
|
||||
template = JObject.Parse(File.ReadAllText(filePath)).ToObject<UpdatePackageTemplate>();
|
||||
}
|
||||
|
||||
public void SaveTemplate(string filePath)
|
||||
{
|
||||
File.WriteAllText(filePath, JObject.FromObject(template).ToString());
|
||||
}
|
||||
|
||||
public void NewTemplate()
|
||||
{
|
||||
template = new UpdatePackageTemplate();
|
||||
}
|
||||
|
||||
public void ExportPackage(string path)
|
||||
{
|
||||
var exporter = new UpdatePackagePackager(template);
|
||||
exporter.Export(path);
|
||||
}
|
||||
|
||||
private bool CheckUpdateInstallerAddOn(string path)
|
||||
{
|
||||
var asm = Assembly.ReflectionOnlyLoadFrom(path);
|
||||
var t = asm.GetType($"{UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_NAMESPACE}.{UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_TYPE}", false);
|
||||
bool isSupported = false;
|
||||
if (t is object)
|
||||
{
|
||||
var mi = t.GetMethod(UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_METHOD, BindingFlags.Static | BindingFlags.Public);
|
||||
if (mi is object)
|
||||
{
|
||||
var @params = mi.GetParameters();
|
||||
if (@params.Length == 1 && @params.GetType() == typeof(Dictionary<string, object>))
|
||||
{
|
||||
isSupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
public bool AddUpdateInstallerAddOn(string path)
|
||||
{
|
||||
if (Conversions.ToBoolean(!template.UpdateInstallerAddOns.Contains(path) && CheckUpdateInstallerAddOn(path)))
|
||||
{
|
||||
template.UpdateInstallerAddOns.Add(path);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllUpdateInstallerÁddOn()
|
||||
{
|
||||
return template.UpdateInstallerAddOns;
|
||||
}
|
||||
|
||||
public void RemoveUpdateInstallerAddOn(string path)
|
||||
{
|
||||
template.UpdateInstallerAddOns.RemoveIfContains(path);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using Pilz.Updating.UpdateInstaller;
|
||||
using Z.IO.Extensions;
|
||||
|
||||
namespace Pilz.Updating.Administration.Packaging;
|
||||
|
||||
public class UpdatePackagePackager
|
||||
{
|
||||
public UpdatePackageTemplate UpdatePackageTemplate { get; set; }
|
||||
|
||||
public UpdatePackagePackager(UpdatePackageTemplate updatePackageTemplate)
|
||||
{
|
||||
UpdatePackageTemplate = updatePackageTemplate;
|
||||
}
|
||||
|
||||
public void Export(string exportPath)
|
||||
{
|
||||
string tempPath = MyPaths.GetMyAppDataPath();
|
||||
var packageDir = new DirectoryInfo(Path.Combine(tempPath, "UpdatePackageCreation"));
|
||||
|
||||
// Ensure package directory exists and is empty
|
||||
if (packageDir.Exists)
|
||||
packageDir.Delete(true);
|
||||
packageDir.Create();
|
||||
|
||||
// Copy local data to temp data directory
|
||||
var dataDir = packageDir.CreateSubdirectory(PackageFileNameDefinations.ZIP_APP_DATA_FILES_DIRECTORY);
|
||||
var localDataDir = new DirectoryInfo(UpdatePackageTemplate.FilesToCopyPath);
|
||||
localDataDir.CopyTo(dataDir.FullName, SearchOption.AllDirectories);
|
||||
|
||||
// Copy all UpdateInstaller AddOns
|
||||
var addOnsDir = packageDir.CreateSubdirectory(PackageFileNameDefinations.ZIP_UPDATE_INSTALLER_ADDONS_DIRECTORY);
|
||||
uint curAddOnID = 0;
|
||||
foreach (string fAddOn in UpdatePackageTemplate.UpdateInstallerAddOns)
|
||||
{
|
||||
File.Copy(fAddOn, Path.Combine(addOnsDir.FullName, $"installer_addon_{curAddOnID}.dll"));
|
||||
curAddOnID += 1;
|
||||
}
|
||||
|
||||
// Ensure destination file doesn't exist
|
||||
if (File.Exists(exportPath))
|
||||
File.Delete(exportPath);
|
||||
|
||||
// Export to ZIP
|
||||
ZipFile.CreateFromDirectory(packageDir.FullName, exportPath);
|
||||
|
||||
// Delete temp directory
|
||||
packageDir.Delete(true);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pilz.Updating.Administration.Packaging;
|
||||
|
||||
public class UpdatePackageTemplate
|
||||
{
|
||||
public string FilesToCopyPath { get; set; }
|
||||
public List<string> UpdateInstallerAddOns { get; set; } = [];
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
|
||||
<PackageReference Include="NGitLab" Version="6.50.3" />
|
||||
<PackageReference Include="Pilz.Cryptography" Version="2.0.1" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||
|
||||
@@ -3,6 +3,4 @@
|
||||
public static class PackageFileNameDefinations
|
||||
{
|
||||
public const string ZIP_PACKAGE_FILENAME = "updatepackage.zip";
|
||||
public const string ZIP_UPDATE_INSTALLER_ADDONS_DIRECTORY = "installer_addons";
|
||||
public const string ZIP_APP_DATA_FILES_DIRECTORY = "appdata";
|
||||
}
|
||||
@@ -1,25 +1,26 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Updating.Administration.Discord;
|
||||
using Pilz.Updating.Administration.Integrations;
|
||||
using System.IO;
|
||||
|
||||
namespace Pilz.Updating.Administration;
|
||||
|
||||
public class UpdateProject
|
||||
{
|
||||
public UpdateServerConfig UpdateServerConfig { get; } = new UpdateServerConfig();
|
||||
public DiscordBotConfig DiscordBotConfig { get; } = new DiscordBotConfig();
|
||||
public ProxyConfiguration ProxyConfig { get; } = new ProxyConfiguration();
|
||||
public UpdateServerConfig UpdateServerConfig { get; } = new();
|
||||
public DiscordBotConfig DiscordBotConfig { get; } = new();
|
||||
public ProxyConfiguration ProxyConfig { get; } = new();
|
||||
|
||||
public static UpdateProject Load(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
return JObject.Parse(File.ReadAllText(filePath)).ToObject<UpdateProject>();
|
||||
return JsonConvert.DeserializeObject<UpdateProject>(File.ReadAllText(filePath));
|
||||
else
|
||||
return new UpdateProject();
|
||||
return new();
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
{
|
||||
File.WriteAllText(filePath, JObject.FromObject(this).ToString());
|
||||
File.WriteAllText(filePath, JsonConvert.SerializeObject(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Cryptography;
|
||||
using Pilz.Updating.Administration.Integrations;
|
||||
|
||||
namespace Pilz.Updating.Administration;
|
||||
|
||||
public class UpdateServerConfig
|
||||
{
|
||||
public bool UseProxyForWebDAV { get; set; } = false;
|
||||
public string ServerAdress { get; set; }
|
||||
public string PublicPackageBaseURL { get; set; }
|
||||
public string UpdateInfoFilename { get; set; }
|
||||
public string Username { get; set; }
|
||||
|
||||
[JsonProperty("PasswordV3")]
|
||||
public SecureString Password { get; set; }
|
||||
public GitLabSnippetConfig GitLabSnippetConfig { get; } = new();
|
||||
}
|
||||
|
||||
@@ -1,403 +1,25 @@
|
||||
using Microsoft.VisualBasic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using WebDav;
|
||||
using static Microsoft.VisualBasic.CompilerServices.LikeOperator;
|
||||
using System.IO;
|
||||
|
||||
namespace Pilz.Updating.Administration;
|
||||
|
||||
public class UpdateServerManager
|
||||
public class UpdateServerManager(UpdateServerConfig config)
|
||||
{
|
||||
private const string PKG_SEARCHTEXT = "pkg*.*.*.*.zip";
|
||||
private const string PKG_FILENAME_TEMPLATE = "pkg{0}{1}.zip";
|
||||
private const string PKG_FILENAME_ALPHADEFINITION = "a";
|
||||
private const string PKG_FILENAME_BETADEFINITION = "b";
|
||||
private const string PKG_FILENAME_RCDEFINITION = "rc";
|
||||
private const string PKG_FILENAME_RELEASEDEFINITION = "r";
|
||||
|
||||
private WebDavClient client;
|
||||
public UpdateInfo UpdateInfo { get; private set; }
|
||||
public UpdateServerConfig Config { get; private set; }
|
||||
public UpdateInfo UpdateInfo { get; internal set; } = new();
|
||||
public UpdateServerConfig Config { get; private set; } = config;
|
||||
public bool IsReady { get; private set; }
|
||||
|
||||
public UpdateServerManager(UpdateServerConfig config)
|
||||
{
|
||||
GenerateClient(config);
|
||||
NewInfo();
|
||||
}
|
||||
|
||||
public bool GenerateClient(UpdateServerConfig config)
|
||||
{
|
||||
bool success;
|
||||
|
||||
try
|
||||
{
|
||||
// Create client params
|
||||
var clientparams = new WebDavClientParams()
|
||||
{
|
||||
BaseAddress = new Uri(config.ServerAdress),
|
||||
Credentials = new NetworkCredential(config.Username, config.Password),
|
||||
UseProxy = false
|
||||
};
|
||||
|
||||
// Create client
|
||||
client = new WebDavClient(clientparams);
|
||||
|
||||
// Remember config
|
||||
Config = config;
|
||||
|
||||
success = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
success = false;
|
||||
Config = null;
|
||||
client = null;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public async Task<bool> LoadInfoFromServer()
|
||||
{
|
||||
bool success;
|
||||
|
||||
try
|
||||
{
|
||||
var response = await client.GetProcessedFile(Config.UpdateInfoFilename);
|
||||
|
||||
if (response.IsSuccessful)
|
||||
{
|
||||
var sr = new StreamReader(response.Stream);
|
||||
var raw = await sr.ReadToEndAsync();
|
||||
sr.Close();
|
||||
UpdateInfo = JObject.Parse(raw).ToObject<UpdateInfo>();
|
||||
}
|
||||
|
||||
success = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveInfoToServer()
|
||||
{
|
||||
bool success;
|
||||
|
||||
try
|
||||
{
|
||||
// Remove configs of non-existing packages
|
||||
await ClearUpdateInfo();
|
||||
|
||||
// Update Packagelinks
|
||||
UpdatePackageLinks();
|
||||
|
||||
// Write
|
||||
var raw = UpdateInfo.ToString();
|
||||
var ms = new MemoryStream();
|
||||
var sw = new StreamWriter(ms);
|
||||
await sw.WriteAsync(raw);
|
||||
await sw.FlushAsync();
|
||||
|
||||
// Upload
|
||||
ms.Position = 0;
|
||||
await client.PutFile(Config.UpdateInfoFilename, ms);
|
||||
|
||||
ms.Close();
|
||||
success = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void LoadInfoFromFile(string filePath)
|
||||
{
|
||||
UpdateInfo = JObject.Parse(File.ReadAllText(filePath)).ToObject<UpdateInfo>();
|
||||
UpdateInfo = UpdateInfo.Parse(File.ReadAllText(filePath));
|
||||
}
|
||||
|
||||
public async Task SaveInfoToFile(string filePath)
|
||||
public void SaveInfoToFile(string filePath)
|
||||
{
|
||||
// Remove configs of non-existing packages
|
||||
await ClearUpdateInfo();
|
||||
|
||||
// Update Packagelinks
|
||||
UpdatePackageLinks();
|
||||
|
||||
// Write
|
||||
File.WriteAllText(filePath, UpdateInfo.ToString());
|
||||
}
|
||||
|
||||
public void NewInfo()
|
||||
{
|
||||
UpdateInfo = new UpdateInfo();
|
||||
}
|
||||
|
||||
private async Task ClearUpdateInfo()
|
||||
{
|
||||
var pkgs = await GetUpdatePackagesList();
|
||||
var infosToRemove = new List<UpdatePackageInfo>();
|
||||
|
||||
// Find non-existing packages
|
||||
foreach (var info in UpdateInfo.Packages)
|
||||
{
|
||||
if (!pkgs.Where((n) => n == info.Version).Any())
|
||||
{
|
||||
infosToRemove.Add(info);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove found packages
|
||||
foreach (var info in infosToRemove)
|
||||
UpdateInfo.Packages.Remove(info);
|
||||
}
|
||||
|
||||
private void UpdatePackageLinks()
|
||||
{
|
||||
foreach (var info in UpdateInfo.Packages)
|
||||
UpdatePackageLink(info);
|
||||
}
|
||||
|
||||
private void UpdatePackageLink(UpdatePackageInfo info)
|
||||
{
|
||||
info.Packagelink = Config.PublicPackageBaseURL + BuildPackageFilename(info.Version);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ApplicationVersion>> GetUpdatePackagesList()
|
||||
{
|
||||
var pkgs = new List<ApplicationVersion>();
|
||||
var response = await client.Propfind(string.Empty);
|
||||
|
||||
if (response.IsSuccessful)
|
||||
{
|
||||
foreach (var resource in response.Resources)
|
||||
{
|
||||
var fileName = Path.GetFileName(resource.Uri);
|
||||
if (!string.IsNullOrEmpty(fileName) && fileName.ToLower() != Config.UpdateInfoFilename && LikeString(fileName, "pkg*.*.*.*.zip", CompareMethod.Text))
|
||||
{
|
||||
var appVersion = new ApplicationVersion();
|
||||
bool allowAdd = true;
|
||||
|
||||
fileName = Path.GetFileNameWithoutExtension(fileName);
|
||||
fileName = fileName.Substring(3);
|
||||
|
||||
// Get alpha/beta/rc value
|
||||
{
|
||||
int indexAlpha, indexBeta, indexRC, indexRelease;
|
||||
indexAlpha = fileName.IndexOf(PKG_FILENAME_ALPHADEFINITION);
|
||||
indexBeta = fileName.IndexOf(PKG_FILENAME_BETADEFINITION);
|
||||
indexRC = fileName.IndexOf(PKG_FILENAME_RCDEFINITION);
|
||||
indexRelease = fileName.IndexOf(PKG_FILENAME_RELEASEDEFINITION);
|
||||
|
||||
int indexDef;
|
||||
string pkgFilenameDef;
|
||||
if (indexAlpha > -1)
|
||||
{
|
||||
indexDef = indexAlpha;
|
||||
pkgFilenameDef = PKG_FILENAME_ALPHADEFINITION;
|
||||
}
|
||||
else if (indexBeta > -1)
|
||||
{
|
||||
indexDef = indexBeta;
|
||||
pkgFilenameDef = PKG_FILENAME_BETADEFINITION;
|
||||
}
|
||||
else if (indexRC > -1)
|
||||
{
|
||||
indexDef = indexRC;
|
||||
pkgFilenameDef = PKG_FILENAME_RCDEFINITION;
|
||||
}
|
||||
else if (indexRelease > -1)
|
||||
{
|
||||
indexDef = indexRelease;
|
||||
pkgFilenameDef = PKG_FILENAME_RELEASEDEFINITION;
|
||||
}
|
||||
else
|
||||
{
|
||||
indexDef = -1;
|
||||
pkgFilenameDef = null;
|
||||
}
|
||||
|
||||
if (indexDef > -1)
|
||||
{
|
||||
// Get def from filename
|
||||
var def = fileName.Substring(indexDef);
|
||||
fileName = fileName.Remove(indexDef);
|
||||
|
||||
// Get channel
|
||||
switch (pkgFilenameDef)
|
||||
{
|
||||
case PKG_FILENAME_ALPHADEFINITION:
|
||||
appVersion.Channel = Channels.Alpha;
|
||||
break;
|
||||
case PKG_FILENAME_BETADEFINITION:
|
||||
appVersion.Channel = Channels.Beta;
|
||||
break;
|
||||
case PKG_FILENAME_RCDEFINITION:
|
||||
appVersion.Channel = Channels.PreRelease;
|
||||
break;
|
||||
case PKG_FILENAME_RELEASEDEFINITION:
|
||||
appVersion.Channel = Channels.Stable;
|
||||
break;
|
||||
}
|
||||
|
||||
// Get build
|
||||
var defBuild = def.Substring(pkgFilenameDef.Length);
|
||||
appVersion.Build = Convert.ToInt32(defBuild);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set to default
|
||||
appVersion.Build = 1;
|
||||
appVersion.Channel = Channels.Stable;
|
||||
}
|
||||
}
|
||||
|
||||
// Get version
|
||||
if (Version.TryParse(fileName, out Version version))
|
||||
appVersion.Version = version;
|
||||
else
|
||||
allowAdd = false;
|
||||
|
||||
if (allowAdd)
|
||||
pkgs.Add(appVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs;
|
||||
}
|
||||
|
||||
public async Task<bool> DeletePackage(ApplicationVersion version)
|
||||
{
|
||||
var fileName = BuildPackageFilename(version);
|
||||
var response = await client.Delete(fileName);
|
||||
return response.IsSuccessful;
|
||||
}
|
||||
|
||||
public async Task<bool> UploadPackage(string filePath, ApplicationVersion version)
|
||||
{
|
||||
bool success;
|
||||
var fileName = BuildPackageFilename(version);
|
||||
|
||||
// Upload
|
||||
var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
var response = await client.PutFile(fileName, fs);
|
||||
fs.Close();
|
||||
success = response.IsSuccessful;
|
||||
|
||||
// Generate public downloadlink
|
||||
if (success)
|
||||
{
|
||||
var pkgInfo = GetOrCreateUpdatePackageInfo(version);
|
||||
pkgInfo.Packagelink = Config.PublicPackageBaseURL + fileName;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
private string BuildPackageFilename(ApplicationVersion version)
|
||||
{
|
||||
// Build channel/build definition of filename
|
||||
string def = string.Empty;
|
||||
switch (version.Channel)
|
||||
{
|
||||
case Channels.Alpha:
|
||||
def = PKG_FILENAME_ALPHADEFINITION + version.Build;
|
||||
break;
|
||||
case Channels.Stable:
|
||||
if (version.Build != 1)
|
||||
def = PKG_FILENAME_RELEASEDEFINITION + version.Build;
|
||||
break;
|
||||
case Channels.PreRelease:
|
||||
def = PKG_FILENAME_RCDEFINITION + version.Build;
|
||||
break;
|
||||
case Channels.Beta:
|
||||
def = PKG_FILENAME_BETADEFINITION + version.Build;
|
||||
break;
|
||||
}
|
||||
|
||||
// Build filename
|
||||
var fileName = string.Format(PKG_FILENAME_TEMPLATE, version.Version, def);
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private UpdatePackageInfo GetOrCreateUpdatePackageInfo(ApplicationVersion version)
|
||||
{
|
||||
var info = GetUpdatePackageInfo(version);
|
||||
|
||||
info ??= CreateUpdatePackageInfo(version);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public UpdatePackageInfo GetUpdatePackageInfo(ApplicationVersion version)
|
||||
{
|
||||
return UpdateInfo.Packages.FirstOrDefault((n) => n.Version == version);
|
||||
}
|
||||
|
||||
private UpdatePackageInfo CreateUpdatePackageInfo(ApplicationVersion version)
|
||||
{
|
||||
var info = new UpdatePackageInfo()
|
||||
{
|
||||
Version = version
|
||||
};
|
||||
UpdateInfo.Packages.Add(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
public (string name, string description, UpdateNotesContentType descriptionType) GetPackageDescription(ApplicationVersion version)
|
||||
{
|
||||
var pkg = GetUpdatePackageInfo(version);
|
||||
if (pkg is object)
|
||||
return (pkg.Name, pkg.Notes.Content, pkg.Notes.ContentType);
|
||||
else
|
||||
return default;
|
||||
}
|
||||
|
||||
public void SetPackageDescription(ApplicationVersion version, string name, string description, UpdateNotesContentType descriptionType)
|
||||
{
|
||||
var pkg = GetOrCreateUpdatePackageInfo(version);
|
||||
if (pkg is object)
|
||||
{
|
||||
pkg.Name = name;
|
||||
pkg.Notes.Content = description;
|
||||
pkg.Notes.ContentType = descriptionType;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ChangePackageVersion(ApplicationVersion currentVersion, ApplicationVersion newVersion)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// Get file names
|
||||
var currentFilename = BuildPackageFilename(currentVersion);
|
||||
var newFilename = BuildPackageFilename(newVersion);
|
||||
|
||||
// Move
|
||||
var response = await client.Move(currentFilename, newFilename);
|
||||
|
||||
// Change package info version, if exists
|
||||
if (response.IsSuccessful)
|
||||
{
|
||||
var pkg = GetUpdatePackageInfo(currentVersion);
|
||||
if (pkg is object)
|
||||
pkg.Version = newVersion;
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
UpdateInfo = new();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user