Skip to content

Commit

Permalink
Fix upload not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Feb 19, 2024
1 parent 2920139 commit e88999e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -8,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>1.1.0</PackageVersion>
<Authors>diogotr7</Authors>
<PackageId>ArtemisRGB.Tools.PluginUploader</PackageId>
<Description>ArtemisRGB plugin uploader tool</Description>
Expand All @@ -21,5 +20,4 @@
<ItemGroup>
<PackageReference Include="CliFx" Version="2.3.5" />
</ItemGroup>

</Project>
20 changes: 11 additions & 9 deletions src/Artemis.Tools.PluginUploader/Commands/Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async ValueTask ExecuteAsync(IConsole console)
{
remotePluginInfo = await workshopClient.GetPluginInfo(localPluginInfo.Guid);
}
catch
catch (PluginNotFoundException)
{
//the plugin has never been published to the workshop. tell the user and exit
await console.Output.WriteLineAsync("Plugin has never been published to the workshop, skipping");
Expand All @@ -50,18 +50,20 @@ public async ValueTask ExecuteAsync(IConsole console)
await console.Output.WriteLineAsync($"Local version {localPluginInfo.Version} is not newer than remote version {remoteVersion}");
return;
}

await console.Output.WriteLineAsync($"Uploading {localPluginInfo.Name} v{localPluginInfo.Version}...");

using var zipStream = new MemoryStream();
using var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, true);
var files = Directory.EnumerateFiles(PluginFolder, "*", SearchOption.AllDirectories);
foreach (var file in files)
using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
{
var entry = archive.CreateEntry(Path.GetRelativePath(PluginFolder, file));
await using var entryStream = entry.Open();
await using var fileStream = File.OpenRead(file);
await fileStream.CopyToAsync(entryStream);
var files = Directory.EnumerateFiles(PluginFolder, "*", SearchOption.AllDirectories);
foreach (var file in files)
{
var entry = archive.CreateEntry(Path.GetRelativePath(PluginFolder, file));
await using var entryStream = entry.Open();
await using var fileStream = File.OpenRead(file);
await fileStream.CopyToAsync(entryStream);
}
}

zipStream.Seek(0, SeekOrigin.Begin);
Expand Down
11 changes: 11 additions & 0 deletions src/Artemis.Tools.PluginUploader/PluginNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Artemis.Tools.PluginUploader;

public class PluginNotFoundException : Exception
{
public Guid PluginGuid { get; }

public PluginNotFoundException(Guid pluginGuid)
{
PluginGuid = pluginGuid;
}
}
5 changes: 3 additions & 2 deletions src/Artemis.Tools.PluginUploader/WorkshopClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ public async Task<Items> GetPluginInfo(Guid pluginGuid)
var result = await GetPluginInfos(pluginGuid);
var pluginInfo = result.FirstOrDefault(x => x.pluginGuid == pluginGuid.ToString());
if (pluginInfo == null)
throw new Exception("Plugin not found");
throw new PluginNotFoundException(pluginGuid);

return pluginInfo;
}

public async Task PublishPlugin(Stream pluginZip, long entryId, CancellationToken cancellationToken = default)
{
pluginZip.Seek(0, SeekOrigin.Begin);
var content = new MultipartFormDataContent();
var streamContent = new StreamContent(pluginZip);
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");

var content = new MultipartFormDataContent();
content.Add(streamContent, "file", "plugin.zip");

var response = await _httpClient.PostAsync($"releases/upload/{entryId}", content, cancellationToken);
Expand Down

0 comments on commit e88999e

Please sign in to comment.