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

 

How to use this library to realise the task of backing up files:

You need to create an archive in which you can put into folders

\MQL5\Experts\

\MQL5/Indicators\

\MQL5/Include.

etc. ?

 
Alexandr Gavrilin #:

How to implement such a file backup task using this library:

You need to create an archive in which you can scatter the files into folders

\MQL5\Experts\

\MQL5/Indicators\

\MQL5\Include\

etc. ?

Here is a good example.

MQL5 Program Packer
MQL5 Program Packer
  • www.mql5.com
This is MQL5 project packer: assemble all source and resource files from dependencies into a single ZIP.
 
fxsaber #:

Here's a good example.

Thanks, I will study it. Tired of periodic updates of files on different archives to clients. A lot of time consuming, need automation.

 
fxsaber #:

Here's a good example.

Thanks, it works!


Addendum.

You can not pack ex5 , ex4 files, and I need to throw them exactly.

Here is a test script on the basis of the proposed one. mq5 throws without problems, if the menu resolution ex5 then all the error wrong file name 5002.

//+------------------------------------------------------------------+
//|UpdateShop.mq5 |
//|Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

// #define UNICODE_WARNING
#include <mql5/FileReader.mqh>
#include <Zip/Zip.mqh>
string sdir="MQL5/Experts/trading-shop.ru/";

string filelist[]=
  {
   "sovetnikov.net/WSO EA.mq5",
   "sovetnikov.net/SN Liza EA.mq5"
  };


CZip Zip;      // Create empty zip archive.

//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int added=0;
   string listing="";
   for(int i=0; i<ArraySize(filelist); i++)
     {
      string name=sdir+filelist[i];

      CZipFile *file = new CZipFile();
      if(!file.AddFile(name)
         || !Zip.AddFile(file))
        {
         delete file;
        }
      else
        {
         added++;
         Print(" + "+name);
        }

     }

   if(added>0)
     {
      //create the catalogue

      //save the archive to a file
      const string archive = "MQL5/Files/Test.zip";
      if(Zip.SaveZipToFile(archive))
        {
         Print("Packed file saved: ", archive);
        }
     }
  }
//+----------------------------------------------------------------
Thanks again to the developers for the safety of working with files..... again another crutches to make.
 

Hello,

I have a ZIP archive with one CSV file in it.
How to read this file into a string. (Without saving to disc and reading from disc)

 
Forester #:

Hello,

I have a ZIP archive with one CSV file in it.
How to read this file into a string. (Without saving to disc and reading from disc)

https://www.mql5.com/en/articles/1971

Работаем с ZIP-архивами средствами MQL5 без использования сторонних библиотек
Работаем с ZIP-архивами средствами MQL5 без использования сторонних библиотек
  • www.mql5.com
Язык MQL5 развивается, и в него постоянно добавляются новые функции для работы с данными. С некоторых пор, благодаря нововведениям, стало возможно работать с ZIP-архивами штатными средствами MQL5 без привлечения сторонних библиотек DLL. Данная статья подробно описывает, как это делается, на примере описания класса CZip — универсального инструмента для чтения, создания и модификации ZIP-архивов.
 

This is the discussion thread for the article you mentioned. I saw only the possibility to upload ZIP to a folder on disc. But I would like to upload it to a line at once.

 

If anyone needs it, here is a ready script for reading the archive in a line.

ZIP folder and Dictionary.mqh download here https://www.mql5.com/en/code/27955 - they work.

#property copyright "Copyright 2015, Vasiliy Sokolov."
#property link      "https://www.mql5.com"
#property version   "1.00"

int is_common=1;

#include <Zip\Zip.mqh>

CZip Zip;

void OnStart(){
   string filenames[]; if(FileSelectDialog("Select files to download.", "CSV/", "CSV files (*.csv)|*.csv;*.zip|ZIP files (*.zip)|*.zip|All files (*.*)|*.*", FSD_ALLOW_MULTISELECT|(is_common?FSD_COMMON_FOLDER:0), filenames, "data.txt")>0){int total=ArraySize(filenames);for(int i=0; i<total; i++){Print(i, ": ", filenames[i]);}} else{Print("Files not selected");}

   bool res=Zip.LoadZipFromFile(filenames[0],FILE_COMMON);//считать 0й файл из выбранных
   if(!res) {
      uint last_error=GetLastError();
      if(last_error<ERR_USER_ERROR_FIRST){printf("A system error occurred while downloading the archive. Error number: "+(string)last_error);}
      else {  ENUM_ZIP_ERROR error=(ENUM_ZIP_ERROR)(last_error-ERR_USER_ERROR_FIRST); printf("An error occurred in processing the archive at the moment of its download: "+EnumToString(error));}
      return;
   }
   
   CZipFile* content = Zip.ElementAt(0);//read file number 0 in the archive
   uchar file_content[];
   content.GetUnpackFile(file_content);// unpack it into the file_content array

   string  s = CharArrayToString(file_content,0,-1,CP_UTF8);//CP_ACP
   
   string sa[];
   int k=StringSplit(s,'\n',sa);//--- split the string into substrings
   for(int i=0;i<k;i++){
      PrintFormat("result[%d]=\"%s\"",i,sa[i]);
   }
}
MQL5 Program Packer
MQL5 Program Packer
  • www.mql5.com
This is MQL5 project packer: assemble all source and resource files from dependencies into a single ZIP.
 
In general, it would be good to add archiving functions to the terminal itself. Judging by the discussion, files regularly stop compiling.
 
Any updates on this? I am running into errors

'ZipLocalHeaderOpen' has constructor and cannot be used as union member ZipHeader.mqh 52 23