mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Option to set API ID and hash from start parameter
This commit is contained in:
@@ -363,9 +363,12 @@ int main(int argc, char *argv[]) {
|
|||||||
bool testmode = false;
|
bool testmode = false;
|
||||||
bool externalupdater = false;
|
bool externalupdater = false;
|
||||||
bool customWorkingDir = false;
|
bool customWorkingDir = false;
|
||||||
|
bool useEnvApi = true;
|
||||||
|
|
||||||
char *key = 0;
|
char *key = 0;
|
||||||
char *workdir = 0;
|
char *workdir = 0;
|
||||||
|
char *customApiId = 0;
|
||||||
|
char *customApiHash = 0;
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (equal(argv[i], "-noupdate")) {
|
if (equal(argv[i], "-noupdate")) {
|
||||||
needupdate = false;
|
needupdate = false;
|
||||||
@@ -391,6 +394,12 @@ int main(int argc, char *argv[]) {
|
|||||||
exeName = argv[i];
|
exeName = argv[i];
|
||||||
} else if (equal(argv[i], "-exepath") && ++i < argc) {
|
} else if (equal(argv[i], "-exepath") && ++i < argc) {
|
||||||
exePath = argv[i];
|
exePath = argv[i];
|
||||||
|
} else if (equal(argv[i], "-no-env-api")) {
|
||||||
|
useEnvApi = false;
|
||||||
|
} else if (equal(argv[i], "-api-id") && ++i < argc) {
|
||||||
|
customApiId = argv[i];
|
||||||
|
} else if (equal(argv[i], "-api-hash") && ++i < argc) {
|
||||||
|
customApiHash = argv[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exeName.empty() || exeName.find('/') != string::npos) {
|
if (exeName.empty() || exeName.find('/') != string::npos) {
|
||||||
@@ -488,6 +497,14 @@ int main(int argc, char *argv[]) {
|
|||||||
push(workdir);
|
push(workdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!useEnvApi) push("-no-env-api");
|
||||||
|
if (customApiId && customApiHash) {
|
||||||
|
push("-api-id");
|
||||||
|
push(customApiId);
|
||||||
|
push("-api-hash");
|
||||||
|
push(customApiHash);
|
||||||
|
}
|
||||||
|
|
||||||
auto args = vector<char*>();
|
auto args = vector<char*>();
|
||||||
for (auto &arg : values) {
|
for (auto &arg : values) {
|
||||||
args.push_back(arg.data());
|
args.push_back(arg.data());
|
||||||
|
@@ -91,8 +91,10 @@ int main(int argc, const char * argv[]) {
|
|||||||
openLog();
|
openLog();
|
||||||
pid_t procId = 0;
|
pid_t procId = 0;
|
||||||
BOOL update = YES, toSettings = NO, autoStart = NO, startInTray = NO, testMode = NO, freeType = NO, externalUpdater = NO;
|
BOOL update = YES, toSettings = NO, autoStart = NO, startInTray = NO, testMode = NO, freeType = NO, externalUpdater = NO;
|
||||||
BOOL customWorkingDir = NO;
|
BOOL customWorkingDir = NO, useEnvApi = YES;
|
||||||
NSString *key = nil;
|
NSString *key = nil;
|
||||||
|
NSString *customApiId = nil;
|
||||||
|
NSString *customApiHash = nil;
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
if ([@"-workpath" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
if ([@"-workpath" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
||||||
if (++i < argc) {
|
if (++i < argc) {
|
||||||
@@ -124,6 +126,12 @@ int main(int argc, const char * argv[]) {
|
|||||||
customWorkingDir = YES;
|
customWorkingDir = YES;
|
||||||
} else if ([@"-key" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
} else if ([@"-key" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
||||||
if (++i < argc) key = [NSString stringWithUTF8String:argv[i]];
|
if (++i < argc) key = [NSString stringWithUTF8String:argv[i]];
|
||||||
|
} else if ([@"-no-env-api" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
||||||
|
useEnvApi = NO;
|
||||||
|
} else if ([@"-api-id" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
||||||
|
if (++i < argc) customApiId = [NSString stringWithUTF8String:argv[i]];
|
||||||
|
} else if ([@"-api-hash" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) {
|
||||||
|
if (++i < argc) customApiHash = [NSString stringWithUTF8String:argv[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!workDir) {
|
if (!workDir) {
|
||||||
@@ -268,6 +276,13 @@ int main(int argc, const char * argv[]) {
|
|||||||
[args addObject:@"-workdir"];
|
[args addObject:@"-workdir"];
|
||||||
[args addObject:workDir];
|
[args addObject:workDir];
|
||||||
}
|
}
|
||||||
|
if (!useEnvApi) [args addObject:@"-no-env-api"];
|
||||||
|
if (customApiId && customApiHash) {
|
||||||
|
[args addObject:@"-api-id"];
|
||||||
|
[args addObject:customApiId];
|
||||||
|
[args addObject:@"-api-hash"];
|
||||||
|
[args addObject:customApiHash];
|
||||||
|
}
|
||||||
writeLog([[NSArray arrayWithObjects:@"Running application '", appPath, @"' with args '", [args componentsJoinedByString:@"' '"], @"'..", nil] componentsJoinedByString:@""]);
|
writeLog([[NSArray arrayWithObjects:@"Running application '", appPath, @"' with args '", [args componentsJoinedByString:@"' '"], @"'..", nil] componentsJoinedByString:@""]);
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
bool _debug = false;
|
bool _debug = false;
|
||||||
|
|
||||||
wstring updaterName, updaterDir, updateTo, exeName, customWorkingDir, customKeyFile;
|
wstring updaterName, updaterDir, updateTo, exeName, customWorkingDir, customKeyFile;
|
||||||
|
wstring customApiId, customApiHash;
|
||||||
|
|
||||||
bool equal(const wstring &a, const wstring &b) {
|
bool equal(const wstring &a, const wstring &b) {
|
||||||
return !_wcsicmp(a.c_str(), b.c_str());
|
return !_wcsicmp(a.c_str(), b.c_str());
|
||||||
@@ -340,6 +341,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara
|
|||||||
int argsCount;
|
int argsCount;
|
||||||
|
|
||||||
bool needupdate = false, autostart = false, debug = false, writeprotected = false, startintray = false, testmode = false, freetype = false, externalupdater = false;
|
bool needupdate = false, autostart = false, debug = false, writeprotected = false, startintray = false, testmode = false, freetype = false, externalupdater = false;
|
||||||
|
bool useEnvApi = true;
|
||||||
args = CommandLineToArgvW(GetCommandLine(), &argsCount);
|
args = CommandLineToArgvW(GetCommandLine(), &argsCount);
|
||||||
if (args) {
|
if (args) {
|
||||||
for (int i = 1; i < argsCount; ++i) {
|
for (int i = 1; i < argsCount; ++i) {
|
||||||
@@ -383,6 +385,14 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (equal(args[i], L"-no-env-api")) {
|
||||||
|
useEnvApi = false;
|
||||||
|
} else if (equal(args[i], L"-api-id") && ++i < argsCount) {
|
||||||
|
writeLog(std::wstring(L"Argument: ") + args[i]);
|
||||||
|
customApiId = args[i];
|
||||||
|
} else if (equal(args[i], L"-api-hash") && ++i < argsCount) {
|
||||||
|
writeLog(std::wstring(L"Argument: ") + args[i]);
|
||||||
|
customApiHash = args[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exeName.empty()) {
|
if (exeName.empty()) {
|
||||||
@@ -437,6 +447,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara
|
|||||||
if (!customKeyFile.empty()) {
|
if (!customKeyFile.empty()) {
|
||||||
targs += L" -key \"" + customKeyFile + L"\"";
|
targs += L" -key \"" + customKeyFile + L"\"";
|
||||||
}
|
}
|
||||||
|
if (!useEnvApi) targs += L" -no-env-api";
|
||||||
|
if (!customApiId.empty() && !customApiHash.empty()) {
|
||||||
|
targs += L" -api-id \"" + customApiId + L"\"";
|
||||||
|
targs += L" -api-hash \"" + customApiHash + L"\"";
|
||||||
|
}
|
||||||
writeLog(L"Result arguments: " + targs);
|
writeLog(L"Result arguments: " + targs);
|
||||||
|
|
||||||
bool executed = false;
|
bool executed = false;
|
||||||
|
@@ -335,10 +335,12 @@ int Launcher::exec() {
|
|||||||
Platform::start();
|
Platform::start();
|
||||||
Ui::DisableCustomScaling();
|
Ui::DisableCustomScaling();
|
||||||
|
|
||||||
if (qEnvironmentVariableIsSet(kApiIdVarName.utf8())
|
if (cUseEnvApi()
|
||||||
|
&& qEnvironmentVariableIsSet(kApiIdVarName.utf8())
|
||||||
&& qEnvironmentVariableIsSet(kApiHashVarName.utf8())) {
|
&& qEnvironmentVariableIsSet(kApiHashVarName.utf8())) {
|
||||||
cSetApiId(qgetenv(kApiIdVarName.utf8()).toInt());
|
cSetApiId(qgetenv(kApiIdVarName.utf8()).toInt());
|
||||||
cSetApiHash(QString::fromLatin1(qgetenv(kApiHashVarName.utf8())));
|
cSetApiHash(QString::fromLatin1(qgetenv(kApiHashVarName.utf8())));
|
||||||
|
cSetApiFromStartParams(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = executeApplication();
|
auto result = executeApplication();
|
||||||
@@ -463,6 +465,9 @@ void Launcher::processArguments() {
|
|||||||
{ "-workdir" , KeyFormat::OneValue },
|
{ "-workdir" , KeyFormat::OneValue },
|
||||||
{ "--" , KeyFormat::OneValue },
|
{ "--" , KeyFormat::OneValue },
|
||||||
{ "-scale" , KeyFormat::OneValue },
|
{ "-scale" , KeyFormat::OneValue },
|
||||||
|
{ "-no-env-api" , KeyFormat::NoValues },
|
||||||
|
{ "-api-id" , KeyFormat::OneValue },
|
||||||
|
{ "-api-hash" , KeyFormat::OneValue },
|
||||||
};
|
};
|
||||||
auto parseResult = QMap<QByteArray, QStringList>();
|
auto parseResult = QMap<QByteArray, QStringList>();
|
||||||
auto parsingKey = QByteArray();
|
auto parsingKey = QByteArray();
|
||||||
@@ -520,6 +525,15 @@ void Launcher::processArguments() {
|
|||||||
? style::kScaleAuto
|
? style::kScaleAuto
|
||||||
: value;
|
: value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gUseEnvApi = !parseResult.contains("-no-env-api");
|
||||||
|
auto customApiId = parseResult.value("-api-id", {}).join(QString()).toInt();
|
||||||
|
auto customApiHash = parseResult.value("-api-hash", {}).join(QString());
|
||||||
|
if (customApiId > 0 && !customApiHash.isEmpty()) {
|
||||||
|
gApiId = customApiId;
|
||||||
|
gApiHash = customApiHash;
|
||||||
|
gApiFromStartParams = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Launcher::executeApplication() {
|
int Launcher::executeApplication() {
|
||||||
|
@@ -216,3 +216,6 @@ int gApiId = 0;
|
|||||||
QString gApiHash;
|
QString gApiHash;
|
||||||
|
|
||||||
#endif // TDESKTOP_API_ID && TDESKTOP_API_HASH
|
#endif // TDESKTOP_API_ID && TDESKTOP_API_HASH
|
||||||
|
|
||||||
|
bool gUseEnvApi = true;
|
||||||
|
bool gApiFromStartParams = false;
|
||||||
|
@@ -127,3 +127,5 @@ DeclareSetting(bool, ForwardChatOnClick);
|
|||||||
|
|
||||||
DeclareSetting(int, ApiId);
|
DeclareSetting(int, ApiId);
|
||||||
DeclareSetting(QString, ApiHash);
|
DeclareSetting(QString, ApiHash);
|
||||||
|
DeclareSetting(bool, UseEnvApi);
|
||||||
|
DeclareSetting(bool, ApiFromStartParams);
|
||||||
|
@@ -96,6 +96,17 @@ bool Launcher::launchUpdater(UpdaterLaunch action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cUseEnvApi()) {
|
||||||
|
argumentsList.push("-no-env-api");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cApiFromStartParams()) {
|
||||||
|
argumentsList.push("-api-id");
|
||||||
|
argumentsList.push(QFile::encodeName(QString::number(cApiId())));
|
||||||
|
argumentsList.push("-api-hash");
|
||||||
|
argumentsList.push(QFile::encodeName(cApiHash()));
|
||||||
|
}
|
||||||
|
|
||||||
Logs::closeMain();
|
Logs::closeMain();
|
||||||
CrashReports::Finish();
|
CrashReports::Finish();
|
||||||
|
|
||||||
|
@@ -74,6 +74,13 @@ bool Launcher::launchUpdater(UpdaterLaunch action) {
|
|||||||
if (customWorkingDir()) {
|
if (customWorkingDir()) {
|
||||||
[args addObject:@"-workdir_custom"];
|
[args addObject:@"-workdir_custom"];
|
||||||
}
|
}
|
||||||
|
if (!cUseEnvApi()) [args addObject:@"-no-env-api"];
|
||||||
|
if (cApiFromStartParams()) {
|
||||||
|
[args addObject:@"-api-id"];
|
||||||
|
[args addObject:Q2NSString(QString::number(cApiId()))];
|
||||||
|
[args addObject:@"-api-hash"];
|
||||||
|
[args addObject:Q2NSString(cApiHash())];
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_LOG(("Application Info: executing %1 %2").arg(NS2QString(path)).arg(NS2QString([args componentsJoinedByString:@" "])));
|
DEBUG_LOG(("Application Info: executing %1 %2").arg(NS2QString(path)).arg(NS2QString([args componentsJoinedByString:@" "])));
|
||||||
Logs::closeMain();
|
Logs::closeMain();
|
||||||
|
@@ -99,6 +99,16 @@ bool Launcher::launchUpdater(UpdaterLaunch action) {
|
|||||||
pushArgument('"' + cExeDir() + '"');
|
pushArgument('"' + cExeDir() + '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cUseEnvApi()) {
|
||||||
|
pushArgument(qsl("-no-env-api"));
|
||||||
|
}
|
||||||
|
if (cApiFromStartParams()) {
|
||||||
|
pushArgument(qsl("-api-id"));
|
||||||
|
pushArgument('"' + QString::number(cApiId()) + '"');
|
||||||
|
pushArgument(qsl("-api-hash"));
|
||||||
|
pushArgument('"' + cApiHash() + '"');
|
||||||
|
}
|
||||||
return launch(operation, binaryPath, argumentsList);
|
return launch(operation, binaryPath, argumentsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -458,6 +458,15 @@ void RegisterCustomScheme(bool force) {
|
|||||||
|
|
||||||
HKEY rkey;
|
HKEY rkey;
|
||||||
QString exe = QDir::toNativeSeparators(cExeDir() + cExeName());
|
QString exe = QDir::toNativeSeparators(cExeDir() + cExeName());
|
||||||
|
QString possibleParams;
|
||||||
|
|
||||||
|
if (!cUseEnvApi()) {
|
||||||
|
possibleParams += " -no-env-api";
|
||||||
|
}
|
||||||
|
if (cApiFromStartParams()) {
|
||||||
|
possibleParams += " -api-id \"" + QString::number(cApiId()) + "\"";
|
||||||
|
possibleParams += " -api-hash \"" + cApiHash() + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
// Legacy URI scheme registration
|
// Legacy URI scheme registration
|
||||||
if (!_psOpenRegKey(L"Software\\Classes\\tg", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\tg", &rkey)) return;
|
||||||
@@ -470,7 +479,7 @@ void RegisterCustomScheme(bool force) {
|
|||||||
if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell", &rkey)) return;
|
||||||
if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open", &rkey)) return;
|
||||||
if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open\\command", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open\\command", &rkey)) return;
|
||||||
if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return;
|
if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\"") + possibleParams + qsl(" -- \"%1\""))) return;
|
||||||
|
|
||||||
// URI scheme registration as Default Program - Windows Vista and above
|
// URI scheme registration as Default Program - Windows Vista and above
|
||||||
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg", &rkey)) return;
|
||||||
@@ -480,7 +489,7 @@ void RegisterCustomScheme(bool force) {
|
|||||||
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg\\shell", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg\\shell", &rkey)) return;
|
||||||
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg\\shell\\open", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg\\shell\\open", &rkey)) return;
|
||||||
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg\\shell\\open\\command", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\Classes\\ktgdesktop.tg\\shell\\open\\command", &rkey)) return;
|
||||||
if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return;
|
if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\"") + possibleParams + qsl(" -- \"%1\""))) return;
|
||||||
|
|
||||||
if (!_psOpenRegKey(L"Software\\KotatogramDesktop", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\KotatogramDesktop", &rkey)) return;
|
||||||
if (!_psOpenRegKey(L"Software\\KotatogramDesktop\\Capabilities", &rkey)) return;
|
if (!_psOpenRegKey(L"Software\\KotatogramDesktop\\Capabilities", &rkey)) return;
|
||||||
|
Reference in New Issue
Block a user