mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Update uploadfile dependencies (#4849)
* Update uploadfile dependencies Also removed the 1 warning in there. * Thanks rider
This commit is contained in:
@@ -11,15 +11,17 @@ namespace Robust.Client.Upload.Commands;
|
||||
|
||||
public sealed class UploadFileCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
|
||||
[Dependency] private readonly IFileDialogManager _dialog = default!;
|
||||
[Dependency] private readonly INetManager _netManager = 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)
|
||||
{
|
||||
var cfgMan = IoCManager.Resolve<IConfigurationManager>();
|
||||
|
||||
if (!cfgMan.GetCVar(CVars.ResourceUploadingEnabled))
|
||||
if (!_cfgManager.GetCVar(CVars.ResourceUploadingEnabled))
|
||||
{
|
||||
shell.WriteError("Network Resource Uploading is currently disabled by the server.");
|
||||
return;
|
||||
@@ -33,10 +35,8 @@ public sealed class UploadFileCommand : IConsoleCommand
|
||||
|
||||
var path = new ResPath(args[0]).ToRelativePath();
|
||||
|
||||
var dialog = IoCManager.Resolve<IFileDialogManager>();
|
||||
|
||||
var filters = new FileDialogFilters(new FileDialogFilters.Group(path.Extension));
|
||||
await using var file = await dialog.OpenFile(filters);
|
||||
await using var file = await _dialog.OpenFile(filters);
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
@@ -44,7 +44,7 @@ public sealed class UploadFileCommand : IConsoleCommand
|
||||
return;
|
||||
}
|
||||
|
||||
var sizeLimit = cfgMan.GetCVar(CVars.ResourceUploadingLimitMb);
|
||||
var sizeLimit = _cfgManager.GetCVar(CVars.ResourceUploadingLimitMb);
|
||||
|
||||
if (sizeLimit > 0f && file.Length * SharedNetworkResourceManager.BytesToMegabytes > sizeLimit)
|
||||
{
|
||||
@@ -54,12 +54,12 @@ public sealed class UploadFileCommand : IConsoleCommand
|
||||
|
||||
var data = file.CopyToArray();
|
||||
|
||||
var netManager = IoCManager.Resolve<INetManager>();
|
||||
var msg = netManager.CreateNetMessage<NetworkResourceUploadMessage>();
|
||||
var msg = new NetworkResourceUploadMessage
|
||||
{
|
||||
RelativePath = path,
|
||||
Data = data
|
||||
};
|
||||
|
||||
msg.RelativePath = path;
|
||||
msg.Data = data;
|
||||
|
||||
netManager.ClientSendMessage(msg);
|
||||
_netManager.ClientSendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
@@ -13,21 +14,20 @@ namespace Robust.Client.Upload.Commands;
|
||||
|
||||
public sealed class UploadFolderCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private IResourceManager _resourceManager = default!;
|
||||
[Dependency] private IConfigurationManager _configManager = default!;
|
||||
[Dependency] private INetManager _netMan = default!;
|
||||
|
||||
public string Command => "uploadfolder";
|
||||
public string Description => Loc.GetString("uploadfolder-command-description");
|
||||
public string Help => Loc.GetString("uploadfolder-command-help");
|
||||
|
||||
private static readonly ResPath BaseUploadFolderPath = new("/UploadFolder");
|
||||
|
||||
[Dependency] private IResourceManager _resourceManager = default!;
|
||||
[Dependency] private IConfigurationManager _configManager = default!;
|
||||
[Dependency] private INetManager _netMan = default!;
|
||||
|
||||
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var fileCount = 0;
|
||||
|
||||
|
||||
if (!_configManager.GetCVar(CVars.ResourceUploadingEnabled))
|
||||
{
|
||||
shell.WriteError( Loc.GetString("uploadfolder-command-resource-upload-disabled"));
|
||||
@@ -52,8 +52,7 @@ public sealed class UploadFolderCommand : IConsoleCommand
|
||||
//Grab all files in specified folder and upload them
|
||||
foreach (var filepath in _resourceManager.UserData.Find($"{folderPath.ToRelativePath()}/").files )
|
||||
{
|
||||
|
||||
await using var filestream = _resourceManager.UserData.Open(filepath,FileMode.Open);
|
||||
await using var filestream = _resourceManager.UserData.Open(filepath, FileMode.Open);
|
||||
{
|
||||
var sizeLimit = _configManager.GetCVar(CVars.ResourceUploadingLimitMb);
|
||||
if (sizeLimit > 0f && filestream.Length * SharedNetworkResourceManager.BytesToMegabytes > sizeLimit)
|
||||
@@ -64,9 +63,11 @@ public sealed class UploadFolderCommand : IConsoleCommand
|
||||
|
||||
var data = filestream.CopyToArray();
|
||||
|
||||
var msg = _netMan.CreateNetMessage<NetworkResourceUploadMessage>();
|
||||
msg.RelativePath = filepath.RelativeTo(BaseUploadFolderPath);
|
||||
msg.Data = data;
|
||||
var msg = new NetworkResourceUploadMessage
|
||||
{
|
||||
RelativePath = filepath.RelativeTo(BaseUploadFolderPath),
|
||||
Data = data
|
||||
};
|
||||
|
||||
_netMan.ClientSendMessage(msg);
|
||||
fileCount++;
|
||||
|
||||
Reference in New Issue
Block a user