From 855e1150495ea755c2c752ca972d0420c4aa2a2b Mon Sep 17 00:00:00 2001 From: Mox <977898+MoxieWhimsy@users.noreply.github.com> Date: Tue, 9 May 2023 22:52:36 -0400 Subject: [PATCH 1/4] Feat: Copy several files to destination directory (optionally) --- Editor/IO/Files/CopyFileToDirectory.cs | 27 ------------- Editor/IO/Files/CopyFilesToDirectory.cs | 40 +++++++++++++++++++ ...y.cs.meta => CopyFilesToDirectory.cs.meta} | 0 3 files changed, 40 insertions(+), 27 deletions(-) delete mode 100644 Editor/IO/Files/CopyFileToDirectory.cs create mode 100644 Editor/IO/Files/CopyFilesToDirectory.cs rename Editor/IO/Files/{CopyFileToDirectory.cs.meta => CopyFilesToDirectory.cs.meta} (100%) diff --git a/Editor/IO/Files/CopyFileToDirectory.cs b/Editor/IO/Files/CopyFileToDirectory.cs deleted file mode 100644 index ed8b734..0000000 --- a/Editor/IO/Files/CopyFileToDirectory.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using UniTools.Build; -using UnityEditor; -using UnityEngine; - -namespace UniTools.Build -{ - [CreateAssetMenu( - fileName = nameof(CopyFileToDirectory), - menuName = MenuPaths.IO + nameof(CopyFileToDirectory) - )] - public sealed class CopyFileToDirectory : BuildStep - { - [SerializeField] private PathProperty m_filePath = default; - [SerializeField] private PathProperty m_destination = default; - - public override async Task Execute() - { - string fileName = Path.GetFileName(m_filePath.ToString()); - string dest = Path.Combine(m_destination.ToString(), fileName); - FileUtil.DeleteFileOrDirectory(dest); - FileUtil.CopyFileOrDirectory(m_filePath.ToString(), dest); - await Task.CompletedTask; - } - } -} \ No newline at end of file diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs b/Editor/IO/Files/CopyFilesToDirectory.cs new file mode 100644 index 0000000..3902a94 --- /dev/null +++ b/Editor/IO/Files/CopyFilesToDirectory.cs @@ -0,0 +1,40 @@ +using System.IO; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; + +namespace UniTools.Build +{ + [CreateAssetMenu( + fileName = nameof(CopyFilesToDirectory), + menuName = MenuPaths.IO + nameof(CopyFilesToDirectory) + )] + public sealed class CopyFilesToDirectory : BuildStep + { + [SerializeField] private PathProperty[] m_filePaths = default; + [System.Obsolete, HideInInspector] + [SerializeField] private PathProperty m_filePath = default; + [SerializeField] private PathProperty m_destination = default; + + public override async Task Execute() + { + foreach (var filePath in m_filePaths) + { + string fileName = Path.GetFileName(filePath.ToString()); + string dest = Path.Combine(m_destination.ToString(), fileName); + FileUtil.DeleteFileOrDirectory(dest); + FileUtil.CopyFileOrDirectory(filePath.ToString(), dest); + } + + await Task.CompletedTask; + } + + private void OnValidate() + { + if (m_filePaths.Length == 0 && !string.IsNullOrEmpty(m_filePath.ToString())) + { + m_filePaths = new[] { m_filePath }; + } + } + } +} \ No newline at end of file diff --git a/Editor/IO/Files/CopyFileToDirectory.cs.meta b/Editor/IO/Files/CopyFilesToDirectory.cs.meta similarity index 100% rename from Editor/IO/Files/CopyFileToDirectory.cs.meta rename to Editor/IO/Files/CopyFilesToDirectory.cs.meta From 9a6f023835b274e9469f01a365b244fba7b86daf Mon Sep 17 00:00:00 2001 From: Mox <977898+MoxieWhimsy@users.noreply.github.com> Date: Fri, 24 May 2024 23:30:10 -0400 Subject: [PATCH 2/4] Revert "Feat: Copy several files to destination directory (optionally)" This reverts commit 855e1150495ea755c2c752ca972d0420c4aa2a2b. --- Editor/IO/Files/CopyFileToDirectory.cs | 27 +++++++++++++ ...ry.cs.meta => CopyFileToDirectory.cs.meta} | 0 Editor/IO/Files/CopyFilesToDirectory.cs | 40 ------------------- 3 files changed, 27 insertions(+), 40 deletions(-) create mode 100644 Editor/IO/Files/CopyFileToDirectory.cs rename Editor/IO/Files/{CopyFilesToDirectory.cs.meta => CopyFileToDirectory.cs.meta} (100%) delete mode 100644 Editor/IO/Files/CopyFilesToDirectory.cs diff --git a/Editor/IO/Files/CopyFileToDirectory.cs b/Editor/IO/Files/CopyFileToDirectory.cs new file mode 100644 index 0000000..ed8b734 --- /dev/null +++ b/Editor/IO/Files/CopyFileToDirectory.cs @@ -0,0 +1,27 @@ +using System.IO; +using System.Threading.Tasks; +using UniTools.Build; +using UnityEditor; +using UnityEngine; + +namespace UniTools.Build +{ + [CreateAssetMenu( + fileName = nameof(CopyFileToDirectory), + menuName = MenuPaths.IO + nameof(CopyFileToDirectory) + )] + public sealed class CopyFileToDirectory : BuildStep + { + [SerializeField] private PathProperty m_filePath = default; + [SerializeField] private PathProperty m_destination = default; + + public override async Task Execute() + { + string fileName = Path.GetFileName(m_filePath.ToString()); + string dest = Path.Combine(m_destination.ToString(), fileName); + FileUtil.DeleteFileOrDirectory(dest); + FileUtil.CopyFileOrDirectory(m_filePath.ToString(), dest); + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs.meta b/Editor/IO/Files/CopyFileToDirectory.cs.meta similarity index 100% rename from Editor/IO/Files/CopyFilesToDirectory.cs.meta rename to Editor/IO/Files/CopyFileToDirectory.cs.meta diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs b/Editor/IO/Files/CopyFilesToDirectory.cs deleted file mode 100644 index 3902a94..0000000 --- a/Editor/IO/Files/CopyFilesToDirectory.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using UnityEditor; -using UnityEngine; - -namespace UniTools.Build -{ - [CreateAssetMenu( - fileName = nameof(CopyFilesToDirectory), - menuName = MenuPaths.IO + nameof(CopyFilesToDirectory) - )] - public sealed class CopyFilesToDirectory : BuildStep - { - [SerializeField] private PathProperty[] m_filePaths = default; - [System.Obsolete, HideInInspector] - [SerializeField] private PathProperty m_filePath = default; - [SerializeField] private PathProperty m_destination = default; - - public override async Task Execute() - { - foreach (var filePath in m_filePaths) - { - string fileName = Path.GetFileName(filePath.ToString()); - string dest = Path.Combine(m_destination.ToString(), fileName); - FileUtil.DeleteFileOrDirectory(dest); - FileUtil.CopyFileOrDirectory(filePath.ToString(), dest); - } - - await Task.CompletedTask; - } - - private void OnValidate() - { - if (m_filePaths.Length == 0 && !string.IsNullOrEmpty(m_filePath.ToString())) - { - m_filePaths = new[] { m_filePath }; - } - } - } -} \ No newline at end of file From f4b7e9df4592108075f08aa65c4c6650e536a2ff Mon Sep 17 00:00:00 2001 From: Mox <977898+MoxieWhimsy@users.noreply.github.com> Date: Fri, 24 May 2024 23:53:36 -0400 Subject: [PATCH 3/4] Feat: Copy multiple files to destination directory --- Editor/IO/Files/CopyFilesToDirectory.cs | 36 ++++++++++++++++++++ Editor/IO/Files/CopyFilesToDirectory.cs.meta | 11 ++++++ 2 files changed, 47 insertions(+) create mode 100644 Editor/IO/Files/CopyFilesToDirectory.cs create mode 100644 Editor/IO/Files/CopyFilesToDirectory.cs.meta diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs b/Editor/IO/Files/CopyFilesToDirectory.cs new file mode 100644 index 0000000..debc726 --- /dev/null +++ b/Editor/IO/Files/CopyFilesToDirectory.cs @@ -0,0 +1,36 @@ +using System.IO; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; + +namespace UniTools.Build +{ + [CreateAssetMenu( + fileName = nameof(CopyFilesToDirectory), + menuName = MenuPaths.IO + nameof(CopyFilesToDirectory) + )] + public sealed class CopyFilesToDirectory : BuildStep + { + [SerializeField] private PathProperty[] m_sourceFiles = default; + [SerializeField] private PathProperty m_destinationDirectory = default; + + public override async Task Execute() + { + var destinationFolder = m_destinationDirectory.ToString(); + if (!Directory.Exists(destinationFolder)) + { + throw new DirectoryNotFoundException($"{destinationFolder} does not exist!"); + } + + foreach (var filePath in m_sourceFiles) + { + var fileName = Path.GetFileName(filePath.ToString()); + var dest = Path.Combine(destinationFolder, fileName); + FileUtil.DeleteFileOrDirectory(dest); + FileUtil.CopyFileOrDirectory(filePath.ToString(), dest); + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs.meta b/Editor/IO/Files/CopyFilesToDirectory.cs.meta new file mode 100644 index 0000000..c36fd7c --- /dev/null +++ b/Editor/IO/Files/CopyFilesToDirectory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3077c4aac47fe402499d5d4347811199 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From e39ef6097b9ca89ec4cf2ab4d7e62aa42112fadf Mon Sep 17 00:00:00 2001 From: Mox <977898+MoxieWhimsy@users.noreply.github.com> Date: Sat, 25 May 2024 00:26:58 -0400 Subject: [PATCH 4/4] Added source directory property --- Editor/IO/Files/CopyFilesToDirectory.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs b/Editor/IO/Files/CopyFilesToDirectory.cs index debc726..b900541 100644 --- a/Editor/IO/Files/CopyFilesToDirectory.cs +++ b/Editor/IO/Files/CopyFilesToDirectory.cs @@ -11,23 +11,33 @@ namespace UniTools.Build )] public sealed class CopyFilesToDirectory : BuildStep { + [SerializeField] private PathProperty m_sourceDirectory = default; [SerializeField] private PathProperty[] m_sourceFiles = default; [SerializeField] private PathProperty m_destinationDirectory = default; public override async Task Execute() { + var sourceFolder = m_sourceDirectory.ToString(); + var hasNoSourceFolder = string.IsNullOrEmpty(sourceFolder); var destinationFolder = m_destinationDirectory.ToString(); + + if (!hasNoSourceFolder && !Directory.Exists(sourceFolder)) + { + throw new DirectoryNotFoundException($"Source folder: {sourceFolder} does not exist!"); + } if (!Directory.Exists(destinationFolder)) { - throw new DirectoryNotFoundException($"{destinationFolder} does not exist!"); + throw new DirectoryNotFoundException($"Destination folder {destinationFolder} does not exist!"); } - foreach (var filePath in m_sourceFiles) + foreach (var sourceFile in m_sourceFiles) { - var fileName = Path.GetFileName(filePath.ToString()); - var dest = Path.Combine(destinationFolder, fileName); - FileUtil.DeleteFileOrDirectory(dest); - FileUtil.CopyFileOrDirectory(filePath.ToString(), dest); + var filePath = sourceFile.ToString(); + var fileName = Path.GetFileName(filePath); + var source = hasNoSourceFolder ? filePath : Path.Combine(sourceFolder, filePath); + var destination = Path.Combine(destinationFolder, fileName); + FileUtil.DeleteFileOrDirectory(destination); + FileUtil.CopyFileOrDirectory(source, destination); } await Task.CompletedTask;