Discussion of article "Handling ZIP Archives in Pure MQL5" - page 2

 
Vasiliy Sokolov:

The notorious casting of structures is swearing. Keep the corrected version in the attachment.


Prompt! Thank you very much!

 
Vasiliy Sokolov:

Now I've looked at your error carefully - the same situation with structure casting, but in another container - CDictionary. Replace Include\Dictionary.mqh with the variant attached below.

And yes, everything works fine under MT4 and I will say more CZip is a workhorse in my projects on MT4.


What is left is this:

'm_array' - structures containing objects are not allowed Dictionary.mqh 306 25

 
Stanislav Korotky:

What's left is this:

'm_array' - structures containing objects are not allowed Dictionary.mqh 306 25


Line 306 should be replaced with this fragment:

#ifdef __MQL4__
int t_size = ArrayResize(temp_array, ArraySize(m_array));
for(int i = 0; i < t_size; i++)
   temp_array[i] = m_array[i];
#else
ArrayCopy(temp_array, m_array);
#endif

In the attache Dictionary for MT4

Files:
Dictionary.mqh  39 kb
 
Vasiliy Sokolov:

Line 306 should be replaced with this fragment:

In the attache Dictionary for MT4.

That makes sense. Super thanks.

PS. It's true that for zero-length files in the archive an incorrect header is created (in the example ZipTask1), because of which they are unretrievable, but this can be sorted out - maybe it's something in the test itself.

 
Stanislav Korotky:

Makes sense. Super thanks.

PS. It's true that for zero-length files in the archive an invalid header is created (in the ZipTask1 example), which makes them unretrievable, but this can be sorted out - maybe it's something in the test itself.

I'll see what I can do with zero length.

 

Here's what's wrong? I can't uncompress the zip.zip file (downloaded from the example).




Log.

18:25:47.809 Script zip_arc101 GBPUSD,H1: loaded successfully

0 18:25:47.830 zip_arc101 GBPUSD,H1: initialised

0 18:25:47.830 zip_arc101 GBPUSD,H1: Handle= 1 GetLastError= 0

0 18:25:47.830 zip_arc101 GBPUSD,H1: FileReadArray= 11004

0 18:25:47.830 zip_arc101 GBPUSD,H1: Zip.CreateFromCharArray= true

0 18:25:47.830 zip_arc101 GBPUSD,H1: Archive successfully loaded. Total files: 7

0 18:25:47.836 zip_arc101 GBPUSD,H1: Zip.UnpackZipArchive= false

0 18:25:47.837 zip_arc101 GBPUSD,H1: Zip.UnpackZipArchive= false

0 18:25:47.837 zip_arc101 GBPUSD,H1: Zip.UnpackZipArchive= false

0 18:25:47.837 zip_arc101 GBPUSD,H1: uninit reason 0

0 18:25:47.839 Script zip_arc101 GBPUSD,H1: removed

 
void OnStart()
  {
//---
   uchar zip_array[];
   
   ResetLastError();
   
   int Handle = FileOpen("zip.zip", FILE_READ|FILE_BIN|FILE_COMMON );
   
   
   Print("Handle= ", Handle, "   GetLastError= ", GetLastError() );
   
   
   Print("FileReadArray= ", FileReadArray(Handle, zip_array) );
   
   
   Print("Zip.CreateFromCharArray= ", Zip.CreateFromCharArray(zip_array) );
   
   
   printf("Archive successfully loaded. Total files: "+(string)Zip.TotalElements());
   
   
   Print("Zip.UnpackZipArchive= ", Zip.UnpackZipArchive("NNN",FILE_COMMON) );
   
   Print("Zip.UnpackZipArchive= ", Zip.UnpackZipArchive("",FILE_COMMON) );
   
   Print("Zip.UnpackZipArchive= ", Zip.UnpackZipArchive("", 0) );
   
  }
//+------------------------------------------------------------------+
 

The CZip::UnpackZipArchive method always returns false for some reason, although it does its job. This is a bug. Check actual unpacking by field observations.

 
Vasiliy Sokolov:

The CZip::UnpackZipArchive method always returns false for some reason, although it does its job. This is a bug. Check the actual unpacking by observation.


Yes. false but unpacking works!

 

Here is another problem, if I need to unpack several archives in a loop, changing only the year in the name.

Only d2014.zip is unpacked and that's it.



0 01:57:36.772 Script zip_arc104 GBPUSD,H1: loaded successfully

0 01:57:36.807 zip_arc104 GBPUSD,H1: initialised

0 01:57:36.807 zip_arc104 GBPUSD,H1: -------------- DD\d2014.zip

0 01:57:36.815 zip_arc104 GBPUSD,H1: DD\d2014.zip Zip.LoadZipFromFile= true

0 01:57:36.815 zip_arc104 GBPUSD,H1: Archive successfully loaded. Total files: 1

0 01:57:36.906 zip_arc104 GBPUSD,H1: Zip.UnpackZipArchive= false

0 01:57:36.906 zip_arc104 GBPUSD,H1: -------------- DD\d2015.zip

0 01:57:36.912 zip_arc104 GBPUSD,H1: DD\d2015.zip Zip.LoadZipFromFile= true

0 01:57:36.912 zip_arc104 GBPUSD,H1: Archive successfully loaded. Total files: 1

1 01:57:36.912 zip_arc104 GBPUSD,H1: invalid pointer access in 'Zip.mqh' (407,28)

0 01:57:36.913 zip_arc104 GBPUSD,H1: uninit reason 0

0 01:57:36.915 Script zip_arc104 GBPUSD,H1: removed