Browse Source

tags/2021-05-28
jules 17 years ago
parent
commit
7ed0423f37
5 changed files with 144 additions and 80 deletions
  1. +3
    -3
      build/linux/platform_specific_code/juce_linux_Windowing.cpp
  2. +18
    -3
      src/juce_core/cryptography/juce_BlowFish.cpp
  3. +11
    -2
      src/juce_core/cryptography/juce_BlowFish.h
  4. +99
    -68
      src/juce_core/misc/juce_ZipFile.cpp
  5. +13
    -4
      src/juce_core/misc/juce_ZipFile.h

+ 3
- 3
build/linux/platform_specific_code/juce_linux_Windowing.cpp View File

@@ -1811,7 +1811,7 @@ private:
unsigned long flags;
unsigned long functions;
unsigned long decorations;
::INT32 input_mode;
long input_mode;
unsigned long status;
} MotifWmHints;
@@ -1872,7 +1872,7 @@ private:
unsigned long flags;
unsigned long functions;
unsigned long decorations;
::INT32 input_mode;
long input_mode;
unsigned long status;
} MotifWmHints;
@@ -2186,7 +2186,7 @@ private:
XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
&data) == Success)
{
const unsigned long* const sizes = (const CARD32*) data;
const unsigned long* const sizes = (const unsigned long*) data;
if (actualFormat == 32)
windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],


+ 18
- 3
src/juce_core/cryptography/juce_BlowFish.cpp View File

@@ -310,7 +310,6 @@ static const uint32 initialSValues [4 * 256] =
//==============================================================================
BlowFish::BlowFish (const uint8* keyData, int keyBytes)
{
p = (uint32*) juce_malloc (18 * sizeof (uint32));
memcpy (p, initialPValues, sizeof (p));
int i, j;
@@ -359,10 +358,26 @@ BlowFish::BlowFish (const uint8* keyData, int keyBytes)
}
}
BlowFish::~BlowFish()
BlowFish::BlowFish (const BlowFish& other)
{
for (int i = 4; --i >= 0;)
s[i] = (uint32*) juce_malloc (256 * sizeof (uint32));
operator= (other);
}
const BlowFish& BlowFish::operator= (const BlowFish& other)
{
juce_free (p);
memcpy (p, other.p, sizeof (p));
for (int i = 4; --i >= 0;)
memcpy (s[i], other.s[i], 256 * sizeof (uint32));
return *this;
}
BlowFish::~BlowFish()
{
for (int i = 4; --i >= 0;)
juce_free (s[i]);
}


+ 11
- 2
src/juce_core/cryptography/juce_BlowFish.h View File

