MCPcopy Create free account
hub / github.com/christophhart/HISE / extractZipFile

Method extractZipFile

hi_scripting/scripting/api/ScriptingApiObjects.cpp:938–1088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

936};
937
938void ScriptingObjects::ScriptFile::extractZipFile(var targetDirectory, bool overwriteFiles, var callback)
939{
940 File tf;
941
942 if (targetDirectory.isString() && File::isAbsolutePath(targetDirectory.toString()))
943 tf = File(targetDirectory.toString());
944 else if (auto sf = dynamic_cast<ScriptFile*>(targetDirectory.getObject()))
945 {
946 tf = sf->f;
947 }
948
949 ReferenceCountedObjectPtr<ScriptFile> safeThis(this);
950
951 auto cb = [safeThis, tf, targetDirectory, overwriteFiles, callback](Processor* p)
952 {
953 if (safeThis == nullptr)
954 return SafeFunctionCall::OK;
955
956 juce::ZipFile zipFile(safeThis->f);
957
958 DynamicObject::Ptr data = new DynamicObject();
959
960 double entryProgress = 0.0;
961
962 data->setProperty("Status", 0);
963 data->setProperty("Progress", 0.0);
964 data->setProperty("TotalBytesWritten", 0);
965 data->setProperty("Cancel", false);
966 data->setProperty("Target", tf.getFullPathName());
967 data->setProperty("CurrentFile", "");
968 data->setProperty("Error", "");
969
970 int64 numBytesWritten = 0;
971
972 WeakCallbackHolder cb(safeThis.get()->getScriptProcessor(), safeThis.get(), callback, 1);
973 //cb.setThisObject(safeThis.get());
974 cb.incRefCount();
975
976 if (cb)
977 {
978 auto c = data->clone();
979 cb.call1(var(c.get()));
980 }
981
982 data->setProperty("Status", 1);
983 int numEntries = zipFile.getNumEntries();
984 bool callForEachFile = numEntries < 500;
985
986 int64 numBytesToWrite = 0;
987
988 for (int i = 0; i < numEntries; i++)
989 {
990 numBytesToWrite += zipFile.getEntry(i)->uncompressedSize;
991 }
992
993 for (int i = 0; i < numEntries; i++)
994 {
995 if (Thread::getCurrentThread()->threadShouldExit())

Callers

nothing calls this directly

Calls 15

isAbsolutePathFunction · 0.85
FileClass · 0.85
varFunction · 0.85
incRefCountMethod · 0.80
getNumEntriesMethod · 0.80
getPreloadProgressMethod · 0.80
getMainController_Method · 0.80
isStringMethod · 0.45
toStringMethod · 0.45
getObjectMethod · 0.45
setPropertyMethod · 0.45
getScriptProcessorMethod · 0.45

Tested by

no test coverage detected