2026-03-27 09:40:26 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| 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
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-02 08:46:32 -05:00 | | | // Incluimos el paquete completo de json
|
| | | #include <TSN\\Json\\Json.mqh>
|
| | | // str math
|
2026-03-27 09:40:26 -05:00 | | | #include "..\\..\\StrMatch\\StrSimpleMatch.mqh"
|
2026-09-02 08:46:32 -05:00 | | | // basicos
|
2026-03-27 09:40:26 -05:00 | | | #include "..\\..\\Basic.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 18:52:51 -05:00 | | | namespace TSN
|
| | | {
|
2026-03-27 09:40:26 -05:00 | | | 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) {}
|
| | |
|
2026-03-27 16:34:14 -05:00 | | | //---
|
2026-09-02 15:54:33 -05:00 | | | bool IsFileIncluyed(const string& file_name);
|
| | | bool IsFileExcluyed(const string& file_name);
|
2026-03-27 16:34:14 -05:00 | | |
|
2026-03-27 09:40:26 -05:00 | | | //---
|
2026-03-27 15:29:57 -05:00 | | | // Size
|
2026-03-27 09:40:26 -05:00 | | | __forceinline int SizeArrInclued() const { return m_arr_clean_inlcluyed_size; }
|
| | | __forceinline int SizeArrExcluyed() const { return m_arr_clean_excluyed_size; }
|
2026-03-27 15:29:57 -05:00 | | |
|
| | | // Resize
|
2026-03-27 09:40:26 -05:00 | | | 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); }
|
2026-03-27 15:29:57 -05:00 | | |
|
2026-04-30 15:56:25 -05:00 | | | //
|
| | | void SetArrIncluyed(const string& str, ushort sep = '|');
|
| | | void SetArrExcluyed(const string& str, ushort sep = '|');
|
| | |
|
| | |
|
2026-03-27 15:29:57 -05:00 | | | // Set val
|
2026-03-27 16:34:14 -05:00 | | | 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; }
|
2026-03-27 15:29:57 -05:00 | | | 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();
|
| | |
|
| | | //---
|
2026-06-03 18:52:51 -05:00 | | | bool Load(const string& json_file_name, bool comon_flag, CJsonParser& json_parser);
|
2026-03-27 15:29:57 -05:00 | | | bool Save(const string& json_file_name, int extra_file_flags, CJsonBuilder& json_builder) const;
|
| | |
|
| | | //---
|
| | | void Summary() const;
|
2026-03-27 09:40:26 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | 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);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 18:52:51 -05:00 | | | bool CFolderOpsBase::Load(const string &json_file_name, bool comon_flag, CJsonParser &json_parser)
|
2026-03-27 15:29:57 -05:00 | | | {
|
| | | //---
|
2026-07-12 22:32:11 -05:00 | | | const int ext = json_parser.AssingFile(json_file_name, comon_flag);
|
| | | if(!json_parser.AutoParseByFileExt(ext))
|
2026-03-27 15:29:57 -05:00 | | | {
|
2026-06-03 18:52:51 -05:00 | | | LogError(StringFormat("Fallo al parsear json, archivo = %s", json_file_name), FUNCION_ACTUAL);
|
2026-03-27 15:29:57 -05:00 | | | return false;
|
| | | }
|
| | |
|
| | |
|
| | | //---
|
2026-06-03 18:52:51 -05:00 | | | CJsonNode root = json_parser.GetRoot();
|
2026-07-12 22:32:11 -05:00 | | | //json_parser.PrintCintaTypes();
|
2026-03-27 15:29:57 -05:00 | | |
|
| | | //--- Inclusion
|
2026-06-03 18:52:51 -05:00 | | | CJsonNode incluyed = root["incluyed"];
|
| | | if(!incluyed.IsValid())
|
2026-03-27 15:29:57 -05:00 | | | {
|
| | | 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());
|
2026-06-03 18:52:51 -05:00 | | | int i = 0;
|
| | | Print(EnumToString(incluyed.GetType()));
|
| | | CJsonIteratorArray it = incluyed.BeginArr();
|
| | | while(it.IsValid())
|
2026-03-27 15:29:57 -05:00 | | | {
|
2026-06-03 18:52:51 -05:00 | | | m_arr_clean_inlcluyed[i++] = it.Val().ToString();
|
| | | it.Next();
|
2026-03-27 15:29:57 -05:00 | | | }
|
| | | }
|
| | |
|
| | | //--- Exclusion
|
2026-06-03 18:52:51 -05:00 | | | CJsonNode excluyed = root["excluyed"];
|
| | | if(!excluyed.IsValid())
|
2026-03-27 15:29:57 -05:00 | | | {
|
| | | 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());
|
2026-06-03 18:52:51 -05:00 | | | int i = 0;
|
| | | CJsonIteratorArray it = excluyed.BeginArr();
|
| | | while(it.IsValid())
|
2026-03-27 15:29:57 -05:00 | | | {
|
2026-06-03 18:52:51 -05:00 | | | m_arr_clean_excluyed[i++] = it.Val().ToString();
|
| | | it.Next();
|
2026-03-27 15:29:57 -05:00 | | | }
|
| | | }
|
| | |
|
| | | //---
|
| | | 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();
|
2026-03-27 16:34:14 -05:00 | | |
|
2026-03-27 15:29:57 -05:00 | | | //--- Inclusion
|
| | | json_builder.Key("incluyed").Arr();
|
| | | for(int i = 0; i < m_arr_clean_inlcluyed_size; i++)
|
2026-06-03 18:52:51 -05:00 | | | json_builder.ValS(m_arr_clean_inlcluyed[i]);
|
2026-03-27 15:29:57 -05:00 | | | json_builder.EndArr();
|
| | |
|
| | | //--- Exclusion
|
| | | json_builder.Key("excluyed").Arr();
|
| | | for(int i = 0; i < m_arr_clean_excluyed_size; i++)
|
2026-06-03 18:52:51 -05:00 | | | json_builder.ValS(m_arr_clean_excluyed[i]);
|
2026-03-27 15:29:57 -05:00 | | | json_builder.EndArr();
|
| | |
|
| | | //---
|
| | | json_builder.EndObj();
|
| | |
|
| | | //---
|
| | | ::FileWriteString(fh, json_builder.Build());
|
| | | ::FileClose(fh);
|
| | |
|
| | | //---
|
| | | return true;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-02 15:54:33 -05:00 | | | bool CFolderOpsBase::IsFileExcluyed(const string & file_name)
|
2026-03-27 09:40:26 -05:00 | | | {
|
| | | for(int i = 0; i < m_arr_clean_excluyed_size; i++)
|
| | | {
|
2026-09-02 15:54:33 -05:00 | | | if(CSimpleStringMatch::SimpleMatchInString(file_name, m_arr_clean_excluyed[i]))
|
2026-03-27 09:40:26 -05:00 | | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-02 15:54:33 -05:00 | | | bool CFolderOpsBase::IsFileIncluyed(const string & file_name)
|
2026-03-27 09:40:26 -05:00 | | | {
|
| | | for(int i = 0; i < m_arr_clean_inlcluyed_size; i++)
|
| | | {
|
2026-09-02 15:54:33 -05:00 | | | if(CSimpleStringMatch::SimpleMatchInString(file_name, m_arr_clean_inlcluyed[i]))
|
2026-03-27 09:40:26 -05:00 | | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
2026-04-30 15:56:25 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | 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);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 18:52:51 -05:00 | | | void CFolderOpsBase::SetArrIncluyed(const string &str, ushort sep)
|
2026-04-30 15:56:25 -05:00 | | | {
|
| | | 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);
|
| | | }
|
| | |
|
2026-03-27 15:29:57 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | void CFolderOpsBase::Summary() const
|
| | | {
|
| | | Print("----- CFolderOpsBase info");
|
2026-06-03 18:52:51 -05:00 | | | Print("Incluyed: [", m_arr_clean_inlcluyed_size, "]");
|
2026-04-30 15:56:25 -05:00 | | | Print(ArrayStrToString(m_arr_clean_inlcluyed, "|"));
|
2026-06-03 18:52:51 -05:00 | | | Print("Excluyed: [", m_arr_clean_excluyed_size, "]");;
|
2026-04-30 15:56:25 -05:00 | | | Print(ArrayStrToString(m_arr_clean_excluyed, "|"));
|
2026-03-27 15:29:57 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | 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);
|
| | | }
|
2026-06-03 18:52:51 -05:00 | | | }
|
2026-03-27 09:40:26 -05:00 | | | #endif // MQLARTICLES_UTILS_FILE_FOLDEROPS_BASE_MQH
|
| | | //+------------------------------------------------------------------+
|
2026-03-27 15:29:57 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|