Revisão | 6749 (tree) |
---|---|
Hora | 2017-05-27 09:24:51 |
Autor | (del#1144) |
FileDir の初期値をDownloads(XP以前はMy Documents)に変更
@@ -823,6 +823,37 @@ | ||
823 | 823 | return v; |
824 | 824 | } |
825 | 825 | |
826 | +void GetDownloadFolder(char *dest, int destlen) | |
827 | +{ | |
828 | + HMODULE hDll; | |
829 | + typedef GUID KNOWNFOLDERID; | |
830 | + typedef HRESULT(WINAPI *SHGETKNOWNFOLDERPATH)(KNOWNFOLDERID*, DWORD, HANDLE, PWSTR*); | |
831 | + // {374DE290-123F-4565-9164-39C4925E467B} | |
832 | + KNOWNFOLDERID FOLDERID_Downloads = { 0x374de290, 0x123f, 0x4565, 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b }; | |
833 | + char download[MAX_PATH]; | |
834 | + | |
835 | + memset(download, 0, sizeof(download)); | |
836 | + if (hDll = LoadLibrary("shell32.dll")) { | |
837 | + SHGETKNOWNFOLDERPATH pSHGetKnownFolderPath = (SHGETKNOWNFOLDERPATH)GetProcAddress(hDll, "SHGetKnownFolderPath"); | |
838 | + if (pSHGetKnownFolderPath) { | |
839 | + PWSTR pBuffer = NULL; | |
840 | + pSHGetKnownFolderPath(&FOLDERID_Downloads, 0, NULL, &pBuffer); | |
841 | + WideCharToMultiByte(CP_ACP, 0, pBuffer, -1, download, sizeof(download), NULL, NULL); | |
842 | + } | |
843 | + FreeLibrary(hDll); | |
844 | + } | |
845 | + if (strlen(download) == 0) { | |
846 | + LPITEMIDLIST pidl; | |
847 | + if (SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl) == NOERROR) { | |
848 | + SHGetPathFromIDList(pidl, download); | |
849 | + CoTaskMemFree(pidl); | |
850 | + } | |
851 | + } | |
852 | + if (strlen(download) > 0) { | |
853 | + strncpy_s(dest, destlen, download, _TRUNCATE); | |
854 | + } | |
855 | +} | |
856 | + | |
826 | 857 | void WINAPI GetDefaultFName(char *home, char *file, char *dest, int destlen) |
827 | 858 | { |
828 | 859 | // My Documents に file がある場合、 |
@@ -37,6 +37,7 @@ | ||
37 | 37 | BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest); |
38 | 38 | void GetNthNum(PCHAR Source, int Nth, int far *Num); |
39 | 39 | int GetNthNum2(PCHAR Source, int Nth, int defval); |
40 | +void GetDownloadFolder(char *dest, int destlen); | |
40 | 41 | void WINAPI GetDefaultFName(char *home, char *file, char *dest, int destlen); |
41 | 42 | void GetDefaultSetupFName(char *home, char *dest, int destlen); |
42 | 43 | void GetUILanguageFile(char *buf, int buflen); |
@@ -1102,11 +1102,11 @@ | ||
1102 | 1102 | GetPrivateProfileString(Section, "FileDir", "", |
1103 | 1103 | ts->FileDir, sizeof(ts->FileDir), FName); |
1104 | 1104 | if (strlen(ts->FileDir) == 0) |
1105 | - strncpy_s(ts->FileDir, sizeof(ts->FileDir), ts->HomeDir, _TRUNCATE); | |
1105 | + GetDownloadFolder(ts->FileDir, sizeof(ts->FileDir)); | |
1106 | 1106 | else { |
1107 | 1107 | _getcwd(Temp, sizeof(Temp)); |
1108 | 1108 | if (_chdir(ts->FileDir) != 0) |
1109 | - strncpy_s(ts->FileDir, sizeof(ts->FileDir), ts->HomeDir, _TRUNCATE); | |
1109 | + GetDownloadFolder(ts->FileDir, sizeof(ts->FileDir)); | |
1110 | 1110 | _chdir(Temp); |
1111 | 1111 | } |
1112 | 1112 |