Files
RobustToolbox/Robust.Client/Upload/Commands/UploadFileCommand.cs
T
Pieter-Jan Briers 83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

60 lines
1.9 KiB
C#

using System.IO;
using Robust.Client.UserInterface;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.IoC;
using Robust.Shared.Upload;
using Robust.Shared.Utility;
namespace Robust.Client.Upload.Commands;
public sealed partial class UploadFileCommand : IConsoleCommand
{
[Dependency] private IConfigurationManager _cfgManager = default!;
[Dependency] private IFileDialogManager _dialog = default!;
[Dependency] private NetworkResourceManager _netRes = default!;
public string Command => "uploadfile";
public string Description => "Uploads a resource to the server.";
public string Help => $"{Command} [relative path for the resource]";
public async void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (!_cfgManager.GetCVar(CVars.ResourceUploadingEnabled))
{
shell.WriteError("Network Resource Uploading is currently disabled by the server.");
return;
}
if (args.Length != 1)
{
shell.WriteError("Wrong number of arguments!");
return;
}
var path = new ResPath(args[0]).ToRelativePath();
var filters = new FileDialogFilters(new FileDialogFilters.Group(path.Extension));
await using var file = await _dialog.OpenFile(filters, FileAccess.Read);
if (file == null)
{
shell.WriteError("Error picking file!");
return;
}
var sizeLimit = _cfgManager.GetCVar(CVars.ResourceUploadingLimitMb);
if (sizeLimit > 0f && file.Length * SharedNetworkResourceManager.BytesToMegabytes > sizeLimit)
{
shell.WriteError($"File above the current size limit! It must be smaller than {sizeLimit} MB.");
return;
}
var data = file.CopyToArray();
_netRes.UploadResources([(path, data)]);
}
}