MCPcopy Create free account
hub / github.com/BlueMatthew/WechatExporter / isValidFileName

Function isValidFileName

WechatExporter/core/FileSystem.cpp:496–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496bool isValidFileName(const std::string& fileName)
497{
498#ifdef _WIN32
499 TCHAR tmpPath[MAX_PATH] = { 0 };
500 if (GetTempPath(MAX_PATH, tmpPath))
501 {
502 // CT2A t2a(charPath);
503 // tempDir = (LPCSTR)t2a;
504 }
505
506 TCHAR path[MAX_PATH] = { 0 };
507 CW2T pszT(CA2W(fileName.c_str(), CP_UTF8));
508 ::PathCombine(path, tmpPath, (LPCTSTR)pszT);
509
510 bool valid = false;
511 if (::CreateDirectory(path, NULL))
512 {
513 valid = true;
514 RemoveDirectory(path);
515 }
516 else
517 {
518 valid = (::GetLastError() == ERROR_ALREADY_EXISTS);
519 }
520 return valid;
521#else
522 char const *tmpdir = getenv("TMPDIR");
523
524 std::string tempDir;
525
526 if (tmpdir == NULL)
527 {
528 tempDir = "/tmp";
529 }
530 else
531 {
532 tempDir = tmpdir;
533 }
534
535 std::string path = combinePath(tempDir, fileName);
536 int status = mkdir(path.c_str(), 0);
537 int lastErrorNo = errno;
538 if (status == 0)
539 {
540 remove(path.c_str());
541 }
542
543 return status == 0 || lastErrorNo == EEXIST;
544#endif
545}
546
547
548std::string readFile(const std::string& path)

Callers 1

buildFileNameForUserMethod · 0.85

Calls 1

combinePathFunction · 0.85

Tested by

no test coverage detected