| 936 | }; |
| 937 | |
| 938 | void 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()) |
nothing calls this directly
no test coverage detected