//
// Created by Ht on 2019/8/1.
//

#ifndef JSONPROTOCOL_FILEUTILS_H
#define JSONPROTOCOL_FILEUTILS_H

#include <string>
#include <vector>
#include <jebase/config.h>

#ifdef _WIN32
#define C_FILE_SEP '\\'
#define C_FILE_SEPD '/'
#define S_FILE_SEP "\\"
#define S_FILE_SEPD "/"
#else
#define C_FILE_SEP '/'
#define C_FILE_SEPD '\\'
#define S_FILE_SEP "/"
#define S_FILE_SEPD "\\"
#endif

#define C_FILE_EXT '.'
#define S_FILE_EXT "."

#if defined(WIN32)
#define DEFAULT_CURRENT_PATH ".\\"
#else
#define DEFAULT_CURRENT_PATH "./"
#endif

#ifndef APPSRC
#define APPSRC "."
//#error "APPSRC Must be defined in compile params"
#endif

class JE_API FileUtils {

public:
    static int listFiles(const std::string& dir, const std::string& ext, std::vector<std::string>& files, bool caseIgnore = true);

    static int listFiles(const std::string& dir, const std::string& prefix, const std::string& suffix, std::vector<std::string>& files, bool caseIgnore = true);

    static std::string fileNameWithoutExt(const std::string &orgFn);

    static std::string fileNameWithNoPath(const std::string &orgFn);

    static bool fileExists(const std::string& fileName);

    static bool isFileDir(const std::string& fileName);

    static std::string contactFilename(const std::string &dest, const std::string &fn);

    static std::string& appendFilename(std::string &dest, const std::string &fn);

    static std::string& contactFileNames(std::string &dest, const char* sub, ...);

    static std::string contactFilenames(const std::string &src, const char *sub, ...);

    static std::string dirName(const std::string &filename_with_path);

    static std::string pathName(const std::string &file_with_path);

    static std::string extOfFileName(const std::string &fileName);

    static void removeFile(const std::string &filename);

    static bool removeDir(const std::string &filename);

    static std::string getJedgeAppBaseDir(const std::string& appSrc);

    static bool copyFile(const std::string &src, const std::string &dest, bool binary = false);

    static char getFileConnector();

};


#endif //JSONPROTOCOL_FILEUTILS_H
