]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Adds uploadfolder command (#15102)
authorZoldorf <silvertorch5@gmail.com>
Wed, 5 Apr 2023 23:37:05 +0000 (17:37 -0600)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2023 23:37:05 +0000 (17:37 -0600)
Content.Client/Administration/Commands/UploadFolder.cs [new file with mode: 0644]
Resources/Locale/en-US/administration/commands/uploadfolder.ftl [new file with mode: 0644]
Resources/clientCommandPerms.yml

diff --git a/Content.Client/Administration/Commands/UploadFolder.cs b/Content.Client/Administration/Commands/UploadFolder.cs
new file mode 100644 (file)
index 0000000..02b094e
--- /dev/null
@@ -0,0 +1,76 @@
+using System.IO;
+using Content.Shared.Administration;
+using Content.Shared.CCVar;
+using Robust.Shared.Configuration;
+using Robust.Shared.Console;
+using Robust.Shared.ContentPack;
+using Robust.Shared.Network;
+using Robust.Shared.Utility;
+
+namespace Content.Client.Administration.Commands;
+
+public sealed class UploadFolder : IConsoleCommand
+{
+    public string Command => "uploadfolder";
+    public string Description => Loc.GetString("uploadfolder-command-description");
+    public string Help => Loc.GetString("uploadfolder-command-help");
+
+    private static readonly ResourcePath BaseUploadFolderPath = new("/UploadFolder");
+
+    [Dependency] private IResourceManager _resourceManager = default!;
+    [Dependency] private IConfigurationManager _configManager = default!;
+
+    public async void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        var fileCount = 0;
+
+
+        if (!_configManager.GetCVar(CCVars.ResourceUploadingEnabled))
+        {
+            shell.WriteError( Loc.GetString("uploadfolder-command-resource-upload-disabled"));
+            return;
+        }
+
+        if (args.Length != 1)
+        {
+            shell.WriteError( Loc.GetString("uploadfolder-command-wrong-args"));
+            shell.WriteLine( Loc.GetString("uploadfolder-command-help"));
+            return;
+        }
+        var folderPath = new ResourcePath(BaseUploadFolderPath + $"/{args[0]}");
+
+        if (!_resourceManager.UserData.Exists(folderPath.ToRootedPath()))
+        {
+            shell.WriteError( Loc.GetString("uploadfolder-command-folder-not-found",("folder", folderPath)));
+            return; // bomb out if the folder doesnt exist in /UploadFolder
+        }
+
+        //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);
+            {
+                var sizeLimit = _configManager.GetCVar(CCVars.ResourceUploadingLimitMb);
+                if (sizeLimit > 0f && filestream.Length * SharedNetworkResourceManager.BytesToMegabytes > sizeLimit)
+                {
+                    shell.WriteError( Loc.GetString("uploadfolder-command-file-too-big", ("filename",filepath), ("sizeLimit",sizeLimit)));
+                    return;
+                }
+
+                var data = filestream.CopyToArray();
+
+                var netManager = IoCManager.Resolve<INetManager>();
+                var msg = netManager.CreateNetMessage<NetworkResourceUploadMessage>();
+
+                msg.RelativePath = new ResourcePath($"{filepath.ToString().Remove(0,14)}"); //removes /UploadFolder/ from path
+                msg.Data = data;
+
+                netManager.ClientSendMessage(msg);
+                fileCount++;
+            }
+        }
+
+        shell.WriteLine( Loc.GetString("uploadfolder-command-success",("fileCount",fileCount)));
+    }
+}
diff --git a/Resources/Locale/en-US/administration/commands/uploadfolder.ftl b/Resources/Locale/en-US/administration/commands/uploadfolder.ftl
new file mode 100644 (file)
index 0000000..9d2ec1b
--- /dev/null
@@ -0,0 +1,7 @@
+uploadfolder-command-description = Uploads a folder from your UserData folder recursively to the server contentDB.
+uploadfolder-command-help = uploadfolder [folder you want to upload in userdata/UploadFolder]
+uploadfolder-command-wrong-args = Wrong number of arguments!
+uploadfolder-command-folder-not-found = Folder {$folder} not found!
+uploadfolder-command-resource-upload-disabled = Network Resource Uploading is currently disabled. check Server CVars.
+uploadfolder-command-file-too-big = File {$filename} above the current size limit! It must be smaller than {$sizeLimit} MB. skipping.
+uploadfolder-command-success = Uploaded {$fileCount} files
index 5dccc849edffc58e421e4492a18b3229c06ae497..9c5a55d4039a615aea62017a33d1a6775cdbed8c 100644 (file)
@@ -71,3 +71,4 @@
   Commands:
     - uploadfile
     - loadprototype
+    - uploadfolder