This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheverythingwrapper.cpp
161 lines (137 loc) · 5.45 KB
/
everythingwrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "stdafx.h"
#include "everythingwrapper.h"
HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPWSTR lpszPath, int iPathBufferSize)
{
HRESULT hres;
IShellLink * psl;
WCHAR szGotPath[MAX_PATH];
WCHAR szDescription[MAX_PATH];
WIN32_FIND_DATA wfd;
*lpszPath = 0; // Assume failure
CoInitialize(NULL);
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
if (SUCCEEDED(hres))
{
IPersistFile *ppf;
// Get a pointer to the IPersistFile interface.
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH] = {0};
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH);
// Add code here to check return value from MultiByteWideChar
// for success.
// Load the shortcut.
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres))
{
// Resolve the link.
hres = psl->Resolve(hwnd, 0);
if (SUCCEEDED(hres))
{
// Get the path to the link target.
hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_RAWPATH);
if (SUCCEEDED(hres))
{
// Get the description of the target.
hres = psl->GetDescription(szDescription, MAX_PATH);
if (SUCCEEDED(hres))
{
hres = StringCbCopy(lpszPath, iPathBufferSize, szGotPath);
if (SUCCEEDED(hres))
{
// Handle success
}
else
{
// Handle the error
}
}
}
}
}
// Release the pointer to the IPersistFile interface.
ppf->Release();
}
// Release the pointer to the IShellLink interface.
psl->Release();
}
return hres;
}
bool isEverythingRunning()
{
HWND everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS, 0);
return everything_hwnd != NULL;
}
void launchEverything(const QString &everythingFilePath)
{
if (QFile::exists(everythingFilePath))
{
QString path = QDir::toNativeSeparators(everythingFilePath);
::ShellExecuteW(NULL, L"open", path.toStdWString().c_str(), NULL, NULL, SW_SHOWMINIMIZED);
}
}
QString GetEverythingPath()
{
HWND hWnd = FindWindow(EVERYTHING_IPC_WNDCLASS, 0);
if (hWnd)
{
int ret = (int)SendMessage(hWnd, EVERYTHING_WM_IPC, EVERYTHING_IPC_IS_DESKTOP_SHORTCUT, 0);
if (!ret)
{
// create one
SendMessage(hWnd, EVERYTHING_WM_IPC, EVERYTHING_IPC_CREATE_DESKTOP_SHORTCUT, 0);
}
QString path = QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) % "/Search Everything.lnk");
WCHAR szTarget[MAX_PATH] = {0};
HRESULT hr = ResolveIt(hWnd, path.toStdString().c_str(), szTarget, sizeof(szTarget) / sizeof(szTarget[0]));
if (!ret)
{
// remove the one created right now
SendMessage(hWnd, EVERYTHING_WM_IPC, EVERYTHING_IPC_DELETE_DESKTOP_SHORTCUT, 0);
}
if (hr == S_OK)
{
QFileInfo f(QString::fromWCharArray(szTarget));
return f.absoluteFilePath();
}
}
return QString();
}
bool QuickGetFilesByFileName(const QString &fileName, QStringList &results)
{
HWND everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS, 0);
if (!everything_hwnd)
{
QWidget *p = QApplication::desktop()->screen();
if (QMessageBox::question(p,
"Notice",
"Everything is not running, thus Cisco Jabber Log Viewer can't find files. Do you want to launch the Everything "
"application shipped with Cisco Jabber Log Viewer?") == QMessageBox::Yes)
{
QString everythingFilePath = QApplication::applicationDirPath() % "/Everything.exe";
if (!QFile::exists(everythingFilePath))
{
QMessageBox::warning(
p, "Warning", "Can't find the Everything executable, please re-install Cisco Jabber Log Viewer.", QMessageBox::Ok);
return false;
}
::ShellExecuteW(NULL, L"open", everythingFilePath.toStdWString().c_str(), NULL, NULL, SW_SHOWMINIMIZED);
}
return false;
}
// find
Everything_SetSearch(fileName.toStdWString().c_str());
Everything_Query(TRUE);
for (DWORD i = 0; i < Everything_GetNumResults(); i++)
{
WCHAR path[MAX_PATH] = {0};
Everything_GetResultFullPathName(i, path, MAX_PATH);
results.append(QString::fromStdWString(path));
}
Everything_Reset();
return !results.isEmpty();
}