mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-22 03:08:48 +00:00
altering AppUserModelId in pinned shortcut in Windows
This commit is contained in:
parent
30e96a1d5e
commit
c16ea77c52
@ -110,7 +110,6 @@ Application::Application(int &argc, char **argv) : PsApplication(argc, argv),
|
|||||||
}
|
}
|
||||||
mainApp = this;
|
mainApp = this;
|
||||||
|
|
||||||
|
|
||||||
installEventFilter(new EventFilterForKeys(this));
|
installEventFilter(new EventFilterForKeys(this));
|
||||||
|
|
||||||
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Regular.ttf"));
|
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Regular.ttf"));
|
||||||
@ -655,7 +654,6 @@ void Application::socketError(QLocalSocket::LocalSocketError e) {
|
|||||||
|
|
||||||
void Application::checkMapVersion() {
|
void Application::checkMapVersion() {
|
||||||
if (Local::oldMapVersion() < AppVersion) {
|
if (Local::oldMapVersion() < AppVersion) {
|
||||||
psRegisterCustomScheme();
|
|
||||||
if (Local::oldMapVersion()) {
|
if (Local::oldMapVersion()) {
|
||||||
QString versionFeatures;
|
QString versionFeatures;
|
||||||
if (cDevVersion() && Local::oldMapVersion() < 8049) {
|
if (cDevVersion() && Local::oldMapVersion() < 8049) {
|
||||||
|
@ -541,7 +541,7 @@ namespace {
|
|||||||
int32 _storageImagesSize = 0, _storageStickersSize = 0, _storageAudiosSize = 0;
|
int32 _storageImagesSize = 0, _storageStickersSize = 0, _storageAudiosSize = 0;
|
||||||
|
|
||||||
bool _mapChanged = false;
|
bool _mapChanged = false;
|
||||||
int32 _oldMapVersion = 0;
|
int32 _oldMapVersion = 0, _oldSettingsVersion = 0;
|
||||||
|
|
||||||
enum WriteMapWhen {
|
enum WriteMapWhen {
|
||||||
WriteMapNow,
|
WriteMapNow,
|
||||||
@ -1573,6 +1573,9 @@ namespace {
|
|||||||
_readMtpData();
|
_readMtpData();
|
||||||
|
|
||||||
LOG(("Map read time: %1").arg(getms() - ms));
|
LOG(("Map read time: %1").arg(getms() - ms));
|
||||||
|
if (_oldSettingsVersion < AppVersion) {
|
||||||
|
Local::writeSettings();
|
||||||
|
}
|
||||||
return Local::ReadMapDone;
|
return Local::ReadMapDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1820,6 +1823,7 @@ namespace Local {
|
|||||||
cSetDcOptions(dcOpts);
|
cSetDcOptions(dcOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_oldSettingsVersion = settingsData.version;
|
||||||
_settingsSalt = salt;
|
_settingsSalt = salt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1962,6 +1966,10 @@ namespace Local {
|
|||||||
return _oldMapVersion;
|
return _oldMapVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 oldSettingsVersion() {
|
||||||
|
return _oldSettingsVersion;
|
||||||
|
}
|
||||||
|
|
||||||
void writeDraft(const PeerId &peer, const MessageDraft &draft) {
|
void writeDraft(const PeerId &peer, const MessageDraft &draft) {
|
||||||
if (!_working()) return;
|
if (!_working()) return;
|
||||||
|
|
||||||
|
@ -100,6 +100,8 @@ namespace Local {
|
|||||||
ReadMapState readMap(const QByteArray &pass);
|
ReadMapState readMap(const QByteArray &pass);
|
||||||
int32 oldMapVersion();
|
int32 oldMapVersion();
|
||||||
|
|
||||||
|
int32 oldSettingsVersion();
|
||||||
|
|
||||||
struct MessageDraft {
|
struct MessageDraft {
|
||||||
MessageDraft(MsgId replyTo = 0, QString text = QString(), bool previewCancelled = false) : replyTo(replyTo), text(text), previewCancelled(previewCancelled) {
|
MessageDraft(MsgId replyTo = 0, QString text = QString(), bool previewCancelled = false) : replyTo(replyTo), text(text), previewCancelled(previewCancelled) {
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ int main(int argc, char *argv[]) {
|
|||||||
logsInit();
|
logsInit();
|
||||||
|
|
||||||
Local::readSettings();
|
Local::readSettings();
|
||||||
|
if (Local::oldSettingsVersion() < AppVersion) {
|
||||||
|
psNewVersion();
|
||||||
|
}
|
||||||
if (cFromAutoStart() && !cAutoStart()) {
|
if (cFromAutoStart() && !cAutoStart()) {
|
||||||
psAutoStart(false, true);
|
psAutoStart(false, true);
|
||||||
Local::stop();
|
Local::stop();
|
||||||
|
@ -1249,6 +1249,10 @@ void psRegisterCustomScheme() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void psNewVersion() {
|
||||||
|
psRegisterCustomScheme();
|
||||||
|
}
|
||||||
|
|
||||||
bool _execUpdater(bool update = true) {
|
bool _execUpdater(bool update = true) {
|
||||||
static const int MaxLen = 65536, MaxArgsCount = 128;
|
static const int MaxLen = 65536, MaxArgsCount = 128;
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ void psShowInFolder(const QString &name);
|
|||||||
void psStart();
|
void psStart();
|
||||||
void psFinish();
|
void psFinish();
|
||||||
|
|
||||||
void psRegisterCustomScheme();
|
void psNewVersion();
|
||||||
|
|
||||||
void psUpdateOverlayed(QWidget *widget);
|
void psUpdateOverlayed(QWidget *widget);
|
||||||
inline QString psConvertFileUrl(const QString &url) {
|
inline QString psConvertFileUrl(const QString &url) {
|
||||||
|
@ -653,7 +653,7 @@ void psFinish() {
|
|||||||
objc_finish();
|
objc_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void psRegisterCustomScheme() {
|
void psNewVersion() {
|
||||||
objc_registerCustomScheme();
|
objc_registerCustomScheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ void psShowInFolder(const QString &name);
|
|||||||
void psStart();
|
void psStart();
|
||||||
void psFinish();
|
void psFinish();
|
||||||
|
|
||||||
void psRegisterCustomScheme();
|
void psNewVersion();
|
||||||
|
|
||||||
void psUpdateOverlayed(QWidget *widget);
|
void psUpdateOverlayed(QWidget *widget);
|
||||||
QString psConvertFileUrl(const QString &url);
|
QString psConvertFileUrl(const QString &url);
|
||||||
|
@ -1197,6 +1197,7 @@ void PsMainWindow::psInitSize() {
|
|||||||
|
|
||||||
bool InitToastManager();
|
bool InitToastManager();
|
||||||
bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title, const QString &subtitle, const QString &msg);
|
bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title, const QString &subtitle, const QString &msg);
|
||||||
|
void CheckPinnedAppUserModelId();
|
||||||
void CleanupAppUserModelIdShortcut();
|
void CleanupAppUserModelIdShortcut();
|
||||||
|
|
||||||
void PsMainWindow::psInitFrameless() {
|
void PsMainWindow::psInitFrameless() {
|
||||||
@ -2197,9 +2198,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void psRegisterCustomScheme() {
|
void RegisterCustomScheme() {
|
||||||
|
|
||||||
|
|
||||||
DEBUG_LOG(("App Info: Checking custom scheme 'tg'.."));
|
DEBUG_LOG(("App Info: Checking custom scheme 'tg'.."));
|
||||||
|
|
||||||
HKEY rkey;
|
HKEY rkey;
|
||||||
@ -2218,6 +2217,11 @@ void psRegisterCustomScheme() {
|
|||||||
if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return;
|
if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void psNewVersion() {
|
||||||
|
RegisterCustomScheme();
|
||||||
|
CheckPinnedAppUserModelId();
|
||||||
|
}
|
||||||
|
|
||||||
void psExecUpdater() {
|
void psExecUpdater() {
|
||||||
QString targs = qsl("-update");
|
QString targs = qsl("-update");
|
||||||
if (cFromAutoStart()) targs += qsl(" -autostart");
|
if (cFromAutoStart()) targs += qsl(" -autostart");
|
||||||
@ -2805,6 +2809,120 @@ bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString pinnedPath() {
|
||||||
|
static const int maxFileLen = MAX_PATH * 10;
|
||||||
|
WCHAR wstrPath[maxFileLen];
|
||||||
|
if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) {
|
||||||
|
QDir appData(QString::fromStdWString(std::wstring(wstrPath)));
|
||||||
|
return appData.absolutePath() + qsl("/Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar/");
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckPinnedAppUserModelId() {
|
||||||
|
static const int maxFileLen = MAX_PATH * 10;
|
||||||
|
|
||||||
|
HRESULT hr = CoInitialize(0);
|
||||||
|
if (!SUCCEEDED(hr)) return;
|
||||||
|
|
||||||
|
QString path = pinnedPath();
|
||||||
|
std::wstring p = QDir::toNativeSeparators(path).toStdWString();
|
||||||
|
|
||||||
|
WCHAR src[MAX_PATH];
|
||||||
|
GetModuleFileNameEx(GetCurrentProcess(), nullptr, src, MAX_PATH);
|
||||||
|
BY_HANDLE_FILE_INFORMATION srcinfo = { 0 };
|
||||||
|
HANDLE srcfile = CreateFile(src, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (srcfile == INVALID_HANDLE_VALUE) return;
|
||||||
|
BOOL srcres = GetFileInformationByHandle(srcfile, &srcinfo);
|
||||||
|
CloseHandle(srcfile);
|
||||||
|
if (!srcres) return;
|
||||||
|
LOG(("Checking.."));
|
||||||
|
WIN32_FIND_DATA findData;
|
||||||
|
HANDLE findHandle = FindFirstFileEx((p + L"*").c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, 0, 0);
|
||||||
|
if (findHandle == INVALID_HANDLE_VALUE) {
|
||||||
|
LOG(("Init Error: could not find files in pinned folder"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
std::wstring fname = p + findData.cFileName;
|
||||||
|
LOG(("Checking %1").arg(QString::fromStdWString(fname)));
|
||||||
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
DWORD attributes = GetFileAttributes(fname.c_str());
|
||||||
|
if (attributes >= 0xFFFFFFF) continue; // file does not exist
|
||||||
|
|
||||||
|
ComPtr<IShellLink> shellLink;
|
||||||
|
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
|
||||||
|
if (!SUCCEEDED(hr)) continue;
|
||||||
|
|
||||||
|
ComPtr<IPersistFile> persistFile;
|
||||||
|
hr = shellLink.As(&persistFile);
|
||||||
|
if (!SUCCEEDED(hr)) continue;
|
||||||
|
|
||||||
|
hr = persistFile->Load(fname.c_str(), STGM_READWRITE);
|
||||||
|
if (!SUCCEEDED(hr)) continue;
|
||||||
|
|
||||||
|
WCHAR dst[MAX_PATH];
|
||||||
|
hr = shellLink->GetPath(dst, MAX_PATH, 0, 0);
|
||||||
|
if (!SUCCEEDED(hr)) continue;
|
||||||
|
|
||||||
|
BY_HANDLE_FILE_INFORMATION dstinfo = { 0 };
|
||||||
|
HANDLE dstfile = CreateFile(dst, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (dstfile == INVALID_HANDLE_VALUE) continue;
|
||||||
|
BOOL dstres = GetFileInformationByHandle(dstfile, &dstinfo);
|
||||||
|
CloseHandle(dstfile);
|
||||||
|
if (!dstres) continue;
|
||||||
|
|
||||||
|
if (srcinfo.dwVolumeSerialNumber == dstinfo.dwVolumeSerialNumber && srcinfo.nFileIndexLow == dstinfo.nFileIndexLow && srcinfo.nFileIndexHigh == dstinfo.nFileIndexHigh) {
|
||||||
|
ComPtr<IPropertyStore> propertyStore;
|
||||||
|
hr = shellLink.As(&propertyStore);
|
||||||
|
if (!SUCCEEDED(hr)) return;
|
||||||
|
|
||||||
|
PROPVARIANT appIdPropVar;
|
||||||
|
hr = propertyStore->GetValue(pkey_AppUserModel_ID, &appIdPropVar);
|
||||||
|
if (!SUCCEEDED(hr)) return;
|
||||||
|
LOG(("Reading.."));
|
||||||
|
WCHAR already[MAX_PATH];
|
||||||
|
hr = propVariantToString(appIdPropVar, already, MAX_PATH);
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
if (std::wstring(AppUserModelId) == already) {
|
||||||
|
LOG(("Already!"));
|
||||||
|
PropVariantClear(&appIdPropVar);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appIdPropVar.vt != VT_EMPTY) {
|
||||||
|
PropVariantClear(&appIdPropVar);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PropVariantClear(&appIdPropVar);
|
||||||
|
|
||||||
|
hr = InitPropVariantFromString(AppUserModelId, &appIdPropVar);
|
||||||
|
if (!SUCCEEDED(hr)) return;
|
||||||
|
|
||||||
|
hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar);
|
||||||
|
PropVariantClear(&appIdPropVar);
|
||||||
|
if (!SUCCEEDED(hr)) return;
|
||||||
|
|
||||||
|
hr = propertyStore->Commit();
|
||||||
|
if (!SUCCEEDED(hr)) return;
|
||||||
|
|
||||||
|
if (persistFile->IsDirty() == S_OK) {
|
||||||
|
persistFile->Save(fname.c_str(), TRUE);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (FindNextFile(findHandle, &findData));
|
||||||
|
DWORD errorCode = GetLastError();
|
||||||
|
if (errorCode && errorCode != ERROR_NO_MORE_FILES) { // everything is found
|
||||||
|
LOG(("Init Error: could not find some files in pinned folder"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FindClose(findHandle);
|
||||||
|
}
|
||||||
|
|
||||||
QString systemShortcutPath() {
|
QString systemShortcutPath() {
|
||||||
static const int maxFileLen = MAX_PATH * 10;
|
static const int maxFileLen = MAX_PATH * 10;
|
||||||
WCHAR wstrPath[maxFileLen];
|
WCHAR wstrPath[maxFileLen];
|
||||||
@ -2963,7 +3081,6 @@ bool ValidateAppUserModelIdShortcut() {
|
|||||||
|
|
||||||
bool InitToastManager() {
|
bool InitToastManager() {
|
||||||
if (!useToast || !ValidateAppUserModelIdShortcut()) return false;
|
if (!useToast || !ValidateAppUserModelIdShortcut()) return false;
|
||||||
|
|
||||||
if (!SUCCEEDED(setCurrentProcessExplicitAppUserModelID(AppUserModelId))) {
|
if (!SUCCEEDED(setCurrentProcessExplicitAppUserModelID(AppUserModelId))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ void psShowInFolder(const QString &name);
|
|||||||
void psStart();
|
void psStart();
|
||||||
void psFinish();
|
void psFinish();
|
||||||
|
|
||||||
void psRegisterCustomScheme();
|
void psNewVersion();
|
||||||
|
|
||||||
void psUpdateOverlayed(TWidget *widget);
|
void psUpdateOverlayed(TWidget *widget);
|
||||||
inline QString psConvertFileUrl(const QString &url) {
|
inline QString psConvertFileUrl(const QString &url) {
|
||||||
|
Loading…
Reference in New Issue
Block a user