Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added getZippedItemList to return contents of a zip file. Also includ… #688

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ struct ScriptingObjects::ScriptFile::Wrapper
API_METHOD_WRAPPER_1(ScriptFile, toReferenceString);
API_METHOD_WRAPPER_1(ScriptFile, getRelativePathFrom);
API_METHOD_WRAPPER_0(ScriptFile, getNumZippedItems);
API_METHOD_WRAPPER_0(ScriptFile, getZippedItemList);
API_VOID_METHOD_WRAPPER_2(ScriptFile, setReadOnly);
API_VOID_METHOD_WRAPPER_3(ScriptFile, extractZipFile);
API_VOID_METHOD_WRAPPER_0(ScriptFile, show);
Expand Down Expand Up @@ -289,6 +290,7 @@ ScriptingObjects::ScriptFile::ScriptFile(ProcessorWithScriptingContent* p, const
ADD_API_METHOD_0(getNonExistentSibling);
ADD_API_METHOD_3(extractZipFile);
ADD_API_METHOD_0(getNumZippedItems);
ADD_API_METHOD_0(getZippedItemList);
ADD_API_METHOD_2(setReadOnly);
ADD_API_METHOD_1(toReferenceString);
ADD_API_METHOD_1(getRelativePathFrom);
Expand Down Expand Up @@ -992,6 +994,7 @@ void ScriptingObjects::ScriptFile::extractZipFile(var targetDirectory, bool over
data->setProperty("TotalBytesWritten", 0);
data->setProperty("Cancel", false);
data->setProperty("Target", tf.getFullPathName());
data->setProperty("ZipFile", safeThis->f.getFullPathName());
data->setProperty("CurrentFile", "");
data->setProperty("Error", "");

Expand Down Expand Up @@ -1121,6 +1124,20 @@ int ScriptingObjects::ScriptFile::getNumZippedItems()
return zipFile.getNumEntries();
}

var ScriptingObjects::ScriptFile::getZippedItemList()
{
juce::ZipFile zipFile(f);
StringArray result;

for (int i = 0; i < zipFile.getNumEntries(); ++i)
{
if (auto* entry = zipFile.getEntry(i))
result.add(entry->filename);
}

return result;
}

void ScriptingObjects::ScriptFile::setReadOnly(bool shouldBeReadOnly, bool applyRecursively)
{
f.setReadOnly(shouldBeReadOnly, applyRecursively);
Expand Down
3 changes: 3 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ namespace ScriptingObjects
/** Returns the number of items in the zip file. */
int getNumZippedItems();

/** Returns an array of the filenames of all entries in the zip file. */
var getZippedItemList();

/** Changes the read/write permission for the given file. */
void setReadOnly(bool shouldBeReadOnly, bool applyRecursively);

Expand Down