blob: 5136ad86c09778d6fb9cfe2d8e648e06d2251099 [file] [log] [blame]
Edric Milaret4bba46d2015-04-29 16:33:38 -04001/***************************************************************************
2 * Copyright (C) 2015 by Savoir-Faire Linux *
3 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
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 3 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, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "utils.h"
20
21bool
22Utils::CreateStartupLink() {
23 TCHAR userHome[MAX_PATH];
24 SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, userHome);
25
26 TCHAR workingDirectory[MAX_PATH];
27 GetCurrentDirectory(MAX_PATH, workingDirectory);
28
29 std::wstring programPath(workingDirectory);
30 programPath += TEXT("\\RingClientWindows.exe");
31
32 std::wstring linkPath(userHome);
33 linkPath += TEXT("\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Ring.lnk");
34
35 return Utils::CreateLink(programPath.c_str(), linkPath.c_str());
36}
37
38bool
39Utils::CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszPathLink) {
40 HRESULT hres;
41 IShellLink* psl;
42
43 hres = CoCreateInstance(CLSID_ShellLink, NULL,
44 CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
45 if (SUCCEEDED(hres))
46 {
47 IPersistFile* ppf;
48 psl->SetPath(lpszPathObj);
49
50 hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
51 if (SUCCEEDED(hres))
52 {
53 hres = ppf->Save(lpszPathLink, TRUE);
54 ppf->Release();
55 }
56 psl->Release();
57 }
58 return hres;
59}
60
61void
62Utils::DeleteStartupLink() {
63 TCHAR userHome[MAX_PATH];
64 SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, userHome);
65
66 std::wstring linkPath(userHome);
67 linkPath += TEXT("\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Ring.lnk");
68
69 DeleteFile(linkPath.c_str());
70}
71
72bool
73Utils::CheckStartupLink() {
74 TCHAR userHome[MAX_PATH];
75 SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, userHome);
76
77 std::wstring linkPath(userHome);
78 linkPath += TEXT("\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Ring.lnk");
79 return PathFileExists(linkPath.c_str());
80}
81
Edric Milaret031c3052015-04-29 18:14:18 -040082QString
83Utils::GetRingtonePath() {
84 TCHAR workingDirectory[MAX_PATH];
85 GetCurrentDirectory(MAX_PATH, workingDirectory);
86
87 QString ringtonePath = QString::fromWCharArray(workingDirectory);
88 ringtonePath += "\\ringtones\\konga.ul";
89
90 return ringtonePath;
91}
92