OSDN Git Service

Defer deleting temporary files. issue #18
authorsdottaka <none@none>
Sat, 6 Apr 2013 13:37:27 +0000 (22:37 +0900)
committersdottaka <none@none>
Sat, 6 Apr 2013 13:37:27 +0000 (22:37 +0900)
Src/7zCommon.cpp
Src/7zCommon.h
Src/Environment.cpp
Src/Environment.h
Src/MainFrm.cpp

index e74e09c..7d4751a 100644 (file)
@@ -629,36 +629,11 @@ void NTAPI Recall7ZipMismatchError()
 }
 
 /**
- * @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;
 }
index 7f33514..0c64fd5 100644 (file)
@@ -16,8 +16,6 @@ extern __declspec(thread) Merge7z::Proxy Merge7z;
 bool IsArchiveFile(const String&);
 Merge7z::Format *ArchiveGuessFormat(const String&);
 
-String NTAPI GetClearTempPath(LPVOID pOwner, LPCTSTR pchExt);
-
 /**
  * @brief temp path context
  */
index 9b23a31..9d49bf4 100644 (file)
@@ -78,6 +78,16 @@ String env_GetTempFileName(const String& lpPathName, const String& lpPrefixStrin
        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;
index e3863eb..07feec0 100644 (file)
@@ -15,6 +15,7 @@ void env_SetTempPath(const String& 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();
 
index b95e5a9..6084ea7 100644 (file)
@@ -341,9 +341,6 @@ CMainFrame::~CMainFrame()
 {
        GetLog()->EnableLogging(FALSE);
 
-       // Delete all temporary folders belonging to this process
-       GetClearTempPath(NULL, NULL);
-
        // Remove files from temp file list.
        while (!m_tempFiles.empty())
        {
@@ -1190,7 +1187,7 @@ BOOL CMainFrame::DoFileOpen(PathContext * pFiles /*=NULL*/,
                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;
@@ -1226,7 +1223,7 @@ BOOL CMainFrame::DoFileOpen(PathContext * pFiles /*=NULL*/,
                                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()))
@@ -1253,7 +1250,7 @@ BOOL CMainFrame::DoFileOpen(PathContext * pFiles /*=NULL*/,
                                        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()))