From 2c630a5ba9cfb63b3b4d95dfcf7dd19c73afb1ec Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 30 Oct 2024 12:34:17 -0400 Subject: [PATCH] Added 'CopyToTarget' command --- BeefLibs/corlib/src/IO/Directory.bf | 17 ++++++++ IDE/src/ScriptManager.bf | 61 ++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/BeefLibs/corlib/src/IO/Directory.bf b/BeefLibs/corlib/src/IO/Directory.bf index 7a4abb6e..d815fb9c 100644 --- a/BeefLibs/corlib/src/IO/Directory.bf +++ b/BeefLibs/corlib/src/IO/Directory.bf @@ -139,6 +139,23 @@ namespace System.IO return FileEnumerator(useStr, findFileData); } + public static FileEnumerator Enumerate(StringView dirPath) + { + let searchStr = scope String(); + searchStr.Append(dirPath); + searchStr.Append("/*"); + return Enumerate(searchStr, .Directories | .Files); + } + + public static FileEnumerator Enumerate(StringView dirPath, StringView wildcard) + { + let searchStr = scope String(); + searchStr.Append(dirPath); + searchStr.Append("/"); + searchStr.Append(wildcard); + return Enumerate(searchStr, .Directories | .Files); + } + public static FileEnumerator EnumerateDirectories(StringView dirPath) { let searchStr = scope String(); diff --git a/IDE/src/ScriptManager.bf b/IDE/src/ScriptManager.bf index d4a32683..5967fb5e 100644 --- a/IDE/src/ScriptManager.bf +++ b/IDE/src/ScriptManager.bf @@ -1300,8 +1300,7 @@ namespace IDE gApp.mProjectPanel.[Friend]RemoveSelectedItems(false); } - [IDECommand] - public void CopyToDependents(String srcPath) + void DoCopyToTarget(String srcPath, bool onlyDependents) { let depProject = GetProject(); if (depProject == null) @@ -1312,7 +1311,8 @@ namespace IDE for (let checkProject in gApp.mWorkspace.mProjects) { - if (checkProject.HasDependency(depProject.mProjectName)) + if ((checkProject.HasDependency(depProject.mProjectName)) || + ((checkProject == depProject) && (!onlyDependents))) { List targetPaths = scope .(); defer ClearAndDeleteItems(targetPaths); @@ -1332,13 +1332,27 @@ namespace IDE String targetDirPath = scope .(); Path.GetDirectoryPath(targetPaths[0], targetDirPath); - bool CopyFile(String srcPath) + bool CopyFile(StringView srcPath, StringView destPath) { - String fileName = scope .(); - Path.GetFileName(srcPath, fileName); + if (Directory.Exists(srcPath)) + { + if (Directory.CreateDirectory(destPath) case .Err) + return false; - String destPath = scope .(); - Path.GetAbsolutePath(fileName, targetDirPath, destPath); + for (let entry in Directory.Enumerate(srcPath)) + { + String foundPath = scope .(); + entry.GetFilePath(foundPath); + String subDestPath = scope .(); + subDestPath.Append(destPath); + subDestPath.Append('/'); + entry.GetFileName(subDestPath); + if (!CopyFile(foundPath, subDestPath)) + return false; + } + + return true; + } if (File.CopyIfNewer(srcPath, destPath) case .Err) { @@ -1348,6 +1362,12 @@ namespace IDE return true; } + if ((srcPath.EndsWith('/')) || (srcPath.EndsWith('\\'))) + srcPath.RemoveFromEnd(1); + + String fileName = scope .(); + Path.GetFileName(srcPath, fileName); + if (srcPath.Contains('*')) { String dirPath = scope .(); @@ -1359,13 +1379,22 @@ namespace IDE { String foundPath = scope .(); entry.GetFilePath(foundPath); - if (!CopyFile(foundPath)) + + String subDestPath = scope .(); + subDestPath.Append(targetDirPath); + subDestPath.Append('/'); + entry.GetFileName(subDestPath); + + if (!CopyFile(foundPath, subDestPath)) return; } } else { - if (!CopyFile(srcPath)) + String destPath = scope .(); + Path.GetAbsolutePath(fileName, targetDirPath, destPath); + + if (!CopyFile(srcPath, destPath)) return; } } @@ -1373,6 +1402,18 @@ namespace IDE } } + [IDECommand] + public void CopyToDependents(String srcPath) + { + DoCopyToTarget(srcPath, true); + } + + [IDECommand] + public void CopyToTarget(String srcPath) + { + DoCopyToTarget(srcPath, false); + } + [IDECommand] public void ExecuteRaw(String cmd) {