OSDN Git Service

TempFile.cpp: Use Poco::File::remove() instead of SHFileOperation()
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 3 Feb 2019 05:43:54 +0000 (14:43 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 3 Feb 2019 05:43:54 +0000 (14:43 +0900)
SHFileOperation() is slow.

--HG--
branch : stable

Src/TempFile.cpp

index cbe50d9..3edd496 100644 (file)
@@ -218,16 +218,13 @@ static bool WMrunning(const vector<int>& processIDs, int iPI)
  */
 bool ClearTempfolder(const String &pathName)
 {
-       // SHFileOperation expects a ZZ terminated list of paths!
-       String normalizedPathName = pathName;
-       paths::normalize(normalizedPathName); // remove trailing slash
-       const size_t pathSize = normalizedPathName.length() + 2;
-       std::vector<TCHAR> path(pathSize, 0);
-       memcpy(&path[0], normalizedPathName.c_str(), normalizedPathName.length() * sizeof(TCHAR));
-
-       SHFILEOPSTRUCT fileop = {0, FO_DELETE, &path[0], 0, FOF_NOCONFIRMATION |
-                       FOF_SILENT | FOF_NOERRORUI, 0, 0, 0};
-       SHFileOperation(&fileop);
-
+       try
+       {
+               TFile(pathName).remove(true);
+       }
+       catch (...)
+       {
+               return false;
+       }
        return true;
 }