From 21f60945831a6edad0f2101b6053a2c8213d5296 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 20 Dec 2003 13:59:13 +0000 Subject: [PATCH 1/1] Added wxPATH_NORM_SHORTCUT git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24939 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 ++ docs/latex/wx/filename.tex | 1 + include/wx/filename.h | 9 ++++- src/common/filename.cpp | 82 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index c1f63e73ce..9980383392 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/docs/latex/wx/filename.tex b/docs/latex/wx/filename.tex index b294adbd72..d739dcd8dc 100644 --- a/docs/latex/wx/filename.tex +++ b/docs/latex/wx/filename.tex @@ -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} } diff --git a/include/wx/filename.h b/include/wx/filename.h index 14aed5347d..774f65aaf0 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -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 diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 07840e5372..c5f7f9a8a3 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -945,6 +945,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) ) { @@ -969,6 +986,71 @@ bool wxFileName::Normalize(int flags, return true; } +// ---------------------------------------------------------------------------- +// get the shortcut target +// ---------------------------------------------------------------------------- + +#if defined(__WIN32__) && !defined(__WXWINCE__) +#include +#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 // ---------------------------------------------------------------------------- -- 2.45.2