From 20aa446433e62eb1312b5fa755724375bad0389d Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 14 Apr 2008 06:41:02 +0000 Subject: [PATCH] Move environment-related functions for getting windows path and user's Myfolders-path from paths.h/cpp to Environment.h/cpp. --- Src/Environment.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Src/Environment.h | 2 ++ Src/FileOrFolderSelect.cpp | 5 +++-- Src/Merge.cpp | 5 +++-- Src/paths.cpp | 38 -------------------------------------- Src/paths.h | 2 -- 6 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Src/Environment.cpp b/Src/Environment.cpp index b327ac95d..88568b9ba 100644 --- a/Src/Environment.cpp +++ b/Src/Environment.cpp @@ -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; +} diff --git a/Src/Environment.h b/Src/Environment.h index fb5a95f03..a5519dc4c 100644 --- a/Src/Environment.h +++ b/Src/Environment.h @@ -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_ diff --git a/Src/FileOrFolderSelect.cpp b/Src/FileOrFolderSelect.cpp index d9a1f46ef..d26bc4df6 100644 --- a/Src/FileOrFolderSelect.cpp +++ b/Src/FileOrFolderSelect.cpp @@ -29,6 +29,7 @@ #include "stdafx.h" #include #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) { diff --git a/Src/Merge.cpp b/Src/Merge.cpp index 5c3ea20ee..e1aa7d3c6 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -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("\\"); diff --git a/Src/paths.cpp b/Src/paths.cpp index 8c10bf64a..2261c6272 100644 --- a/Src/paths.cpp +++ b/Src/paths.cpp @@ -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; -} diff --git a/Src/paths.h b/Src/paths.h index 35d130075..0c94fc5f5 100644 --- a/Src/paths.h +++ b/Src/paths.h @@ -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 -- 2.11.0