mrDarker
2025-08-22 f8ad0695ff2431cb90640be52b523d6434bdbf83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "stdafx.h"
#include <io.h>
#include "FileRecipe.h"
#include <time.h>
#include <stdarg.h>
#include <direct.h>
#include <vector>
#include <Dbghelp.h>
#pragma comment(lib,"Dbghelp.lib")
 
CFileRecipe::CFileRecipe()
{
}
 
CFileRecipe::~CFileRecipe()
{
}
 
bool CFileRecipe::fileIsExist(std::string fileName) {
    /* code */
    if (-1 != _access(fileName.c_str(), 0)) return true;
 
    return false;
}
 
void CFileRecipe::removeDir(std::string dirPath) {
    /* code */
    struct _finddata_t fb;   // ²éÕÒÏàͬÊôÐÔÎļþµÄ´æ´¢½á¹¹Ìå
    string path;
    long long  handle; // ×¢Òâ´Ë´¦ÐèÒªlong*2
    int   noFile;            // ¶ÔϵͳÒþ²ØÎļþµÄ´¦Àí±ê¼Ç
 
    noFile = 0;
    handle = 0;
 
    struct stat s;
    if (stat(dirPath.c_str(), &s) == 0) {
        if (s.st_mode & S_IFDIR) {
            std::cout << "it's a directory" << std::endl;
        }
        else if (s.st_mode & S_IFREG) {
            std::cout << "it's a file" << std::endl;
        }
        else {
            std::cout << "not file not directory" << std::endl;
        }
    }
    else {
        std::cout << "error, doesn't exist" << std::endl;
        return;
    }
 
    path = dirPath + "/*";
 
    handle = _findfirst(path.c_str(), &fb);
    // ÕÒµ½µÚÒ»¸öÆ¥ÅäµÄÎļþ
    if (handle != 0){
        // µ±¿ÉÒÔ¼ÌÐøÕÒµ½Æ¥ÅäµÄÎļþ£¬¼ÌÐøÖ´ÐÐ
        while (0 == _findnext(handle, &fb)){
            // windowsÏ£¬³£ÓиöϵͳÎļþ£¬ÃûΪ¡°..¡±,¶ÔËü²»×ö´¦Àí
            noFile = strcmp(fb.name, "..");
 
            if (0 != noFile){
                path = dirPath + "/" + fb.name;
 
                // ÊôÐÔֵΪ16£¬Ôò˵Ã÷ÊÇÎļþ¼Ð£¬µü´ú
                if (fb.attrib == 16){
                    removeDir(path);
                }
                // ·ÇÎļþ¼ÐµÄÎļþ£¬Ö±½Óɾ³ý¡£¶ÔÎļþÊôÐÔÖµµÄÇé¿öû×öÏêϸµ÷²é£¬¿ÉÄÜ»¹ÓÐÆäËûÇé¿ö¡£
                else{
                    remove(path.c_str());
                }
            }
        }
        //ɾ³ý¿ÕĿ¼
//        _rmdir(dirPath.c_str());
        // ¹Ø±ÕÎļþ¼Ð£¬Ö»ÓйرÕÁ˲ÅÄÜɾ³ý¡£ÕÒÕâ¸öº¯ÊýÕÒÁ˺ܾ㬱ê×¼cÖÐÓõÄÊÇclosedir
        // ¾­Ñé½éÉÜ£ºÒ»°ã²úÉúHandleµÄº¯ÊýÖ´Ðк󣬶¼Òª½øÐйرյ͝×÷¡£
        _findclose(handle);
    }
}
 
void CFileRecipe::makeDir(std::string dirName) {
    /* code */
    MakeSureDirectoryPathExists(dirName.c_str());
}
 
bool CFileRecipe::openRecipeFile(CStdioFile &fileRecipe, CString fileName) {
    /* code */
    if (!fileRecipe.Open(fileName, CFile::modeCreate | CFile::modeReadWrite)) return false;
 
    return true;
}
 
bool CFileRecipe::readRecileFile(CStdioFile &fileRecipe, CString fileName) {
    /* code */
    if (!fileRecipe.Open(fileName, CFile::modeRead)) return false;
 
    return true;
}
 
CString CFileRecipe::toCString(std::string str) {
    /* code */
    CString strRes = CA2T(str.c_str());
    return strRes;
}
 
std::string CFileRecipe::toString(CString str) {
    /* code */
    std::string strRes(CT2A(str.GetString()));
    return strRes;
}
 
void CFileRecipe::WriteString(CStdioFile &fileRecipe, std::string strText) {
    /* code */
    CString str = toCString(strText);
    fileRecipe.WriteString(str);
}
 
void CFileRecipe::WriteCString(CStdioFile &fileRecipe, CString strText) {
    /* code */
    fileRecipe.WriteString(strText);
}
 
BOOL CFileRecipe::ReadString(CStdioFile &fileRecipe, CString &strRes) {
    /* code */
    return fileRecipe.ReadString(strRes);
}
 
void StringTrim(std::string& s) {
    /* code */
    if (!s.empty()) {
        s.erase(0, s.find_first_not_of(" "));
        s.erase(s.find_last_not_of(" ") + 1);
    }
}
 
int CFileRecipe::StringSplit(const std::string& strScr, const std::string& delim, std::vector<std::string>& strings) {
    /* code */
    strings.clear();
    size_t pos = 0;
    size_t len = strScr.length();
    size_t delim_len = delim.length();
    if (delim_len == 0) {
        return 0;
    }
 
    while (pos < len) {
        size_t find_pos = strScr.find(delim, pos);
        if (find_pos == strScr.npos) {
            std::string str2 = strScr.substr(pos, len - pos);
            StringTrim(str2);
            strings.push_back(str2);
            break;
        }
 
        std::string str2 = strScr.substr(pos, find_pos - pos);
        StringTrim(str2);
        strings.push_back(str2);
        pos = find_pos + delim_len;
    }
 
    return (int)strings.size();
}
 
int CFileRecipe::CStringSplit(const CString& strText, const std::string& delim, std::vector<std::string>& strings) {
    /* code */
    std::string str = toString(strText);
    return StringSplit(str, delim, strings);
}
 
int CFileRecipe::CStringToInt(CString strText) {
    /* code */
    int result = _wtoi(strText);
    return result;
}
 
int CFileRecipe::StringToInt(std::string str) {
    /* code */
    CString strText = toCString(str);
    return CStringToInt(strText);
}
 
double CFileRecipe::CStringToF(CString strText) {
    /* code */
    double result = _wtof(strText);
    return result;
}
 
double CFileRecipe::StringToF(std::string str) {
    /* code */
    CString strText = toCString(str);
    return CStringToF(strText);
}