Added wxPATH_NORM_SHORTCUT

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24939 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2003-12-20 13:59:13 +00:00
parent 892dd3cef3
commit 21f6094583
4 changed files with 94 additions and 1 deletions

View File

@@ -84,6 +84,8 @@ All:
- check if file exists in wxFileConfig::DeleteFile() (Christian Sturmlechner)
- when wxUSE_STL == 1 wxHashTable will not be implemented using wxHashMap
(as in 2.5.0).
- Added some extra convenience functions to wxRect such as
GetBottomRight (Hajo Kirchhoff)
All (GUI):
@@ -114,6 +116,7 @@ wxMSW:
- MDI child frames are not always resizeable any more (Andrei Fortuna)
- fixed enumerating of entries/groups under '/' in wxRegConfig
- added wxSYS_ICONTITLE_FONT (Andreas Pflug)
- added wxPATH_NORM_SHORTCUT to wxFileName
wxGTK:

View File

@@ -652,6 +652,7 @@ any or-combination of the following constants:
\twocolitem{{\bf wxPATH\_NORM\_CASE}}{if filesystem is case insensitive, transform to tolower case}
\twocolitem{{\bf wxPATH\_NORM\_ABSOLUTE}}{make the path absolute}
\twocolitem{{\bf wxPATH\_NORM\_LONG}}{make the path the long form}
\twocolitem{{\bf wxPATH\_NORM\_SHORTCUT}}{resolve if it is a shortcut (Windows only)}
\twocolitem{{\bf wxPATH\_NORM\_ALL}}{all of previous flags except \texttt{wxPATH\_NORM\_CASE}}
\end{twocollist}
}

View File

@@ -72,7 +72,8 @@ enum wxPathNormalize
wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
wxPATH_NORM_LONG = 0x0020, // make the path the long form
wxPATH_NORM_ALL = 0x003f & ~wxPATH_NORM_CASE
wxPATH_NORM_SHORTCUT = 0x0040, // resolve the shortcut, if it is a shortcut
wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE
};
// what exactly should GetPath() return?
@@ -283,6 +284,12 @@ public:
{ return Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
wxPATH_NORM_TILDE, cwd, format); }
#ifdef __WIN32__
// if the path is a shortcut, return the target and optionally,
// the arguments
bool GetShortcutTarget(const wxString& shortcutPath, wxString& targetFilename, wxString* arguments = NULL);
#endif
// Comparison
// compares with the rules of the given platforms format

View File

@@ -946,6 +946,23 @@ bool wxFileName::Normalize(int flags,
m_dirs.Add(dir);
}
#ifdef __WIN32__
if ( (flags & wxPATH_NORM_SHORTCUT) )
{
wxString filename;
if (GetShortcutTarget(GetFullPath(format), filename))
{
// Repeat this since we may now have a new path
if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
{
filename.MakeLower();
}
m_relative = false;
Assign(filename);
}
}
#endif
if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
{
// VZ: expand env vars here too?
@@ -969,6 +986,71 @@ bool wxFileName::Normalize(int flags,
return true;
}
// ----------------------------------------------------------------------------
// get the shortcut target
// ----------------------------------------------------------------------------
#if defined(__WIN32__) && !defined(__WXWINCE__)
#include <shlobj.h>
#endif
#ifdef __WIN32__
bool wxFileName::GetShortcutTarget(const wxString& shortcutPath, wxString& targetFilename, wxString* arguments)
{
#ifdef __WXWINCE__
// Not tested on WinCE, so don't compile yet
return shortcutPath;
#else
wxString path, file, ext;
wxSplitPath(shortcutPath, & path, & file, & ext);
HRESULT hres;
IShellLink* psl;
bool success = FALSE;
// Assume it's not a shortcut if it doesn't end with lnk
if (ext.Lower() != wxT("lnk"))
return FALSE;
// create a ShellLink object
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*) &psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz,
MAX_PATH);
hres = ppf->Load(wsz, 0);
if (SUCCEEDED(hres))
{
wxChar buf[2048];
psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY);
targetFilename = wxString(buf);
success = (shortcutPath != targetFilename);
psl->GetArguments(buf, 2048);
wxString args(buf);
if (!args.IsEmpty() && arguments)
{
*arguments = args;
}
}
}
}
psl->Release();
return success;
#endif
}
#endif
// ----------------------------------------------------------------------------
// absolute/relative paths
// ----------------------------------------------------------------------------