mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-24 01:54:22 +00:00
Added a progress value for ZipFile::Builder.
This commit is contained in:
parent
ab33b1a05d
commit
830332d3ec
4 changed files with 27 additions and 10 deletions
|
|
@ -130,7 +130,7 @@ namespace
|
|||
TemporaryFile temp (targetFile);
|
||||
ScopedPointer<FileOutputStream> out (temp.getFile().createOutputStream());
|
||||
|
||||
bool ok = out != nullptr && zip.writeToStream (*out);
|
||||
bool ok = out != nullptr && zip.writeToStream (*out, nullptr);
|
||||
out = nullptr;
|
||||
ok = ok && temp.overwriteTargetFileWithTemporary();
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,14 @@ class JUCE_API FileInputSource : public InputSource
|
|||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Creates a FileInputSource for a file.
|
||||
If the useFileTimeInHashGeneration parameter is true, then this object's
|
||||
hashCode() method will incorporate the file time into its hash code; if
|
||||
false, only the file name will be used for the hash.
|
||||
*/
|
||||
FileInputSource (const File& file, bool useFileTimeInHashGeneration = false);
|
||||
|
||||
/** Destructor. */
|
||||
~FileInputSource();
|
||||
|
||||
InputStream* createInputStream();
|
||||
|
|
|
|||
|
|
@ -541,18 +541,22 @@ void ZipFile::Builder::addFile (const File& fileToAdd, const int compressionLeve
|
|||
items.add (new Item (fileToAdd, compressionLevel, storedPathName));
|
||||
}
|
||||
|
||||
bool ZipFile::Builder::writeToStream (OutputStream& target) const
|
||||
bool ZipFile::Builder::writeToStream (OutputStream& target, double* const progress) const
|
||||
{
|
||||
const int64 fileStart = target.getPosition();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < items.size(); ++i)
|
||||
for (int i = 0; i < items.size(); ++i)
|
||||
{
|
||||
if (progress != nullptr)
|
||||
*progress = (i + 0.5) / items.size();
|
||||
|
||||
if (! items.getUnchecked (i)->writeData (target, fileStart))
|
||||
return false;
|
||||
}
|
||||
|
||||
const int64 directoryStart = target.getPosition();
|
||||
|
||||
for (i = 0; i < items.size(); ++i)
|
||||
for (int i = 0; i < items.size(); ++i)
|
||||
if (! items.getUnchecked (i)->writeDirectoryEntry (target))
|
||||
return false;
|
||||
|
||||
|
|
@ -567,5 +571,8 @@ bool ZipFile::Builder::writeToStream (OutputStream& target) const
|
|||
target.writeInt ((int) (directoryStart - fileStart));
|
||||
target.writeShort (0);
|
||||
|
||||
if (progress != nullptr)
|
||||
*progress = 1.0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class JUCE_API ZipFile
|
|||
{
|
||||
public:
|
||||
/** Creates a ZipFile based for a file. */
|
||||
ZipFile (const File& file);
|
||||
explicit ZipFile (const File& file);
|
||||
|
||||
//==============================================================================
|
||||
/** Creates a ZipFile for a given stream.
|
||||
|
|
@ -58,14 +58,14 @@ public:
|
|||
The stream will not be owned or deleted by this class - if you want the ZipFile to
|
||||
manage the stream's lifetime, use the other constructor.
|
||||
*/
|
||||
ZipFile (InputStream& inputStream);
|
||||
explicit ZipFile (InputStream& inputStream);
|
||||
|
||||
/** Creates a ZipFile for an input source.
|
||||
|
||||
The inputSource object will be owned by the zip file, which will delete
|
||||
it later when not needed.
|
||||
*/
|
||||
ZipFile (InputSource* inputSource);
|
||||
explicit ZipFile (InputSource* inputSource);
|
||||
|
||||
/** Destructor. */
|
||||
~ZipFile();
|
||||
|
|
@ -198,8 +198,11 @@ public:
|
|||
void addFile (const File& fileToAdd, int compressionLevel,
|
||||
const String& storedPathName = String::empty);
|
||||
|
||||
/** Generates the zip file, writing it to the specified stream. */
|
||||
bool writeToStream (OutputStream& target) const;
|
||||
/** Generates the zip file, writing it to the specified stream.
|
||||
If the progress parameter is non-null, it will be updated with an approximate
|
||||
progress status between 0 and 1.0
|
||||
*/
|
||||
bool writeToStream (OutputStream& target, double* progress) const;
|
||||
|
||||
//==============================================================================
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue