OSDN Git Service

Move environment-related functions for getting windows path and user's Myfolders...
authorKimmo Varis <kimmov@gmail.com>
Mon, 14 Apr 2008 06:41:02 +0000 (06:41 +0000)
committerKimmo Varis <kimmov@gmail.com>
Mon, 14 Apr 2008 06:41:02 +0000 (06:41 +0000)
Src/Environment.cpp
Src/Environment.h
Src/FileOrFolderSelect.cpp
Src/Merge.cpp
Src/paths.cpp
Src/paths.h

index b327ac9..88568b9 100644 (file)
@@ -76,3 +76,42 @@ String env_GetTempFileName(LPCTSTR lpPathName, LPCTSTR lpPrefixString, int * pne
        }
        return buffer;
 }
+
+/**
+ * @brief Get Windows directory.
+ * @return Windows directory.
+ */
+String env_GetWindowsDirectory()
+{
+       TCHAR buf[MAX_PATH] = {0};
+       GetWindowsDirectory(buf, MAX_PATH);
+       return buf;
+}
+
+/**
+ * @brief Return User's My Documents Folder.
+ * This function returns full path to User's My Documents -folder.
+ * @param [in] hWindow Parent window.
+ * @return Full path to My Documents -folder.
+ */
+String env_GetMyDocuments(HWND hWindow)
+{
+       LPITEMIDLIST pidl;
+       LPMALLOC pMalloc;
+       String path;
+
+       HRESULT rv = SHGetSpecialFolderLocation(hWindow, CSIDL_PERSONAL, &pidl);
+       if (rv == S_OK)
+       {
+               TCHAR szPath[MAX_PATH] = {0};
+               if (SHGetPathFromIDList(pidl, szPath))
+               {
+                       path = szPath;
+               }
+
+               SHGetMalloc(&pMalloc);
+               pMalloc->Free(pidl);
+               pMalloc->Release();
+       }
+       return path;
+}
index fb5a95f..a5519dc 100644 (file)
@@ -13,5 +13,7 @@ LPCTSTR env_GetTempPath(int * pnerr = NULL);
 String env_GetTempFileName(LPCTSTR lpPathName, LPCTSTR lpPrefixString,
                int * pnerr = NULL);
 
+String env_GetWindowsDirectory();
+String env_GetMyDocuments(HWND hWindow);
 
 #endif // _ENVIRONMENT_H_
index d9a1f46..d26bc4d 100644 (file)
@@ -29,6 +29,7 @@
 #include "stdafx.h"
 #include <sys/stat.h>
 #include "UnicodeString.h"
+#include "Environment.h"
 #include "FileOrFolderSelect.h"
 #include "coretools.h"
 #include "paths.h"
@@ -127,7 +128,7 @@ BOOL SelectFile(HWND parent, CString& path, LPCTSTR initialPath /*=NULL*/,
                bRetVal = GetSaveFileName((OPENFILENAME *)&ofn);
        // common file dialog populated sSelectedFile variable's buffer
        sSelectedFile.ReleaseBuffer();
-       SetCurrentDirectory(paths_GetWindowsDirectory().c_str()); // Free handle held by GetOpenFileName
+       SetCurrentDirectory(env_GetWindowsDirectory().c_str()); // Free handle held by GetOpenFileName
 
        if (bRetVal)
                path = sSelectedFile;
@@ -254,7 +255,7 @@ BOOL SelectFileOrFolder(HWND parent, CString& path, LPCTSTR initialPath /*=NULL*
        BOOL bRetVal = GetOpenFileName((OPENFILENAME *)&ofn);
        // common file dialog populated sSelectedFile variable's buffer
        sSelectedFile.ReleaseBuffer();
-       SetCurrentDirectory(paths_GetWindowsDirectory().c_str()); // Free handle held by GetOpenFileName
+       SetCurrentDirectory(env_GetWindowsDirectory().c_str()); // Free handle held by GetOpenFileName
 
        if (bRetVal)
        {
index 5c3ea20..e1aa7d3 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "stdafx.h"
 #include "UnicodeString.h"
+#include "Environment.h"
 #include "OptionsMgr.h"
 #include "Merge.h"
 #include "AboutDlg.h"
@@ -820,7 +821,7 @@ static String CmdlineOption(int idres)
  */
 CString CMergeApp::GetDefaultEditor()
 {
-       CString path = paths_GetWindowsDirectory().c_str();
+       CString path = env_GetWindowsDirectory().c_str();
        path += _T("\\NOTEPAD.EXE");
        return path;
 }
@@ -837,7 +838,7 @@ CString CMergeApp::GetDefaultEditor()
  */
 CString CMergeApp::GetDefaultFilterUserPath(BOOL bCreate /*=FALSE*/)
 {
-       CString pathMyFolders = paths_GetMyDocuments(NULL).c_str();
+       CString pathMyFolders = env_GetMyDocuments(NULL).c_str();
        CString pathFilters(pathMyFolders);
        if (pathFilters.Right(1) != _T("\\"))
                pathFilters += _T("\\");
index 8c10bf6..2261c62 100644 (file)
@@ -572,41 +572,3 @@ String paths_EnsurePathExist(const String & sPath)
                return _T("");
 }
 
-/**
- * @brief Get Windows directory.
- * @return Windows directory.
- */
-String paths_GetWindowsDirectory()
-{
-       TCHAR buf[MAX_PATH] = {0};
-       GetWindowsDirectory(buf, MAX_PATH);
-       return buf;
-}
-
-/**
- * @brief Return User's My Documents Folder.
- * This function returns full path to User's My Documents -folder.
- * @param [in] hWindow Parent window.
- * @return Full path to My Documents -folder.
- */
-String paths_GetMyDocuments(HWND hWindow)
-{
-       LPITEMIDLIST pidl;
-       LPMALLOC pMalloc;
-       String path;
-
-       HRESULT rv = SHGetSpecialFolderLocation(hWindow, CSIDL_PERSONAL, &pidl);
-       if (rv == S_OK)
-       {
-               TCHAR szPath[MAX_PATH] = {0};
-               if (SHGetPathFromIDList(pidl, szPath))
-               {
-                       path = szPath;
-               }
-
-               SHGetMalloc(&pMalloc);
-               pMalloc->Free(pidl);
-               pMalloc->Release();
-       }
-       return path;
-}
index 35d1300..0c94fc5 100644 (file)
@@ -35,7 +35,5 @@ String paths_GetParentPath(LPCTSTR path);
 String paths_GetLastSubdir(const String & path);
 BOOL paths_IsPathAbsolute(const String & path);
 String paths_EnsurePathExist(const String & sPath);
-String paths_GetWindowsDirectory();
-String paths_GetMyDocuments(HWND hWindow);
 
 #endif // paths_h_included