forked from nique_372/MQLArticles
258 lines
9.3 KiB
MQL5
258 lines
9.3 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Base.mqh |
|
|
//| Copyright 2026, Niquel Mendoza. |
|
|
//| https://www.mql5.com/es/users/nique_372 |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2026, Niquel Mendoza."
|
|
#property link "https://www.mql5.com/es/users/nique_372"
|
|
#property strict
|
|
|
|
#ifndef MQLARTICLES_UTILS_FILE_FOLDEROPS_BASE_MQH
|
|
#define MQLARTICLES_UTILS_FILE_FOLDEROPS_BASE_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
// Incluimos el paquete completo de json
|
|
#include <TSN\\Json\\Json.mqh>
|
|
// str math
|
|
#include "..\\..\\StrMatch\\StrSimpleMatch.mqh"
|
|
// basicos
|
|
#include "..\\..\\Basic.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
namespace TSN
|
|
{
|
|
class CFolderOpsBase : public CLoggerBase
|
|
{
|
|
protected:
|
|
//---
|
|
string m_arr_clean_inlcluyed[];
|
|
int m_arr_clean_inlcluyed_size;
|
|
string m_arr_clean_excluyed[];
|
|
int m_arr_clean_excluyed_size;
|
|
|
|
public:
|
|
CFolderOpsBase(void);
|
|
~CFolderOpsBase(void) {}
|
|
|
|
//---
|
|
bool IsFileIncluyed(const string& file_name);
|
|
bool IsFileExcluyed(const string& file_name);
|
|
|
|
//---
|
|
// Size
|
|
__forceinline int SizeArrInclued() const { return m_arr_clean_inlcluyed_size; }
|
|
__forceinline int SizeArrExcluyed() const { return m_arr_clean_excluyed_size; }
|
|
|
|
// Resize
|
|
void SizeArrInclued(int size) { m_arr_clean_inlcluyed_size = ArrayResize(m_arr_clean_inlcluyed, size); }
|
|
void SizeArrExcluyed(int size) { m_arr_clean_excluyed_size = ArrayResize(m_arr_clean_excluyed, size); }
|
|
|
|
//
|
|
void SetArrIncluyed(const string& str, ushort sep = '|');
|
|
void SetArrExcluyed(const string& str, ushort sep = '|');
|
|
|
|
|
|
// Set val
|
|
void SetValIncluyed(int pos, const string& val) { m_arr_clean_inlcluyed[pos] = val; }
|
|
void SetValExluyed(int pos, const string& val) { m_arr_clean_excluyed[pos] = val; }
|
|
void SetValIncluyedNoRef(int pos, const string val) { m_arr_clean_inlcluyed[pos] = val; }
|
|
void SetValExluyedNoRef(int pos, const string val) { m_arr_clean_excluyed[pos] = val; }
|
|
|
|
// clean
|
|
void Clean();
|
|
|
|
//---
|
|
bool Load(const string& json_file_name, bool comon_flag, CJsonParser& json_parser);
|
|
bool Save(const string& json_file_name, int extra_file_flags, CJsonBuilder& json_builder) const;
|
|
|
|
//---
|
|
void Summary() const;
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CFolderOpsBase::CFolderOpsBase(void)
|
|
{
|
|
m_arr_clean_inlcluyed_size = ArrayResize(m_arr_clean_inlcluyed, 0);
|
|
m_arr_clean_excluyed_size = ArrayResize(m_arr_clean_excluyed, 0);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CFolderOpsBase::Load(const string &json_file_name, bool comon_flag, CJsonParser &json_parser)
|
|
{
|
|
//---
|
|
const int ext = json_parser.AssingFile(json_file_name, comon_flag);
|
|
if(!json_parser.AutoParseByFileExt(ext))
|
|
{
|
|
LogError(StringFormat("Fallo al parsear json, archivo = %s", json_file_name), FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
|
|
//---
|
|
CJsonNode root = json_parser.GetRoot();
|
|
//json_parser.PrintCintaTypes();
|
|
|
|
//--- Inclusion
|
|
CJsonNode incluyed = root["incluyed"];
|
|
if(!incluyed.IsValid())
|
|
{
|
|
m_arr_clean_inlcluyed_size = ArrayResize(m_arr_clean_inlcluyed, 0);
|
|
LogWarning("No se ha encontrado el campo 'incluyed' en el json config, todos los archivos se omitiran para su uso", FUNCION_ACTUAL);
|
|
}
|
|
else
|
|
{
|
|
m_arr_clean_inlcluyed_size = ArrayResize(m_arr_clean_inlcluyed, incluyed.Size());
|
|
int i = 0;
|
|
Print(EnumToString(incluyed.GetType()));
|
|
CJsonIteratorArray it = incluyed.BeginArr();
|
|
while(it.IsValid())
|
|
{
|
|
m_arr_clean_inlcluyed[i++] = it.Val().ToString();
|
|
it.Next();
|
|
}
|
|
}
|
|
|
|
//--- Exclusion
|
|
CJsonNode excluyed = root["excluyed"];
|
|
if(!excluyed.IsValid())
|
|
{
|
|
m_arr_clean_excluyed_size = ArrayResize(m_arr_clean_excluyed, 0);
|
|
LogWarning("No se ha encontrado el campo 'excluyed' en el json config, ningun archivo se excluira para su uso", FUNCION_ACTUAL);
|
|
}
|
|
else
|
|
{
|
|
m_arr_clean_excluyed_size = ArrayResize(m_arr_clean_excluyed, excluyed.Size());
|
|
int i = 0;
|
|
CJsonIteratorArray it = excluyed.BeginArr();
|
|
while(it.IsValid())
|
|
{
|
|
m_arr_clean_excluyed[i++] = it.Val().ToString();
|
|
it.Next();
|
|
}
|
|
}
|
|
|
|
//---
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CFolderOpsBase::Save(const string &json_file_name, int extra_file_flags, CJsonBuilder &json_builder) const
|
|
{
|
|
//---
|
|
::ResetLastError();
|
|
const int fh = FileOpen(json_file_name, FILE_WRITE | FILE_TXT | extra_file_flags, 0);
|
|
if(fh == INVALID_HANDLE)
|
|
{
|
|
LogError(StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", json_file_name, ::GetLastError()), FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
//---
|
|
json_builder.Obj();
|
|
|
|
//--- Inclusion
|
|
json_builder.Key("incluyed").Arr();
|
|
for(int i = 0; i < m_arr_clean_inlcluyed_size; i++)
|
|
json_builder.ValS(m_arr_clean_inlcluyed[i]);
|
|
json_builder.EndArr();
|
|
|
|
//--- Exclusion
|
|
json_builder.Key("excluyed").Arr();
|
|
for(int i = 0; i < m_arr_clean_excluyed_size; i++)
|
|
json_builder.ValS(m_arr_clean_excluyed[i]);
|
|
json_builder.EndArr();
|
|
|
|
//---
|
|
json_builder.EndObj();
|
|
|
|
//---
|
|
::FileWriteString(fh, json_builder.Build());
|
|
::FileClose(fh);
|
|
|
|
//---
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CFolderOpsBase::IsFileExcluyed(const string & file_name)
|
|
{
|
|
for(int i = 0; i < m_arr_clean_excluyed_size; i++)
|
|
{
|
|
if(CSimpleStringMatch::SimpleMatchInString(file_name, m_arr_clean_excluyed[i]))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CFolderOpsBase::IsFileIncluyed(const string & file_name)
|
|
{
|
|
for(int i = 0; i < m_arr_clean_inlcluyed_size; i++)
|
|
{
|
|
if(CSimpleStringMatch::SimpleMatchInString(file_name, m_arr_clean_inlcluyed[i]))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CFolderOpsBase::SetArrExcluyed(const string &str, ushort sep)
|
|
{
|
|
m_arr_clean_excluyed_size = StringSplit(str, sep, m_arr_clean_excluyed);
|
|
if(m_arr_clean_excluyed_size <= -1)
|
|
m_arr_clean_excluyed_size = 0;
|
|
ArrayResize(m_arr_clean_excluyed, m_arr_clean_excluyed_size);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CFolderOpsBase::SetArrIncluyed(const string &str, ushort sep)
|
|
{
|
|
m_arr_clean_inlcluyed_size = StringSplit(str, sep, m_arr_clean_inlcluyed);
|
|
if(m_arr_clean_inlcluyed_size <= -1)
|
|
m_arr_clean_inlcluyed_size = 0;
|
|
ArrayResize(m_arr_clean_inlcluyed, m_arr_clean_inlcluyed_size);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CFolderOpsBase::Summary() const
|
|
{
|
|
Print("----- CFolderOpsBase info");
|
|
Print("Incluyed: [", m_arr_clean_inlcluyed_size, "]");
|
|
Print(ArrayStrToString(m_arr_clean_inlcluyed, "|"));
|
|
Print("Excluyed: [", m_arr_clean_excluyed_size, "]");;
|
|
Print(ArrayStrToString(m_arr_clean_excluyed, "|"));
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CFolderOpsBase::Clean(void)
|
|
{
|
|
m_arr_clean_inlcluyed_size = ArrayResize(m_arr_clean_inlcluyed, 0);
|
|
m_arr_clean_excluyed_size = ArrayResize(m_arr_clean_excluyed, 0);
|
|
}
|
|
}
|
|
#endif // MQLARTICLES_UTILS_FILE_FOLDEROPS_BASE_MQH
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|