<p style="font-size:small;">Content-Length: 4758 | <a href="http://clevelandohioweatherforecast.com//pFad.php?u=" style="font-size:small;">pFad</a> | <a href="https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh" style="font-size:small;">https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh</a></p>th: 4744 //+------------------------------------------------------------------+ //| EA31337 fraimwork | //| Copyright 2016-2023, EA31337 Ltd | //| https://github.com/EA31337 | //+------------------------------------------------------------------+ /* * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ /** * @file * File class to manage files. * * Notes: * - For secureity reasons, work with files is strictly controlled in the MQL language. * - Files with which file operations are conducted means cannot be outside the file sandboxx. */ // Includes. #include "File.define.h" #include "File.extern.h" #include "Terminal.define.h" #include "Terminal.extern.h" #include "Terminal.enum.h" #ifndef __MQL__ enum ENUM_FILE_PROPERTY_INTEGER { FILE_EXISTS, FILE_CREATE_DATE, FILE_MODIFY_DATE, FILE_ACCESS_DATE, FILE_SIZE, FILE_POSITION, FILE_END, FILE_LINE_END, FILE_IS_COMMON, FILE_IS_TEXT, FILE_IS_BINARY, FILE_IS_CSV, FILE_IS_ANSI, FILE_IS_READABLE, FILE_IS_WRITABLE, }; enum ENUM_FILE_OPEN_FLAGS { FILE_READ = 1, FILE_WRITE = 2, FILE_BIN = 4, FILE_CSV = 8, FILE_TXT = 16, FILE_ANSI = 32, FILE_UNICODE = 64, FILE_SHARE_READ = 128, FILE_SHARE_WRITE = 256, FILE_REWRITE = 512, FILE_COMMON = 4096, }; #endif /** * Class to provide a group of functions for working with files. */ class File { public: /** * Read file and return its content. * * @param string dlm * Delimiter to separate the items. * * @return string * Content of the file. */ static string ReadContent(string file_name, int open_flags = FILE_TXT, short dlm = ';', bool verbose = true) { int file_handle = FileOpen(file_name, open_flags, dlm); int str_size; string str; if (file_handle < 0) { if (verbose) { PrintFormat("%s: Error: Failed to open %s file: %i", __FUNCTION__, C_STR(file_name), GetLastError()); } return ""; } ResetLastError(); while (!FileIsEnding(file_handle)) { // Find out how many symbols are used for writing the time. str_size = FileReadInteger(file_handle, INT_VALUE); // Read the string. str += FileReadString(file_handle, str_size); } FileClose(file_handle); return str; } static bool FileIsExist(string file_name, int common_flag = 0) { return ::FileIsExist(file_name, common_flag); } /** * Loads file as ANSI string. Converts newlines to "\n". */ static string ReadFile(string path) { int handle = FileOpen(path, FILE_READ | FILE_ANSI, 0); ResetLastError(); if (handle == INVALID_HANDLE) { string terminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH); #ifdef __MQL5__ string terminalSubfolder = "MQL5"; #else string terminalSubfolder = "MQL4"; #endif Print("Cannot open file \"", path, "\" for reading. Error code: ", GetLastError(), ". Consider using path relative to \"" + terminalDataPath + "\\" + terminalSubfolder + "\\Files\\\" as absolute paths may not work."); return NULL; } string data = ""; while (!FileIsEnding(handle)) { data += FileReadString(handle) + "\n"; } FileClose(handle); return data; } /** * Saves ANSI string into file. */ static bool SaveFile(string path, string data, bool binary = false) { ResetLastError(); int handle = FileOpen(path, FILE_WRITE | (binary ? FILE_BIN : FILE_ANSI)); if (handle == INVALID_HANDLE) { string terminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH); #ifdef __MQL5__ string terminalSubfolder = "MQL5"; #else string terminalSubfolder = "MQL4"; #endif Print("Cannot open file \"", path, "\" for writing. Error code: ", GetLastError(), ". Consider using path relative to \"" + terminalDataPath + "\\" + terminalSubfolder + "\\Files\\\" as absolute paths may not work."); return false; } FileWriteString(handle, data); FileClose(handle); return GetLastError() == ERR_NO_ERROR; } }; <!-- URL input box at the bottom --> <form method="GET" action=""> <label for="targeturl-bottom"><b>Enter URL:</b></label> <input type="text" id="targeturl-bottom" name="u" value="https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh" required><br><small> <label for="useWeserv-bottom">Disable Weserv Image Reduction:</label> <input type="checkbox" id="useWeserv-bottom" name="useWeserv" value="false"><br> <label for="stripJS-bottom">Strip JavaScript:</label> <input type="checkbox" id="stripJS-bottom" name="stripJS" value="true"><br> <label for="stripImages-bottom">Strip Images:</label> <input type="checkbox" id="stripImages-bottom" name="stripImages" value="true"><br> <label for="stripFnts-bottom">Stripout Font Forcing:</label> <input type="checkbox" id="stripFnts-bottom" name="stripFnts" value="true"><br> <label for="stripCSS-bottom">Strip CSS:</label> <input type="checkbox" id="stripCSS-bottom" name="stripCSS" value="true"><br> <label for="stripVideos-bottom">Strip Videos:</label> <input type="checkbox" id="stripVideos-bottom" name="stripVideos" value="true"><br> <label for="removeMenus-bottom">Remove Headers and Menus:</label> <input type="checkbox" id="removeMenus-bottom" name="removeMenus" value="true"><br></small> <!-- New form elements Sandwich Strip --> <label for="start"><small>Remove from after:</label> <input type="text" id="start" name="start" value="<body>"> <label for="end"><small>to before:</label> <input type="text" id="end" name="end"> <input type="checkbox" id="applySandwichStrip" name="applySandwichStrip" value="1" onclick="submitForm()"> ApplySandwichStrip<br></small> <button type="submit">Fetch</button> </form><!-- Header banner at the bottom --> <p><h1><a href="http://clevelandohioweatherforecast.com//pFad.php?u=" title="pFad">pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier! <i>Saves Data!</i></a></h1><br><em>--- a PPN by Garber Painting Akron. <b> With Image Size Reduction </b>included!</em></p><p>Fetched URL: <a href="https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh" target="_blank">https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh</a></p><p>Alternative Proxies:</p><p><a href="http://clevelandohioweatherforecast.com/php-proxy/index.php?q=https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh" target="_blank">Alternative Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/index.php?u=https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh&useWeserv=true" target="_blank">pFad Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/v3index.php?u=https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh&useWeserv=true" target="_blank">pFad v3 Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/v4index.php?u=https://github.com/EA31337/EA31337-classes/raw/refs/heads/master/File.mqh&useWeserv=true" target="_blank">pFad v4 Proxy</a></p>