}
/**
- * @brief Construct path to a temporary folder for pOwner, and clear the folder.
- */
-String NTAPI GetClearTempPath(LPVOID pOwner, LPCTSTR pchExt)
-{
- String strPath = string_format
- (
- pOwner ? _T("%sWINMERGE.%08lX\\%08lX.%s") : _T("%sWINMERGE.%08lX"),
- env_GetTempPath().c_str(), GetCurrentProcessId(), pOwner, pchExt
- );
- // SHFileOperation expects a ZZ terminated list of paths!
- String::size_type len = strPath.size();
- strPath.resize(len + 1);
- SHFILEOPSTRUCT fileop =
- {
- 0, FO_DELETE, &strPath[0], 0,
- FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI,
- 0, 0, 0
- };
- SHFileOperation(&fileop);
- strPath.resize(len);
- return strPath;
-}
-
-/**
* @brief Delete head of temp path context list, and return its parent context.
*/
CTempPathContext *CTempPathContext::DeleteHead()
{
CTempPathContext *pParent = m_pParent;
- GetClearTempPath(this, _T("*"));
delete this;
return pParent;
}
bool IsArchiveFile(const String&);
Merge7z::Format *ArchiveGuessFormat(const String&);
-String NTAPI GetClearTempPath(LPVOID pOwner, LPCTSTR pchExt);
-
/**
* @brief temp path context
*/
return buffer;
}
+String env_GetTempChildPath()
+{
+ String path;
+ do
+ {
+ path = paths_ConcatPath(env_GetTempPath(), string_format(_T("%08x"), rand()));
+ } while (paths_IsDirectory(path) || !paths_CreateIfNeeded(path));
+ return path;
+}
+
void env_SetProgPath(const String& path)
{
strProgPath = path;
String env_GetTempPath();
String env_GetTempFileName(const String& lpPathName, const String& lpPrefixString,
int * pnerr = NULL);
+String env_GetTempChildPath();
void env_SetProgPath(const String& path);
String env_GetProgPath();
{
GetLog()->EnableLogging(FALSE);
- // Delete all temporary folders belonging to this process
- GetClearTempPath(NULL, NULL);
-
// Remove files from temp file list.
while (!m_tempFiles.empty())
{
if (Merge7z::Format *piHandler = ArchiveGuessFormat(files[0].c_str()))
{
pTempPathContext = new CTempPathContext;
- path = GetClearTempPath(pTempPathContext, _T("0"));
+ path = env_GetTempChildPath();
for (int index = 0; index < files.GetSize(); index++)
pTempPathContext->m_strDisplayRoot[index] = files[index];
pathsType = IS_EXISTING_DIR;
for (int index = 0; index < files.GetSize(); index++)
pTempPathContext->m_strDisplayRoot[index] = files[index];
}
- path = GetClearTempPath(pTempPathContext, _T("1"));
+ path = env_GetTempChildPath();
do
{
if FAILED(piHandler->DeCompressArchive(m_hWnd, files[1].c_str(), path.c_str()))
for (int index = 0; index < files.GetSize(); index++)
pTempPathContext->m_strDisplayRoot[index] = files[index];
}
- path = GetClearTempPath(pTempPathContext, _T("2"));
+ path = env_GetTempChildPath();
do
{
if FAILED(piHandler->DeCompressArchive(m_hWnd, files[2].c_str(), path.c_str()))