diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/IFileUpload.cs b/EftPatchHelper/EftPatchHelper/Interfaces/IFileUpload.cs index 0910f73..307e052 100644 --- a/EftPatchHelper/EftPatchHelper/Interfaces/IFileUpload.cs +++ b/EftPatchHelper/EftPatchHelper/Interfaces/IFileUpload.cs @@ -9,6 +9,8 @@ namespace EftPatchHelper.Interfaces public interface IFileUpload { public string DisplayName { get; set; } + public string ServiceName { get; set; } + public string HubEntryText { get; set; } public string GetLink(); public Task UploadAsync(IProgress? progress = null); } diff --git a/EftPatchHelper/EftPatchHelper/Model/GoFileUpload.cs b/EftPatchHelper/EftPatchHelper/Model/GoFileUpload.cs index 773d908..8b356ec 100644 --- a/EftPatchHelper/EftPatchHelper/Model/GoFileUpload.cs +++ b/EftPatchHelper/EftPatchHelper/Model/GoFileUpload.cs @@ -10,17 +10,21 @@ namespace EftPatchHelper.Model private GoFileFile _uploadedFile; public string DisplayName { get; set; } + public string ServiceName { get; set; } + public string HubEntryText { get; set; } public GoFileUpload(FileInfo file, string apiToken) { GoFile.ApiToken = apiToken; _file = file; - DisplayName = $"GoFile Upload: {_file.Name}"; + ServiceName = "GoFile"; + DisplayName = $"{ServiceName} Upload: {_file.Name}"; + HubEntryText = $"Download from {ServiceName}"; } public string GetLink() { - return _uploadedFile.Link; + return _uploadedFile.DirectLink; } public async Task UploadAsync(IProgress? progress = null) diff --git a/EftPatchHelper/EftPatchHelper/Model/MegaUpload.cs b/EftPatchHelper/EftPatchHelper/Model/MegaUpload.cs index 1e3a51b..f82e427 100644 --- a/EftPatchHelper/EftPatchHelper/Model/MegaUpload.cs +++ b/EftPatchHelper/EftPatchHelper/Model/MegaUpload.cs @@ -15,6 +15,8 @@ namespace EftPatchHelper.Model private INode _uploadedFile; public string DisplayName { get; set; } + public string ServiceName { get; set; } + public string HubEntryText { get; set; } public MegaUpload(FileInfo file, string email, string password, string mfaKey = null) { @@ -22,7 +24,9 @@ namespace EftPatchHelper.Model _file = file; _email = email; _password = password; - DisplayName = $"Mega Upload: {_file.Name}"; + ServiceName = "Mega"; + DisplayName = $"{ServiceName} Upload: {_file.Name}"; + HubEntryText = $"Download from {ServiceName}"; } private async Task CheckLoginStatus() diff --git a/EftPatchHelper/EftPatchHelper/Model/Options.cs b/EftPatchHelper/EftPatchHelper/Model/Options.cs index 7d72b50..0675008 100644 --- a/EftPatchHelper/EftPatchHelper/Model/Options.cs +++ b/EftPatchHelper/EftPatchHelper/Model/Options.cs @@ -38,5 +38,10 @@ namespace EftPatchHelper.Model /// Whether or not to upload the pather to mega.io /// public bool UploadToMega = false; + + /// + /// List of mirrors to upload to Gitea + /// + public Dictionary MirrorList = new Dictionary(); } } diff --git a/EftPatchHelper/EftPatchHelper/Program.cs b/EftPatchHelper/EftPatchHelper/Program.cs index bd469ed..efbd454 100644 --- a/EftPatchHelper/EftPatchHelper/Program.cs +++ b/EftPatchHelper/EftPatchHelper/Program.cs @@ -39,8 +39,8 @@ namespace EftPatchHelper IFileProcessingTasks fileProcessingTasks, IPatchGenTasks patchGenTasks, IPatchTestingTasks patchTestingTasks, - IReleaseCreator createReleaseTasks, - IUploadTasks uploadTasks + IUploadTasks uploadTasks, + IReleaseCreator createReleaseTasks ) { _settingsTasks = settingsTasks; @@ -59,8 +59,8 @@ namespace EftPatchHelper _fileProcessingTasks.Run(); _patchGenTasks.Run(); _patchTestingTasks.Run(); - _createReleaseTasks.Run(); _uploadTasks.Run(); + _createReleaseTasks.Run(); } private static IHost ConfigureHost(string[] args) diff --git a/EftPatchHelper/EftPatchHelper/Tasks/CreateReleaseTasks.cs b/EftPatchHelper/EftPatchHelper/Tasks/CreateReleaseTasks.cs index c67fa4d..6558666 100644 --- a/EftPatchHelper/EftPatchHelper/Tasks/CreateReleaseTasks.cs +++ b/EftPatchHelper/EftPatchHelper/Tasks/CreateReleaseTasks.cs @@ -5,6 +5,7 @@ using Gitea.Model; using Gitea.Client; using Spectre.Console; using EftPatchHelper.Extensions; +using System.Text.Json; namespace EftPatchHelper.Tasks { @@ -81,6 +82,19 @@ namespace EftPatchHelper.Tasks } } + public bool CreateMirrorList(FileInfo mirrorListFileInfo) + { + List mirrors = _options.MirrorList.Values.ToList(); + + string json = JsonSerializer.Serialize(mirrors, new JsonSerializerOptions() { WriteIndented = true }); + + File.WriteAllText(mirrorListFileInfo.FullName, json); + + mirrorListFileInfo.Refresh(); + + return mirrorListFileInfo.Exists; + } + public void Run() { AnsiConsole.WriteLine(); @@ -93,9 +107,11 @@ namespace EftPatchHelper.Tasks var repo = new RepositoryApi(Configuration.Default); - var release = MakeRelease(repo).ValidateOrExit(); + var fileInfo = new FileInfo(Path.Join(Environment.CurrentDirectory, "mirrors.json")); - var fileInfo = new FileInfo(_options.OutputPatchPath + ".zip"); + CreateMirrorList(fileInfo); + + var release = MakeRelease(repo).ValidateOrExit(); UploadAsset(fileInfo, release, repo); } diff --git a/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs b/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs index d78a39a..01a7cbd 100644 --- a/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs +++ b/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs @@ -62,14 +62,9 @@ namespace EftPatchHelper.Tasks { _options.IgnoreExistingDirectories = new ConfirmationPrompt("Skip existing directories? (you will be prompted if no)").Show(AnsiConsole.Console); - if (!_settings.UsingGitea()) return; - - _options.CreateRelease = new ConfirmationPrompt("Create a release on gitea?").Show(AnsiConsole.Console); - - if(_options.CreateRelease) + if (_settings.UsingGitea()) { - // only allow upload options if the release is not being made - return; + _options.CreateRelease = new ConfirmationPrompt("Create a release on gitea?").Show(AnsiConsole.Console); } if (_settings.UsingMega()) diff --git a/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs b/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs index 618e4a7..b56b1a3 100644 --- a/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs +++ b/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs @@ -24,6 +24,12 @@ namespace EftPatchHelper.Tasks if (!patcherFile.Exists) return false; + if(_settings.UsingGoFile() && _options.UploadToGoFile) + { + var gofile = new GoFileUpload(patcherFile, _settings.GoFileApiKey); + _fileUploads.Add(gofile); + } + if (_settings.UsingMega() && _options.UploadToMega) { var mega = new MegaUpload(patcherFile, _settings.MegaEmail, _settings.MegaPassword); @@ -31,45 +37,17 @@ namespace EftPatchHelper.Tasks _fileUploads.Add(mega); } - if(_settings.UsingGoFile() && _options.UploadToGoFile) - { - var gofile = new GoFileUpload(patcherFile, _settings.GoFileApiKey); - _fileUploads.Add(gofile); - } - return true; } private void CreateHubEntrySource() { - var goFile = _fileUploads.SingleOrDefault(x => x.GetType() == typeof(GoFileUpload)); - var mega = _fileUploads.SingleOrDefault(x => x.GetType() == typeof(MegaUpload)); - - if(goFile == null || mega == null) - { - AnsiConsole.WriteLine("Failed to get required info to create hub entry source"); - return; - } - - var goFileLink = goFile.GetLink(); - var megaLink = mega.GetLink(); - - if(goFileLink == null || megaLink == null) - { - AnsiConsole.WriteLine("Failed to get link for uploaded files"); - return; - } - string output = $"

Downgrade EFT Client files from version {_options.SourceClient.Version} to {_options.TargetClient.Version}

\n


"; - if(_options.UploadToGoFile) + foreach (var pair in _options.MirrorList) { - output += $"\n

Download From GoFile

"; - } - - if(_options.UploadToMega) - { - output += $"\n

Download From Mega

"; + // value is the link, key is the hub entry text + output += $"\n

{pair.Key}

"; } AnsiConsole.WriteLine(output); @@ -124,6 +102,10 @@ namespace EftPatchHelper.Tasks AnsiConsole.MarkupLine($"[red]{pair.Key.DisplayName.EscapeMarkup()} failed[/]"); return false; } + else + { + _options.MirrorList.Add(pair.Key.HubEntryText, pair.Key.GetLink()); + } } return true; @@ -134,10 +116,9 @@ namespace EftPatchHelper.Tasks public void Run() { - if (!_options.CreateRelease) - { - UploadAllFiles().GetAwaiter().GetResult().ValidateOrExit(); - } + if (!_options.UploadToGoFile && !_options.UploadToMega) return; + + UploadAllFiles().GetAwaiter().GetResult().ValidateOrExit(); CreateHubEntrySource(); }