1
/***************************************************************************
2
* Copyright (C) 2005 - 2007 by *
3
* Last.fm Ltd <client@last.fm> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "UnicornCommonWin.h"
22
#include "UnicornCommon.h"
24
// This file contains legacy code that doesn't work with Unicode.
39
#include <atlbase.h> // For the COM shortcut stuff
45
namespace UnicornUtils
52
char acPath[MAX_PATH];
54
// TODO: this call is dependant on a specific version of shell32.dll.
55
// Need to degrade gracefully. Need to bundle SHFolder.exe with installer
56
// and execute it on install for this to work on Win98.
57
HRESULT h = SHGetFolderPathA(NULL,
65
LOG(1, "Couldn't get Program Files dir, is this possibly Win 9x?\n");
67
//throw logic_error("Couldn't get Program Files dir.");
75
if (sPath[sPath.size() - 1] != '\\')
83
/******************************************************************************
85
******************************************************************************/
86
/* use QDir::tempPath instead
88
CWinUtils::GetTempDir()
90
TCHAR acTempPath[MAX_PATH];
91
::GetTempPath(MAX_PATH, acTempPath);
93
string sTempPath(acTempPath);
95
if (sTempPath[sTempPath.size() - 1] != '\\')
97
sTempPath.append("\\");
107
// Try and write to Program Files, if so we should be fine.
108
string pf = programFilesPath();
109
QString file = QString::fromStdString(pf) + "dummy";
111
if ( !f.open( QIODevice::WriteOnly ) )
113
LOG(3, "Couldn't open test file, it's a limited user.\n");
128
QSettings regKey( "HKEY_LOCAL_MACHINE\\Software\\Classes\\.mp3", QSettings::NativeFormat );
129
QString progId = regKey.value("Default").toString();
133
QString( "HKEY_LOCAL_MACHINE\\Software\\Classes\\%1\\shell\\open\\command" ).arg( progId ),
134
QSettings::NativeFormat );
135
QString exeCmd = progIdKey.value("Default").toString();
137
vector<string> separated;
138
UnicornUtils::parseQuotedStrings( exeCmd.toStdString(), separated );
140
QString path = separated.size() > 0 ? QString::fromStdString(separated.at(0)) : "";
141
QFileInfo file(path);
142
return file.fileName();
147
createShortcut( LPCTSTR lpszFileName,
149
LPCTSTR lpszShortcutPath )
151
HRESULT hRes = E_FAIL;
153
CComPtr<IShellLink> ipShellLink;
154
// buffer that receives the null-terminated string
155
// for the drive and path
156
TCHAR szPath[MAX_PATH];
157
// buffer that receives the address of the final
158
//file name component in the path
160
WCHAR wszTemp[MAX_PATH];
162
// Retrieve the full path and file name of a specified file
163
dwRet = GetFullPathName(lpszFileName,
164
sizeof(szPath) / sizeof(TCHAR),
165
szPath, &lpszFilePart);
169
// Get a pointer to the IShellLink interface
170
hRes = CoCreateInstance(CLSID_ShellLink,
172
CLSCTX_INPROC_SERVER,
174
(void**)&ipShellLink);
178
// Get a pointer to the IPersistFile interface
179
CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);
181
// Set the path to the shortcut target and add the description
182
hRes = ipShellLink->SetPath(szPath);
186
hRes = ipShellLink->SetDescription(lpszDesc);
190
// IPersistFile is using LPCOLESTR, so make sure
191
// that the string is Unicode
192
#if !defined _UNICODE
193
MultiByteToWideChar(CP_ACP, 0,
194
lpszShortcutPath, -1, wszTemp, MAX_PATH);
196
wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
199
// Write the shortcut to disk
200
hRes = ipPersistFile->Save(wszTemp, TRUE);
207
} // namespace UnicornUtils
b'\\ No newline at end of file'