//+------------------------------------------------------------------+ //| 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 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Def.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // MQLARTICLES_FOLDEROPS_ENABLE_LOGS namespace TSN { //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CFolderOpsBase { protected: string m_arr_clean_inlcluyed[]; int m_arr_clean_inlcluyed_size; string m_arr_clean_excluyed[]; int m_arr_clean_excluyed_size; //--- ENUM_FILE_FOLDEOPS_ERR m_last_err; ENUM_FILE_FOLDEROPS_WARN m_warns[FILEFOLDEROPS_MAX_WARNS]; int m_warns_s; 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); //--- void Summary() const; //--- __forceinline ENUM_FILE_FOLDEOPS_ERR LastErr() const { return m_last_err; } __forceinline int TotalWarns() const { return m_warns_s; } __forceinline ENUM_FILE_FOLDEROPS_WARN Warn(const int i) const { return m_warns[i]; } }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CFolderOpsBase::CFolderOpsBase(void) : m_arr_clean_inlcluyed_size(0), m_arr_clean_excluyed_size(0), m_last_err(FILE_FOLDEOPS_ERR_NOT), m_warns_s(0) { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CFolderOpsBase::Load(const string &json_file_name, bool comon_flag, CJsonParser &json_parser) { //--- m_warns_s = 0; //--- const int ext = json_parser.AssingFile(json_file_name, comon_flag); if(!json_parser.AutoParseByFileExt(ext)) { m_last_err = FILE_FOLDEOPS_ERR_PARSE_JSON; return false; } //--- CJsonNode root = json_parser.GetRoot(); //--- Inclusion CJsonNode incluyed = root["incluyed"]; if(!incluyed.IsValid()) { m_arr_clean_inlcluyed_size = ArrayResize(m_arr_clean_inlcluyed, 0); FILEFOLDESOPS_PUSH_WARN(FILE_FOLDEROPS_WARN_INCLUED_CAMP_NOT_FOUND) #ifdef MQLARTICLES_FOLDEROPS_ENABLE_LOGS FastLog(FUNCION_ACTUAL, WARNING_TEXT, "No se ha encontrado el campo 'incluyed' en el json config, todos los archivos se omitiran para su uso"); #endif // MQLARTICLES_FOLDEROPS_ENABLE_LOGS } else { m_arr_clean_inlcluyed_size = incluyed.ToArray(m_arr_clean_inlcluyed); } //--- Exclusion CJsonNode excluyed = root["excluyed"]; if(!excluyed.IsValid()) { m_arr_clean_excluyed_size = ArrayResize(m_arr_clean_excluyed, 0); FILEFOLDESOPS_PUSH_WARN(FILE_FOLDEROPS_WARN_EXCLUYED_CAMP_NOT_FOUND) #ifdef MQLARTICLES_FOLDEROPS_ENABLE_LOGS FastLog(FUNCION_ACTUAL, WARNING_TEXT, "No se ha encontrado el campo 'excluyed' en el json config, ningun archivo se excluira para su uso"); #endif // MQLARTICLES_FOLDEROPS_ENABLE_LOGS } else { m_arr_clean_excluyed_size = excluyed.ToArray(m_arr_clean_excluyed); } //--- return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CFolderOpsBase::Save(const string &json_file_name, int extra_file_flags, CJsonBuilder &json_builder) { //--- ::ResetLastError(); const int fh = FileOpen(json_file_name, FILE_WRITE | FILE_TXT | extra_file_flags, 0); if(fh == INVALID_HANDLE) { m_last_err = FILE_FOLDEOPS_ERR_OPENFILE; 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; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CFolderOpsBase::Summary() const { Print("----- CFolderOpsBase info"); Print("Incluyed: [", m_arr_clean_inlcluyed_size, "]"); Print(ArrayStrToString(m_arr_clean_inlcluyed, "|", m_arr_clean_inlcluyed_size)); Print("Excluyed: [", m_arr_clean_excluyed_size, "]"); Print(ArrayStrToString(m_arr_clean_excluyed, "|", m_arr_clean_excluyed_size)); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CFolderOpsBase::Clean(void) { m_arr_clean_inlcluyed_size = 0; m_arr_clean_excluyed_size = 0; } } #endif // MQLARTICLES_UTILS_FILE_FOLDEROPS_BASE_MQH //+------------------------------------------------------------------+ //+------------------------------------------------------------------+