Skip to content

Commit

Permalink
Added copyDirectory script wrapper (#655)
Browse files Browse the repository at this point in the history
* Added copyDirectoryTo script wrapper

* Renamed copyDirectoryTo to copyDirectory
  • Loading branch information
davidhealey authored Jan 19, 2025
1 parent f85f76a commit bbf5b5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 19 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ struct ScriptingObjects::ScriptFile::Wrapper
API_METHOD_WRAPPER_1(ScriptFile, rename);
API_METHOD_WRAPPER_1(ScriptFile, move);
API_METHOD_WRAPPER_1(ScriptFile, copy);
API_METHOD_WRAPPER_1(ScriptFile, copyDirectory);
API_METHOD_WRAPPER_2(ScriptFile, isChildOf);
API_METHOD_WRAPPER_1(ScriptFile, isSameFileAs);
API_METHOD_WRAPPER_1(ScriptFile, toReferenceString);
Expand Down Expand Up @@ -281,6 +282,7 @@ ScriptingObjects::ScriptFile::ScriptFile(ProcessorWithScriptingContent* p, const
ADD_API_METHOD_1(rename);
ADD_API_METHOD_1(move);
ADD_API_METHOD_1(copy);
ADD_API_METHOD_1(copyDirectory);
ADD_API_METHOD_0(show);
ADD_API_METHOD_2(isChildOf);
ADD_API_METHOD_1(isSameFileAs);
Expand Down Expand Up @@ -801,6 +803,23 @@ bool ScriptingObjects::ScriptFile::copy(var target)
RETURN_IF_NO_THROW(false);
}

bool ScriptingObjects::ScriptFile::copyDirectory(var target)
{
if (auto sf = dynamic_cast<ScriptFile*>(target.getObject()))
{
if (!sf->f.isDirectory())
reportScriptError("target is not a directory");

return f.copyDirectoryTo(sf->f);
}
else
{
reportScriptError("target is not a directory");
}

RETURN_IF_NO_THROW(false);
}

juce::var ScriptingObjects::ScriptFile::loadAsAudioFile() const
{
double unused = 0;
Expand Down
7 changes: 5 additions & 2 deletions hi_scripting/scripting/api/ScriptingApiObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,15 @@ namespace ScriptingObjects
/** Renames the file. */
bool rename(String newName);

/** Moves the file. */
/** Moves the file. The target isn't the directory to put it in, it's the actual file to create. */
bool move(var target);

/** Copies the file. */
/** Copies the file. The target isn't the directory to put it in, it's the actual file to create. */
bool copy(var target);

/** Recursively copies the directory. The target is the actual directory to create, not the directory into which the new one should be placed. */
bool copyDirectory(var target);

/** Loads the given file as audio file. */
var loadAsAudioFile() const;

Expand Down

0 comments on commit bbf5b5b

Please sign in to comment.