~ubuntu-branches/ubuntu/lucid/lastfm/lucid

« back to all changes in this revision

Viewing changes to src/libUnicorn/UnicornCommonWin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-31 09:49:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071231094954-ix1amvcsj9pk61ya
Tags: 1:1.4.1.57486.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #180254), remaining changes:
  - debian/rules;
    - Added dh_icons
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 - 2007 by                                          *
 
3
 *      Last.fm Ltd <client@last.fm>                                       *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "UnicornCommonWin.h"
 
22
#include "UnicornCommon.h"
 
23
 
 
24
// This file contains legacy code that doesn't work with Unicode.
 
25
//#undef UNICODE
 
26
//#undef _UNICODE
 
27
 
 
28
#undef LOG
 
29
#undef LOGL
 
30
#define LOG(x, y)
 
31
#define LOGL(x, y)
 
32
 
 
33
#include <QFile>
 
34
#include <QIODevice>
 
35
#include <QSettings>
 
36
#include <QFileInfo>
 
37
 
 
38
#include <shlobj.h>
 
39
#include <atlbase.h> // For the COM shortcut stuff
 
40
 
 
41
#include <string>
 
42
 
 
43
using namespace std;
 
44
 
 
45
namespace UnicornUtils
 
46
{
 
47
 
 
48
 
 
49
string
 
50
programFilesPath()
 
51
{
 
52
    char acPath[MAX_PATH];
 
53
 
 
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,
 
58
                                 CSIDL_PROGRAM_FILES, 
 
59
                                 NULL,
 
60
                                 0, // current path
 
61
                                 acPath);
 
62
 
 
63
    if (h != S_OK)
 
64
    {
 
65
        LOG(1, "Couldn't get Program Files dir, is this possibly Win 9x?\n");
 
66
 
 
67
        //throw logic_error("Couldn't get Program Files dir.");
 
68
 
 
69
        acPath[0] = '\0';
 
70
        return acPath;
 
71
    }
 
72
 
 
73
    string sPath(acPath);
 
74
 
 
75
    if (sPath[sPath.size() - 1] != '\\')
 
76
    {
 
77
        sPath.append( "/" );
 
78
    }
 
79
 
 
80
    return sPath;
 
81
}
 
82
 
 
83
/******************************************************************************
 
84
    GetTempPath
 
85
******************************************************************************/
 
86
/* use QDir::tempPath instead
 
87
string
 
88
CWinUtils::GetTempDir()
 
89
{
 
90
    TCHAR acTempPath[MAX_PATH];
 
91
    ::GetTempPath(MAX_PATH, acTempPath);
 
92
 
 
93
    string sTempPath(acTempPath);
 
94
 
 
95
    if (sTempPath[sTempPath.size() - 1] != '\\')
 
96
    {
 
97
        sTempPath.append("\\");
 
98
    }
 
99
 
 
100
    return sTempPath;
 
101
}
 
102
*/
 
103
 
 
104
bool
 
105
isLimitedUser()
 
106
{
 
107
    // Try and write to Program Files, if so we should be fine.
 
108
    string pf = programFilesPath();
 
109
    QString file = QString::fromStdString(pf) + "dummy";
 
110
    QFile f( file );
 
111
    if ( !f.open( QIODevice::WriteOnly ) )
 
112
    {
 
113
        LOG(3, "Couldn't open test file, it's a limited user.\n");
 
114
        return true;
 
115
    }
 
116
    else
 
117
    {
 
118
        f.close();
 
119
        QFile::remove(file);
 
120
        return false;
 
121
    }
 
122
}
 
123
 
 
124
QString
 
125
findDefaultPlayer()
 
126
{
 
127
    // Get mp3 progID
 
128
    QSettings regKey( "HKEY_LOCAL_MACHINE\\Software\\Classes\\.mp3", QSettings::NativeFormat );
 
129
    QString progId = regKey.value("Default").toString();
 
130
 
 
131
    // Look under progID
 
132
    QSettings progIdKey(
 
133
        QString( "HKEY_LOCAL_MACHINE\\Software\\Classes\\%1\\shell\\open\\command" ).arg( progId ),
 
134
        QSettings::NativeFormat );
 
135
    QString exeCmd = progIdKey.value("Default").toString();
 
136
 
 
137
    vector<string> separated;
 
138
    UnicornUtils::parseQuotedStrings( exeCmd.toStdString(), separated );
 
139
 
 
140
    QString path = separated.size() > 0 ? QString::fromStdString(separated.at(0)) : "";
 
141
    QFileInfo file(path);
 
142
    return file.fileName();
 
143
}
 
144
 
 
145
 
 
146
HRESULT
 
147
createShortcut( LPCTSTR lpszFileName, 
 
148
                LPCTSTR lpszDesc, 
 
149
                LPCTSTR lpszShortcutPath )
 
150
{
 
151
    HRESULT hRes = E_FAIL;
 
152
    DWORD dwRet = 0;
 
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
 
159
    LPTSTR lpszFilePart;    
 
160
    WCHAR wszTemp[MAX_PATH];
 
161
        
 
162
    // Retrieve the full path and file name of a specified file
 
163
    dwRet = GetFullPathName(lpszFileName, 
 
164
                       sizeof(szPath) / sizeof(TCHAR), 
 
165
                       szPath, &lpszFilePart);
 
166
    if (!dwRet)                                        
 
167
        return hRes;
 
168
 
 
169
    // Get a pointer to the IShellLink interface
 
170
    hRes = CoCreateInstance(CLSID_ShellLink,
 
171
                            NULL, 
 
172
                            CLSCTX_INPROC_SERVER,
 
173
                            IID_IShellLink,
 
174
                            (void**)&ipShellLink);
 
175
 
 
176
    if (SUCCEEDED(hRes))
 
177
    {
 
178
        // Get a pointer to the IPersistFile interface
 
179
        CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);
 
180
 
 
181
        // Set the path to the shortcut target and add the description
 
182
        hRes = ipShellLink->SetPath(szPath);
 
183
        if (FAILED(hRes))
 
184
            return hRes;
 
185
 
 
186
        hRes = ipShellLink->SetDescription(lpszDesc);
 
187
        if (FAILED(hRes))
 
188
            return hRes;
 
189
 
 
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);
 
195
    #else
 
196
        wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
 
197
    #endif
 
198
 
 
199
        // Write the shortcut to disk
 
200
        hRes = ipPersistFile->Save(wszTemp, TRUE);
 
201
    }
 
202
 
 
203
    return hRes;
 
204
}
 
205
 
 
206
 
 
207
} // namespace UnicornUtils
 
 
b'\\ No newline at end of file'