[ttssh2-commit] [9413] GetDownloadFolder() から _SHGetKnownFolderPath() を使用

Zurück zum Archiv-Index
scmno****@osdn***** scmno****@osdn*****
2021年 9月 12日 (日) 01:12:54 JST


Revision: 9413
          https://osdn.net/projects/ttssh2/scm/svn/commits/9413
Author:   zmatsuo
Date:     2021-09-12 01:12:53 +0900 (Sun, 12 Sep 2021)
Log Message:
-----------
GetDownloadFolder() から _SHGetKnownFolderPath() を使用

- _SHGetKnownFolderPath() と同様の実装だった
- GetDownloadFolderW() を追加
- GetDownloadFolder() を GetDownloadFolderW() のラッパに変更

Modified Paths:
--------------
    trunk/teraterm/common/compat_win.cpp
    trunk/teraterm/common/ttknownfolders.h
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/ttlib_static_cpp.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/compat_win.cpp
===================================================================
--- trunk/teraterm/common/compat_win.cpp	2021-09-11 16:12:44 UTC (rev 9412)
+++ trunk/teraterm/common/compat_win.cpp	2021-09-11 16:12:53 UTC (rev 9413)
@@ -511,8 +511,9 @@
 		int csidl;
 	} list[] = {
 		{ FOLDERID_Desktop, CSIDL_DESKTOPDIRECTORY },
-		{ FOLDERID_Documents, CSIDL_PERSONAL },	// My Documents
+		{ FOLDERID_Documents, CSIDL_MYDOCUMENTS },	// %USERPROFILE%\My Documents
 		{ FOLDERID_LocalAppData, CSIDL_LOCAL_APPDATA },
+		{ FOLDERID_Downloads, CSIDL_MYDOCUMENTS },	// %USERPROFILE%\Downloads, My Documents
 	};
 
 	for (size_t i = 0; i < _countof(list); i++) {

Modified: trunk/teraterm/common/ttknownfolders.h
===================================================================
--- trunk/teraterm/common/ttknownfolders.h	2021-09-11 16:12:44 UTC (rev 9412)
+++ trunk/teraterm/common/ttknownfolders.h	2021-09-11 16:12:53 UTC (rev 9413)
@@ -47,3 +47,4 @@
 DEFINE_KNOWN_FOLDER(FOLDERID_Desktop, 0xB4BFCC3A, 0xDB2C, 0x424C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41);
 DEFINE_KNOWN_FOLDER(FOLDERID_Documents, 0xFDD39AD0, 0x238F, 0x46AF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7);
 DEFINE_KNOWN_FOLDER(FOLDERID_LocalAppData, 0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91);
+DEFINE_KNOWN_FOLDER(FOLDERID_Downloads, 0x374de290, 0x123f, 0x4565, 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b);

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2021-09-11 16:12:44 UTC (rev 9412)
+++ trunk/teraterm/common/ttlib.c	2021-09-11 16:12:53 UTC (rev 9413)
@@ -823,33 +823,9 @@
 
 void GetDownloadFolder(char *dest, int destlen)
 {
-	HMODULE hDll;
-	typedef GUID KNOWNFOLDERID;
-	typedef HRESULT(WINAPI *SHGETKNOWNFOLDERPATH)(KNOWNFOLDERID*, DWORD, HANDLE, PWSTR*);
-	// {374DE290-123F-4565-9164-39C4925E467B}
-	KNOWNFOLDERID FOLDERID_Downloads = { 0x374de290, 0x123f, 0x4565, 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b };
-	char download[MAX_PATH];
-
-	memset(download, 0, sizeof(download));
-	if (hDll = LoadLibrary("shell32.dll")) {
-		SHGETKNOWNFOLDERPATH pSHGetKnownFolderPath = (SHGETKNOWNFOLDERPATH)GetProcAddress(hDll, "SHGetKnownFolderPath");
-		if (pSHGetKnownFolderPath) {
-			PWSTR pBuffer = NULL;
-			pSHGetKnownFolderPath(&FOLDERID_Downloads, 0, NULL, &pBuffer);
-			WideCharToMultiByte(CP_ACP, 0, pBuffer, -1, download, sizeof(download), NULL, NULL);
-		}
-		FreeLibrary(hDll);
-	}
-	if (strlen(download) == 0) {
-		LPITEMIDLIST pidl;
-		if (SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl) == NOERROR) {
-			SHGetPathFromIDList(pidl, download);
-			CoTaskMemFree(pidl);
-		}
-	}
-	if (strlen(download) > 0) {
-		strncpy_s(dest, destlen, download, _TRUNCATE);
-	}
+	wchar_t *download = GetDownloadFolderW();
+	WideCharToACP_t(download, dest, destlen);
+	free(download);
 }
 
 void GetDefaultFName(const char *home, const char *file, char *dest, int destlen)

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2021-09-11 16:12:44 UTC (rev 9412)
+++ trunk/teraterm/common/ttlib.h	2021-09-11 16:12:53 UTC (rev 9413)
@@ -81,6 +81,7 @@
 void GetNthNum(PCHAR Source, int Nth, int *Num);
 int GetNthNum2(PCHAR Source, int Nth, int defval);
 void GetDownloadFolder(char *dest, int destlen);
+wchar_t *GetDownloadFolderW(void);
 wchar_t *GetHomeDirW(HINSTANCE hInst);
 void GetDefaultFName(const char *home, const char *file, char *dest, int destlen);
 wchar_t *GetDefaultFNameW(const wchar_t *home, const wchar_t *file);

Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2021-09-11 16:12:44 UTC (rev 9412)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2021-09-11 16:12:53 UTC (rev 9413)
@@ -43,6 +43,7 @@
 #include "asprintf.h"
 #include "win32helper.h"
 #include "codeconv.h"
+#include "compat_win.h"
 
 #include "ttlib.h"
 
@@ -1063,3 +1064,10 @@
 
 	return v;
 }
+
+wchar_t *GetDownloadFolderW(void)
+{
+	wchar_t *download;
+	_SHGetKnownFolderPath(FOLDERID_Downloads, 0, NULL, &download);
+	return download;
+}


ttssh2-commit メーリングリストの案内
Zurück zum Archiv-Index