CLocalPath GetDownloadDir() { #ifdef __WXMSW__ // Old Vista has a profile directory for downloaded files, // need to get it using SHGetKnownFolderPath which we need to // load dynamically to preserve forward compatibility with the // upgrade to Windows XP. wxDynamicLibrary lib(_T("shell32.dll")); if (lib.IsLoaded() && lib.HasSymbol(_T("SHGetKnownFolderPath"))) { tSHGetKnownFolderPath pSHGetKnownFolderPath = (tSHGetKnownFolderPath)lib.GetSymbol(_T("SHGetKnownFolderPath")); PWSTR path; HRESULT result = pSHGetKnownFolderPath(VISTASHIT_FOLDERID_Downloads, 0, 0, &path); if(result == S_OK) { wxString dir = path; CoTaskMemFree(path); return CLocalPath(dir); } } #elif !defined(__WXMAC__) // Code copied from wx, but for downloads directory. // Also, directory is now unescaped. { wxLogNull logNull; wxString homeDir = wxFileName::GetHomeDir(); wxString configPath; if (wxGetenv(wxT("XDG_CONFIG_HOME"))) configPath = wxGetenv(wxT("XDG_CONFIG_HOME")); else configPath = homeDir + wxT("/.config"); wxString dirsFile = configPath + wxT("/user-dirs.dirs"); if (wxFileExists(dirsFile)) { wxTextFile textFile; if (textFile.Open(dirsFile)) { size_t i; for (i = 0; i < textFile.GetLineCount(); i++) { wxString line(textFile[i]); int pos = line.Find(wxT("XDG_DOWNLOAD_DIR")); if (pos != wxNOT_FOUND) { wxString value = line.AfterFirst(wxT('=')); value = ShellUnescape(value); if (!value.IsEmpty() && wxDirExists(value)) return CLocalPath(value); else break; } } } } } #endif return CLocalPath(wxStandardPaths::Get().GetDocumentsDir()); }
CLocalPath GetDownloadDir() { #ifdef __WXMSW__ // Unfortunately MinGW's import library lacks SHGetKnownFolderPath, even though it has it in its headers. wxDynamicLibrary lib(_T("shell32.dll")); if (lib.IsLoaded() && lib.HasSymbol(_T("SHGetKnownFolderPath"))) { tSHGetKnownFolderPath pSHGetKnownFolderPath = (tSHGetKnownFolderPath)lib.GetSymbol(_T("SHGetKnownFolderPath")); PWSTR path; HRESULT result = pSHGetKnownFolderPath(FOLDERID_Downloads, 0, 0, &path); if(result == S_OK) { std::wstring dir = path; CoTaskMemFree(path); return CLocalPath(dir); } } #elif !defined(__WXMAC__) // Code copied from wx, but for downloads directory. // Also, directory is now unescaped. { wxLogNull logNull; wxString homeDir = wxFileName::GetHomeDir(); wxString configPath; if (wxGetenv(wxT("XDG_CONFIG_HOME"))) { configPath = wxGetenv(wxT("XDG_CONFIG_HOME")); } else { configPath = homeDir + wxT("/.config"); } wxString dirsFile = configPath + wxT("/user-dirs.dirs"); if (wxFileExists(dirsFile)) { wxTextFile textFile; if (textFile.Open(dirsFile)) { size_t i; for (i = 0; i < textFile.GetLineCount(); i++) { wxString line(textFile[i]); int pos = line.Find(wxT("XDG_DOWNLOAD_DIR")); if (pos != wxNOT_FOUND) { wxString value = line.AfterFirst(wxT('=')); value = ShellUnescape(value); if (!value.empty() && wxDirExists(value)) return CLocalPath(value.ToStdWstring()); else break; } } } } } #endif return CLocalPath(wxStandardPaths::Get().GetDocumentsDir().ToStdWstring()); }
CLocalPath CUpdateWizard::GetDownloadDir() const { #ifdef __WXMSW__ // Old Vista has a profile directory for downloaded files, // need to get it using SHGetKnownFolderPath which we need to // load dynamically to preserve forward compatibility with the // upgrade to Windows XP. wxDynamicLibrary lib(_T("shell32.dll")); if (lib.IsLoaded() && lib.HasSymbol(_T("SHGetKnownFolderPath"))) { tSHGetKnownFolderPath pSHGetKnownFolderPath = (tSHGetKnownFolderPath)lib.GetSymbol(_T("SHGetKnownFolderPath")); PWSTR path; HRESULT result = pSHGetKnownFolderPath(VISTASHIT_FOLDERID_Downloads, 0, 0, &path); if (result == S_OK) { wxString dir = path; CoTaskMemFree(path); return CLocalPath(dir); } } #endif return CLocalPath(wxStandardPaths::Get().GetDocumentsDir()); }