@@ -42,9 +42,18 @@ class JUCE_API BlowFish
{
public:
//==============================================================================
/** Creates an object that can encode/decode based on the specified key. */
/** Creates an object that can encode/decode based on the specified key.
The key data can be up to 72 bytes long.
*/
BlowFish (const uint8* keyData, int keyBytes);
/** Creates a copy of another blowfish object. */
BlowFish (const BlowFish& other);
/** Copies another blowfish object. */
const BlowFish& operator= (const BlowFish& other);
/** Destructor. */
~BlowFish();
@@ -60,7 +69,7 @@ public:
juce_UseDebuggingNewOperator
private:
uint32* p;
uint32 p[18];
uint32* s[4];
uint32 F (uint32 x) const;


+ 99
- 68
src/juce_core/misc/juce_ZipFile.cpp View File

@@ -37,6 +37,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_ZipFile.h"
#include "../io/streams/juce_GZIPDecompressorInputStream.h"
#include "../io/streams/juce_BufferedInputStream.h"
#include "../io/streams/juce_FileInputSource.h"
#include "../io/files/juce_FileInputStream.h"
#include "../io/files/juce_FileOutputStream.h"
#include "../threads/juce_ScopedLock.h"
@@ -62,39 +63,43 @@ public:
: file (file_),
zipEntryInfo (zei),
pos (0),
headerSize (0)
headerSize (0),
inputStream (0)
{
char buffer [30];
if (file.source->setPosition (zei.streamOffset)
&& file.source->read (buffer, 30) == 30
&& littleEndianInt (buffer) == 0x04034b50)
{
headerSize = 30 + littleEndianShort (buffer + 26)
+ littleEndianShort (buffer + 28);
}
inputStream = file_.inputStream;
if (! file_.isFromCustomStream)
if (file_.inputSource != 0)
{
source = file_.sourceFile.createInputStream();
inputStream = file.inputSource->createInputStream();
}
else
{
source = 0;
#ifdef JUCE_DEBUG
file_.numOpenStreams++;
#endif
}
char buffer [30];
if (inputStream != 0
&& inputStream->setPosition (zei.streamOffset)
&& inputStream->read (buffer, 30) == 30
&& littleEndianInt (buffer) == 0x04034b50)
{
headerSize = 30 + littleEndianShort (buffer + 26)
+ littleEndianShort (buffer + 28);
}
}
~ZipInputStream() throw()
{
#ifdef JUCE_DEBUG
if (source == 0)
if (inputStream != 0 && inputStream == file.inputStream)
file.numOpenStreams--;
#endif
delete source;
if (inputStream != file.inputStream)
delete inputStream;
}
int64 getTotalLength() throw()
@@ -108,19 +113,22 @@ public:
return 0;
howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
if (inputStream == 0)
return 0;
int num;
if (source != 0)
if (inputStream == file.inputStream)
{
source->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
num = source->read (buffer, howMany);
const ScopedLock sl (file.lock);
inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
num = inputStream->read (buffer, howMany);
}
else
{
const ScopedLock sl (file.lock);
file.source->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
num = file.source->read (buffer, howMany);
inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
num = inputStream->read (buffer, howMany);
}
pos += num;
@@ -150,7 +158,7 @@ private:
ZipEntryInfo zipEntryInfo;
int64 pos;
int headerSize;
InputStream* source;
InputStream* inputStream;
ZipInputStream (const ZipInputStream&);
const ZipInputStream& operator= (const ZipInputStream&);
@@ -160,8 +168,7 @@ private:
//==============================================================================
ZipFile::ZipFile (InputStream* const source_,
const bool deleteStreamWhenDestroyed_) throw()
: source (source_),
isFromCustomStream (true),
: inputStream (source_),
deleteStreamWhenDestroyed (deleteStreamWhenDestroyed_)
#ifdef JUCE_DEBUG
, numOpenStreams (0)
@@ -171,14 +178,24 @@ ZipFile::ZipFile (InputStream* const source_,
}
ZipFile::ZipFile (const File& file)
: sourceFile (file),
isFromCustomStream (false),
deleteStreamWhenDestroyed (true)
: inputStream (0),
deleteStreamWhenDestroyed (false)
#ifdef JUCE_DEBUG
, numOpenStreams (0)
#endif
{
inputSource = new FileInputSource (file);
init();
}
ZipFile::ZipFile (InputSource* const inputSource_)
: inputStream (0),
inputSource (inputSource_),
deleteStreamWhenDestroyed (false)
#ifdef JUCE_DEBUG
, numOpenStreams (0)
#endif
{
source = file.createInputStream();
init();
}
@@ -190,8 +207,10 @@ ZipFile::~ZipFile() throw()
delete zei;
}
if (deleteStreamWhenDestroyed && (source != 0))
delete source;
if (deleteStreamWhenDestroyed)
delete inputStream;
delete inputSource;
#ifdef JUCE_DEBUG
// If you hit this assertion, it means you've created a stream to read
@@ -273,64 +292,76 @@ void ZipFile::sortEntriesByFilename()
//==============================================================================
void ZipFile::init()
{
if (source != 0)
InputStream* in = inputStream;
bool deleteInput = false;
if (inputSource != 0)
{
deleteInput = true;
in = inputSource->createInputStream();
}
if (in != 0)
{
numEntries = 0;
int pos = findEndOfZipEntryTable();
int size = (int) (source->getTotalLength() - pos);
int pos = findEndOfZipEntryTable (in);
const int size = (int) (in->getTotalLength() - pos);
source->setPosition (pos);
in->setPosition (pos);
MemoryBlock headerData;
if (source->readIntoMemoryBlock (headerData, size) != size)
return;
pos = 0;
for (int i = 0; i < numEntries; ++i)
if (in->readIntoMemoryBlock (headerData, size) == size)
{
if (pos + 46 > size)
break;
pos = 0;
const char* const buffer = ((const char*) headerData.getData()) + pos;
for (int i = 0; i < numEntries; ++i)
{
if (pos + 46 > size)
break;
const char* const buffer = ((const char*) headerData.getData()) + pos;
const int fileNameLen = littleEndianShort (buffer + 28);
const int fileNameLen = littleEndianShort (buffer + 28);
if (pos + 46 + fileNameLen > size)
break;
if (pos + 46 + fileNameLen > size)
break;
ZipEntryInfo* const zei = new ZipEntryInfo();
zei->entry.filename = String (buffer + 46, fileNameLen);
ZipEntryInfo* const zei = new ZipEntryInfo();
zei->entry.filename = String (buffer + 46, fileNameLen);
const int time = littleEndianShort (buffer + 12);
const int date = littleEndianShort (buffer + 14);
const int time = littleEndianShort (buffer + 12);
const int date = littleEndianShort (buffer + 14);
const int year = 1980 + (date >> 9);
const int month = ((date >> 5) & 15) - 1;
const int day = date & 31;
const int hours = time >> 11;
const int minutes = (time >> 5) & 63;
const int seconds = (time & 31) << 1;
const int year = 1980 + (date >> 9);
const int month = ((date >> 5) & 15) - 1;
const int day = date & 31;
const int hours = time >> 11;
const int minutes = (time >> 5) & 63;
const int seconds = (time & 31) << 1;
zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
zei->compressed = littleEndianShort (buffer + 10) != 0;
zei->compressedSize = littleEndianInt (buffer + 20);
zei->entry.uncompressedSize = littleEndianInt (buffer + 24);
zei->compressed = littleEndianShort (buffer + 10) != 0;
zei->compressedSize = littleEndianInt (buffer + 20);
zei->entry.uncompressedSize = littleEndianInt (buffer + 24);
zei->streamOffset = littleEndianInt (buffer + 42);
entries.add (zei);
zei->streamOffset = littleEndianInt (buffer + 42);
entries.add (zei);
pos += 46 + fileNameLen
+ littleEndianShort (buffer + 30)
+ littleEndianShort (buffer + 32);
pos += 46 + fileNameLen
+ littleEndianShort (buffer + 30)
+ littleEndianShort (buffer + 32);
}
}
if (deleteInput)
delete in;
}
}
int ZipFile::findEndOfZipEntryTable()
int ZipFile::findEndOfZipEntryTable (InputStream* input)
{
BufferedInputStream in (source, 8192, false);
BufferedInputStream in (input, 8192, false);
in.setPosition (in.getTotalLength());
int64 pos = in.getPosition();


+ 13
- 4
src/juce_core/misc/juce_ZipFile.h View File

@@ -34,6 +34,7 @@
#include "../io/files/juce_File.h"
#include "../io/juce_InputStream.h"
#include "../io/streams/juce_InputSource.h"
#include "../threads/juce_CriticalSection.h"
@@ -60,6 +61,13 @@ public:
/** Creates a ZipFile based for a file. */
ZipFile (const File& file);
/** 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* const inputSource);
/** Destructor. */
~ZipFile() throw();
@@ -146,9 +154,10 @@ private:
VoidArray entries;
friend class ZipInputStream;
CriticalSection lock;
InputStream* source;
File sourceFile;
bool isFromCustomStream, deleteStreamWhenDestroyed;
InputStream* inputStream;
InputSource* inputSource;
bool deleteStreamWhenDestroyed;
int numEntries, centralRecStart;
#ifdef JUCE_DEBUG
@@ -156,7 +165,7 @@ private:
#endif
void init();
int findEndOfZipEntryTable();
int findEndOfZipEntryTable (InputStream* in);
ZipFile (const ZipFile&);
const ZipFile& operator= (const ZipFile&);


Loading…
Cancel
Save