LAUNCHER: resolve .lnk shortcuts
This commit is contained in:
parent
94fad3a0c4
commit
208e216a35
|
@ -2,6 +2,8 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
#include <objbase.h>
|
||||||
|
#include <shlobj.h>
|
||||||
|
|
||||||
enum arch
|
enum arch
|
||||||
{
|
{
|
||||||
|
@ -98,6 +100,59 @@ static void CreateUnicodeFile(const wchar_t* file)
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Taken from: http://www.cplusplus.com/forum/windows/64088/
|
||||||
|
static bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedPath, size_t nSize)
|
||||||
|
{
|
||||||
|
if(szResolvedPath == NULL)
|
||||||
|
return SUCCEEDED(E_INVALIDARG);
|
||||||
|
|
||||||
|
//Initialize COM stuff
|
||||||
|
CoInitialize(NULL);
|
||||||
|
|
||||||
|
//Get a pointer to the IShellLink interface.
|
||||||
|
IShellLink* psl = NULL;
|
||||||
|
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
|
||||||
|
if(SUCCEEDED(hres))
|
||||||
|
{
|
||||||
|
//Get a pointer to the IPersistFile interface.
|
||||||
|
IPersistFile* ppf = NULL;
|
||||||
|
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
|
||||||
|
if(SUCCEEDED(hres))
|
||||||
|
{
|
||||||
|
//Load the shortcut.
|
||||||
|
hres = ppf->Load(szShortcutPath, STGM_READ);
|
||||||
|
|
||||||
|
if(SUCCEEDED(hres))
|
||||||
|
{
|
||||||
|
//Resolve the link.
|
||||||
|
hres = psl->Resolve(hwnd, 0);
|
||||||
|
|
||||||
|
if(SUCCEEDED(hres))
|
||||||
|
{
|
||||||
|
//Get the path to the link target.
|
||||||
|
char szGotPath[MAX_PATH] = {0};
|
||||||
|
hres = psl->GetPath(szGotPath, _countof(szGotPath), NULL, SLGP_SHORTPATH);
|
||||||
|
|
||||||
|
if(SUCCEEDED(hres))
|
||||||
|
{
|
||||||
|
strcpy_s(szResolvedPath, nSize, szGotPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Release the pointer to the IPersistFile interface.
|
||||||
|
ppf->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Release the pointer to the IShellLink interface.
|
||||||
|
psl->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Uninitialize COM stuff
|
||||||
|
CoUninitialize();
|
||||||
|
return SUCCEEDED(hres);
|
||||||
|
}
|
||||||
|
|
||||||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||||
{
|
{
|
||||||
CoInitialize(NULL); //fixed some crash
|
CoInitialize(NULL); //fixed some crash
|
||||||
|
@ -192,10 +247,15 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
}
|
}
|
||||||
if(argc == 2) //one argument -> execute debugger
|
if(argc == 2) //one argument -> execute debugger
|
||||||
{
|
{
|
||||||
|
wchar_t szPath[MAX_PATH] = L"";
|
||||||
|
wcscpy_s(szPath, argv[1]);
|
||||||
|
char szResolvedPath[MAX_PATH] = "";
|
||||||
|
if(ResolveShortcut(0, szPath, szResolvedPath, _countof(szResolvedPath)))
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, szResolvedPath, -1, szPath, _countof(szPath));
|
||||||
std::wstring cmdLine = L"\"";
|
std::wstring cmdLine = L"\"";
|
||||||
cmdLine += argv[1];
|
cmdLine += szPath;
|
||||||
cmdLine += L"\"";
|
cmdLine += L"\"";
|
||||||
switch(GetFileArchitecture(argv[1]))
|
switch(GetFileArchitecture(szPath))
|
||||||
{
|
{
|
||||||
case x32:
|
case x32:
|
||||||
if(sz32Path[0])
|
if(sz32Path[0])
|
||||||
|
|
Loading…
Reference in New Issue