Skip to content

Commit

Permalink
Updated to newer KekUploadLibrary and added new option for uploading …
Browse files Browse the repository at this point in the history
…without chunk hashing
  • Loading branch information
CraftingDragon007 committed Jul 5, 2023
1 parent 5f0426b commit 3987b90
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 197 deletions.
15 changes: 7 additions & 8 deletions KekUploadCLIClient/DownloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public class DownloadCommand : ConsoleCommand
private const int Success = 0;
private const int Failure = 2;

private string? FileLocation { get; set; }
private string? DownloadUrl { get; set; }

public DownloadCommand()
{
IsCommand("Download", "Download a File");
HasLongDescription("Can be used to download a File from a Server running KotwOSS/UploadServer");
HasRequiredOption("u|url=", "The base Download Url from the file", p => DownloadUrl = p);
HasRequiredOption("f|file=", "The path to save the file to", p => FileLocation = p);
HasOption("s|silent=", "If the command should be executed silently", t =>{});
HasOption("s|silent=", "If the command should be executed silently", t => { });
}

private string? FileLocation { get; set; }
private string? DownloadUrl { get; set; }

public override int Run(string[] remainingArguments)
{
if (DownloadUrl != null && FileLocation != null)
Expand All @@ -32,29 +32,28 @@ public override int Run(string[] remainingArguments)
client.ProgressChangedEvent += (size, downloaded, percentage) =>
{
if (size != null)
{
Program.WriteLine("Downloaded " + Utils.SizeToString(downloaded) + " of " +
Utils.SizeToString((long) size) + "!");
}
else Program.WriteLine("Downloaded " + Utils.SizeToString(downloaded) + "!");

progressBar.SetProgress((float) (percentage ?? 0));
};
try
{
client.DownloadFile(DownloadUrl, FileLocation);
client.Download(DownloadUrl, new DownloadItem(FileLocation));
Program.WriteLine("Successfully downloaded file to: " + Path.GetFullPath(FileLocation));
return Success;
}
catch (KekException e)
{
Program.WriteLine("Could not download the file! Are you sure you entered a correct url?");
Program.WriteLine("Exception: " + e.Message);
if(e.Error!=null)
if (e.Error != null)
Program.WriteLine("Server Response Error: " + e.Error);
return Failure;
}
}

Program.WriteLine("Please enter a valid url and a file location!");
return Failure;
}
Expand Down
6 changes: 3 additions & 3 deletions KekUploadCLIClient/KekUploadCLIClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyVersion>1.0.0.4</AssemblyVersion>
<AssemblyVersion>1.0.0.5</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CraftingDragon007.KekUploadLibrary" Version="1.0.0.4" />
<PackageReference Include="ManyConsole" Version="2.0.1" />
<PackageReference Include="CraftingDragon007.KekUploadLibrary" Version="1.0.0.6"/>
<PackageReference Include="ManyConsole" Version="2.0.1"/>
</ItemGroup>

</Project>
67 changes: 34 additions & 33 deletions KekUploadCLIClient/Program.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
using System.Text;
using ManyConsole;

namespace KekUploadCLIClient
namespace KekUploadCLIClient;

public class Program
{
public class Program
{
public const string Version = "1.0.0.4";
public const string Version = "1.0.0.5";

private static TextWriter? _console;
private static TextWriter? _console;

public static int Main(string[] args)
{
var builder = new StringBuilder();
foreach (var s in args)
{
builder.Append(s);
builder.Append(" ");
}

var commands = GetCommands();
if (builder.ToString().ToLower().Contains(" -s true") || builder.ToString().ToLower().Contains(" --silent true"))
{
Silent = true;
_console = TextWriter.Null;
return ConsoleCommandDispatcher.DispatchCommand(commands, args, TextWriter.Null);
}
Silent = false;
_console = Console.Out;
Console.WriteLine("KekUploadCLIClient v" + Version + " made by CraftingDragon007 and KekOnTheWorld.");
return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
}

public static IEnumerable<ConsoleCommand> GetCommands()
public static bool Silent { get; private set; }

public static int Main(string[] args)
{
var builder = new StringBuilder();
foreach (var s in args)
{
return ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
builder.Append(s);
builder.Append(' ');
}

public static bool Silent { get; private set; }
public static void WriteLine(string text)
var commands = GetCommands();
if (builder.ToString().ToLower().Contains(" -s true") ||
builder.ToString().ToLower().Contains(" --silent true"))
{
_console?.WriteLine(text);
Silent = true;
_console = TextWriter.Null;
return ConsoleCommandDispatcher.DispatchCommand(commands, args, TextWriter.Null);
}

Silent = false;
_console = Console.Out;
Console.WriteLine("KekUploadCLIClient v" + Version + " made by CraftingDragon007 and KekOnTheWorld.");
return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
}

public static IEnumerable<ConsoleCommand> GetCommands()
{
return ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
}
}

public static void WriteLine(string text)
{
_console?.WriteLine(text);
}
}
Loading

0 comments on commit 3987b90

Please sign in to comment.