mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
*Core, CtrlLib: Fixing GetDownloadsFolder()
git-svn-id: svn://ultimatepp.org/upp/trunk@2194 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
c7d7e8588d
commit
c11ff4bfe1
10 changed files with 90 additions and 68 deletions
|
|
@ -1,7 +1,17 @@
|
|||
#include "Core.h"
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#define Ptr Ptr_
|
||||
#define byte byte_
|
||||
#define CY win32_CY_
|
||||
|
||||
#include <shellapi.h>
|
||||
#include <wincon.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#undef Ptr
|
||||
#undef byte
|
||||
#undef CY
|
||||
#endif
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
|
@ -421,45 +431,45 @@ String GetDesktopManager()
|
|||
}
|
||||
|
||||
#if defined(PLATFORM_WIN32)
|
||||
String GetShellFolder(const char *local, const char *users)
|
||||
|
||||
String GetShellFolder(int clsid)
|
||||
{
|
||||
String ret = FromSystemCharset(GetWinRegString(local, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
|
||||
HKEY_CURRENT_USER));
|
||||
if (ret == "" && *users != '\0')
|
||||
return FromSystemCharset(GetWinRegString(users, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
|
||||
HKEY_LOCAL_MACHINE));
|
||||
return ret;
|
||||
wchar path[MAX_PATH];
|
||||
if(SHGetFolderPathW(NULL, clsid, NULL, SHGFP_TYPE_CURRENT, path) == S_OK)
|
||||
return FromUnicodeBuffer(path);
|
||||
return Null;
|
||||
}
|
||||
|
||||
String GetDesktopFolder() {return GetShellFolder("Desktop", "Common Desktop");}
|
||||
String GetProgramsFolder() {return FromSystemCharset(GetWinRegString("ProgramFilesDir", "Software\\Microsoft\\Windows\\CurrentVersion", HKEY_LOCAL_MACHINE));}
|
||||
String GetAppDataFolder() {return GetShellFolder("AppData", "Common AppData");}
|
||||
String GetMusicFolder() {return GetShellFolder("My Music", "CommonMusic");}
|
||||
String GetPicturesFolder() {return GetShellFolder("My Pictures", "CommonPictures");}
|
||||
String GetVideoFolder() {return GetShellFolder("My Video", "CommonVideo");}
|
||||
String GetPersonalFolder() {return GetShellFolder("Personal", 0);}
|
||||
String GetTemplatesFolder() {return GetShellFolder("Templates", "Common Templates");}
|
||||
String GetDesktopFolder() { return GetShellFolder(CSIDL_DESKTOP); }
|
||||
String GetProgramsFolder() { return GetShellFolder(CSIDL_PROGRAM_FILES); }
|
||||
String GetAppDataFolder() { return GetShellFolder(CSIDL_APPDATA);}
|
||||
String GetMusicFolder() { return GetShellFolder(CSIDL_MYMUSIC);}
|
||||
String GetPicturesFolder() { return GetShellFolder(CSIDL_MYPICTURES);}
|
||||
String GetVideoFolder() { return GetShellFolder(CSIDL_MYVIDEO);}
|
||||
String GetDocumentsFolder() { return GetShellFolder(CSIDL_MYDOCUMENTS);}
|
||||
String GetTemplatesFolder() { return GetShellFolder(CSIDL_TEMPLATES);}
|
||||
|
||||
#define MY_DEFINE_KNOWN_FOLDER(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
static const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
||||
|
||||
MY_DEFINE_KNOWN_FOLDER(MY_FOLDERID_Downloads, 0x374de290, 0x123f, 0x4565, 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b);
|
||||
|
||||
String GetDownloadFolder()
|
||||
{
|
||||
String ret = FromSystemCharset(GetWinRegString("Download Directory", "Software\\Microsoft\\Internet Explorer", HKEY_CURRENT_USER));
|
||||
if (ret == "")
|
||||
ret = FromSystemCharset(GetWinRegString("Save Directory", "Software\\Microsoft\\Internet Explorer\\Main", HKEY_CURRENT_USER));
|
||||
return ret;
|
||||
static HRESULT (STDAPICALLTYPE * SHGetKnownFolderPath)(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
|
||||
ONCELOCK {
|
||||
DllFn(SHGetKnownFolderPath, "shell32.dll", "SHGetKnownFolderPath");
|
||||
}
|
||||
if(SHGetKnownFolderPath) {
|
||||
PWSTR path = NULL;
|
||||
if(SHGetKnownFolderPath(MY_FOLDERID_Downloads, 0, NULL, &path) == S_OK && path) {
|
||||
String s = FromUnicodeBuffer(path, wstrlen(path));
|
||||
CoTaskMemFree(path);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return Null;
|
||||
};
|
||||
|
||||
String GetOsFolder()
|
||||
{
|
||||
char ret[MAX_PATH];
|
||||
::GetWindowsDirectory(ret, MAX_PATH);
|
||||
return String(ret);
|
||||
}
|
||||
String GetSystemFolder()
|
||||
{
|
||||
char ret[MAX_PATH];
|
||||
::GetSystemDirectory(ret, MAX_PATH);
|
||||
return String(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
|
|
@ -515,24 +525,10 @@ String GetAppDataFolder() {return GetHomeDirectory();};
|
|||
String GetMusicFolder() {return GetShellFolder("XDG_MUSIC_DIR", "MUSIC");}
|
||||
String GetPicturesFolder() {return GetShellFolder("XDG_PICTURES_DIR", "PICTURES");}
|
||||
String GetVideoFolder() {return GetShellFolder("XDG_VIDEOS_DIR", "VIDEOS");}
|
||||
String GetPersonalFolder() {return GetShellFolder("XDG_DOCUMENTS_DIR", "DOCUMENTS");}
|
||||
String GetDocumentsFolder() {return GetShellFolder("XDG_DOCUMENTS_DIR", "DOCUMENTS");}
|
||||
String GetTemplatesFolder() {return GetShellFolder("XDG_TEMPLATES_DIR", "XDG_TEMPLATES_DIR");}
|
||||
String GetDownloadFolder()
|
||||
{
|
||||
return GetHomeDirFile("Downloads"); // wrong!
|
||||
};
|
||||
String GetTempFolder()
|
||||
{
|
||||
return GetHomeDirectory();
|
||||
}
|
||||
String GetOsFolder()
|
||||
{
|
||||
return String("/bin");
|
||||
}
|
||||
String GetSystemFolder()
|
||||
{
|
||||
return String("");
|
||||
}
|
||||
String GetDownloadFolder() {return GetShellFolder("XDG_DOWNLOAD_DIR", "XDG_DOWNLOAD_DIR");
|
||||
|
||||
#endif
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -86,8 +86,6 @@ String GetAppDataFolder();
|
|||
String GetMusicFolder();
|
||||
String GetPicturesFolder();
|
||||
String GetVideoFolder();
|
||||
String GetPersonalFolder();
|
||||
String GetDocumentsFolder();
|
||||
String GetTemplatesFolder();
|
||||
String GetDownloadFolder();
|
||||
String GetOsFolder();
|
||||
String GetSystemFolder();
|
||||
|
|
|
|||
|
|
@ -2811,6 +2811,11 @@ String FromUnicodeBuffer(const wchar *src, int len, byte charset, int defchar)
|
|||
return result;
|
||||
}
|
||||
|
||||
String FromUnicodeBuffer(const wchar *src)
|
||||
{
|
||||
return FromUnicodeBuffer(src, wstrlen(src));
|
||||
}
|
||||
|
||||
String FromUnicode(const WString& src, byte charset, int defchar)
|
||||
{
|
||||
return FromUnicodeBuffer(~src, src.GetCount(), charset, defchar);
|
||||
|
|
|
|||
|
|
@ -269,6 +269,7 @@ bool CheckUtf8(const String& src);
|
|||
WString ToUnicode(const String& src, byte charset);
|
||||
WString ToUnicode(const char *src, int n, byte charset);
|
||||
String FromUnicodeBuffer(const wchar *src, int len, byte charset = CHARSET_DEFAULT, int defchar = DEFAULTCHAR);
|
||||
String FromUnicodeBuffer(const wchar *src);
|
||||
String FromUnicode(const WString& src, byte charset = CHARSET_DEFAULT, int defchar = DEFAULTCHAR);
|
||||
|
||||
String ToCharset(byte charset, const String& s, byte scharset = CHARSET_DEFAULT, int defchar = DEFAULTCHAR);
|
||||
|
|
|
|||
|
|
@ -163,7 +163,6 @@ void *CheckDll__(const char *fn, const char *const *names, UPP::Vector<void *>&
|
|||
{
|
||||
void *hmod = dlopen(fn, RTLD_LAZY | RTLD_GLOBAL);
|
||||
if(!hmod) {
|
||||
RLOG("prdel");
|
||||
RLOG("Error loading library " << fn << ": " << dlerror());
|
||||
/*
|
||||
for(int i = 0; i < 100; i++) {
|
||||
|
|
|
|||
|
|
@ -328,7 +328,11 @@ String::String(StringBuffer& b)
|
|||
chr[KIND] = min(b.GetAlloc(), 255);
|
||||
}
|
||||
b.Zero();
|
||||
|
||||
// char h[100];
|
||||
// DLOG(sprintf(h, "String(StringBuffer) end %p (%p)", ptr, this));
|
||||
Dsyn();
|
||||
// DLOG(sprintf(h, "String(StringBuffer) end2 %p (%p)", ptr, this));
|
||||
}
|
||||
|
||||
char *StringBuffer::Alloc(int count, int& alloc)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ void Panic(const char *msg)
|
|||
return;
|
||||
PanicMode = true;
|
||||
LOG(msg);
|
||||
LOG(GetLastErrorMessage());
|
||||
BugLog() << "PANIC: " << msg << "\n";
|
||||
UsrLogT("===== PANIC ================================================");
|
||||
UsrLogT(msg);
|
||||
|
|
|
|||
|
|
@ -166,6 +166,13 @@ String GetWindowsDirectory() {
|
|||
}
|
||||
#endif
|
||||
|
||||
void *GetDllFn(const char *dll, const char *fn)
|
||||
{
|
||||
if(HMODULE hDLL = LoadLibrary(dll))
|
||||
return GetProcAddress(hDLL, fn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String GetModuleFileName(HINSTANCE instance) {
|
||||
#ifdef PLATFORM_WINCE
|
||||
wchar h[_MAX_PATH];
|
||||
|
|
|
|||
|
|
@ -28,6 +28,15 @@ bool SetWinRegExpandString(const String& string, const char *value, const char
|
|||
bool SetWinRegInt(int data, const char *value, const char *path, HKEY base_key = HKEY_LOCAL_MACHINE);
|
||||
void DeleteWinReg(const String& key, HKEY base = HKEY_LOCAL_MACHINE);
|
||||
|
||||
void *GetDllFn(const char *dll, const char *fn);
|
||||
|
||||
template <class T>
|
||||
void DllFn(T& x, const char *dll, const char *fn)
|
||||
{
|
||||
x = (T)GetDllFn(dll, fn);
|
||||
}
|
||||
|
||||
|
||||
#ifndef PLATFORM_WINCE
|
||||
String GetSystemDirectory();
|
||||
String GetWindowsDirectory();
|
||||
|
|
|
|||
|
|
@ -1236,9 +1236,11 @@ bool FileSel::Execute(int _mode) {
|
|||
Array<FileSystemInfo::FileInfo> root = filesystem->Find(Null);
|
||||
for(i = 0; i < root.GetCount(); i++) {
|
||||
String ugly = root[i].filename;
|
||||
ugly.Cat('\0');
|
||||
ugly.Cat(root[i].root_style);
|
||||
dir.Add(root[i].filename, ugly);
|
||||
if(ugly != "A:\\" && ugly != "B:\\") {
|
||||
ugly.Cat('\0');
|
||||
ugly.Cat(root[i].root_style);
|
||||
dir.Add(root[i].filename, ugly);
|
||||
}
|
||||
}
|
||||
if(filesystem == &StdFileSystemInfo())
|
||||
dir.Add("\\", String(t_("Network")) + String(0, 1) + "\xff");
|
||||
|
|
@ -1494,22 +1496,24 @@ FileSel& FileSel::AddStandardPlaces()
|
|||
AddPlace(GetMusicFolder(), t_("Music"));
|
||||
AddPlace(GetPicturesFolder(), t_("Pictures"));
|
||||
AddPlace(GetVideoFolder(), t_("Video"));
|
||||
AddPlace(GetPersonalFolder(), t_("Documents"));
|
||||
// AddPlace(GetDownloadFolder(), t_("Downloads"));
|
||||
AddPlace(GetDocumentsFolder(), t_("Documents"));
|
||||
AddPlace(GetDownloadFolder(), t_("Downloads"));
|
||||
AddPlaceSeparator();
|
||||
Array<FileSystemInfo::FileInfo> root = filesystem->Find(Null);
|
||||
for(int i = 0; i < root.GetCount(); i++) {
|
||||
String desc = root[i].root_desc;
|
||||
String n = root[i].filename;
|
||||
#ifdef PLATFORM_WIN32
|
||||
if(*n.Last() == '\\')
|
||||
n.Trim(n.GetCount() - 1);
|
||||
#endif
|
||||
if(desc.GetCount())
|
||||
desc << " (" << root[i].filename << ")";
|
||||
else
|
||||
desc = n;
|
||||
AddPlace(root[i].filename, n);
|
||||
if(n != "A:\\" && n != "B:\\") {
|
||||
#ifdef PLATFORM_WIN32
|
||||
if(*n.Last() == '\\')
|
||||
n.Trim(n.GetCount() - 1);
|
||||
#endif
|
||||
if(desc.GetCount())
|
||||
desc << " (" << root[i].filename << ")";
|
||||
else
|
||||
desc = n;
|
||||
AddPlace(root[i].filename, n);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue