* @brief Cleanup tempfiles created by WinMerge. * This function finds temp folders which don't have WinMerge instance using * them anymore. */
| 118 | * them anymore. |
| 119 | */ |
| 120 | void CleanupWMtemp() |
| 121 | { |
| 122 | DirItemArray dirs, files; |
| 123 | DirTravel::LoadFiles(paths::GetParentPath(env::GetTemporaryPath()), &dirs, &files, String(TempFolderPrefix) + _T("*")); |
| 124 | |
| 125 | for (auto& dir : dirs) |
| 126 | { |
| 127 | const String foldername = dir.filename; |
| 128 | // Remove leading "WM_" from filename to get the ProcessID |
| 129 | const String tempfolderPID = foldername.substr(tc::tcslen(TempFolderPrefix)); |
| 130 | // Check if this instance of WM is still running |
| 131 | try |
| 132 | { |
| 133 | int pid = atoi(ucr::toUTF8(tempfolderPID).c_str()); |
| 134 | if (!WMrunning(pid)) |
| 135 | ClearTempfolder(paths::ConcatPath(dir.path, foldername)); |
| 136 | } |
| 137 | catch (...) |
| 138 | { |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @brief Is WinMerge with given processID running? |
no test coverage detected