将程序获取的本地用户数据路径存储到临时目录下的scanner-first.log文件中
This commit is contained in:
parent
ed4902b1ac
commit
e590c9e4af
|
@ -585,7 +585,10 @@ namespace utils
|
|||
ldp += "Scan";
|
||||
create_folder(ldp.c_str());
|
||||
|
||||
printf("# local data path: %s\n", ldp.c_str());
|
||||
std::string first("[" + format_current_time() + "]: Process "),
|
||||
ff(temporary_path() + PATH_SEPARATOR + "scanner-first.log");
|
||||
first += std::to_string(GetCurrentProcessId()) + " root of local data path is " + ldp + "\n";
|
||||
save_2_file(&first[0], first.length(), ff.c_str());
|
||||
}
|
||||
|
||||
return ldp;
|
||||
|
@ -664,6 +667,58 @@ namespace utils
|
|||
|
||||
return buf;
|
||||
}
|
||||
std::string load_mini_file(const char* file, int* err)
|
||||
{
|
||||
std::string cont("");
|
||||
FILE* src = fopen(file, "rb");
|
||||
|
||||
if (src)
|
||||
{
|
||||
long len = 0;
|
||||
|
||||
fseek(src, 0, SEEK_END);
|
||||
len = ftell(src);
|
||||
fseek(src, 0, SEEK_SET);
|
||||
if (len > SIZE_MB(1))
|
||||
{
|
||||
if (err)
|
||||
*err = E2BIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* buf = new char[len];
|
||||
if (buf)
|
||||
{
|
||||
len = fread(buf, 1, len, src);
|
||||
cont = std::string(buf, len);
|
||||
if (err)
|
||||
*err = 0;
|
||||
delete[] buf;
|
||||
}
|
||||
else if (err)
|
||||
*err = ENOMEM;
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
else if (err)
|
||||
*err = errno;
|
||||
|
||||
return std::move(cont);
|
||||
}
|
||||
int save_2_file(void* data, size_t len, const char* file, bool append)
|
||||
{
|
||||
FILE* dst = fopen(file, append ? "w+b" : "wb");
|
||||
int err = 0;
|
||||
|
||||
if (!dst)
|
||||
return errno;
|
||||
|
||||
if (fwrite(data, 1, len, dst) < len)
|
||||
err = ENOSPC;
|
||||
fclose(dst);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
const char* to_lower(std::string& str)
|
||||
{
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace utils
|
|||
std::string get_module_full_path(const char* part_name = nullptr/*nullptr to get main-pe/first module's full path*/);
|
||||
std::string target_file_from_link(const char* lnk_file);
|
||||
std::string get_ini_value(const char* seg, const char* key, const char* cfg_file); // return "" if not found
|
||||
std::string load_mini_file(const char* file, int* err); // <= 1MB
|
||||
int save_2_file(void* data, size_t len, const char* file);
|
||||
|
||||
const char* to_lower(std::string& str); // return str.c_str()
|
||||
const char* trim(std::string& str, const char* sp = "\r\n\t "); // return str.c_str()
|
||||
|
|
Loading…
Reference in New Issue