mirror of https://github.com/procxx/kepka.git
improved os x updater
This commit is contained in:
parent
ecc6899b42
commit
d62d5908d1
|
@ -64,11 +64,17 @@ int main(int argc, const char * argv[]) {
|
|||
if (!path) {
|
||||
return -1;
|
||||
}
|
||||
NSRange range = [path rangeOfString:appName options:NSBackwardsSearch];
|
||||
NSRange range = [path rangeOfString:@".app/" options:NSBackwardsSearch];
|
||||
if (range.location == NSNotFound) {
|
||||
return -1;
|
||||
}
|
||||
appDir = [path substringToIndex:range.location > 0 ? range.location : 0];
|
||||
path = [path substringToIndex:range.location > 0 ? range.location : 0];
|
||||
|
||||
range = [path rangeOfString:@"/" options:NSBackwardsSearch];
|
||||
NSString *appRealName = (range.location == NSNotFound) ? path : [path substringFromIndex:range.location + 1];
|
||||
appRealName = [[NSArray arrayWithObjects:appRealName, @".app", nil] componentsJoinedByString:@""];
|
||||
appDir = (range.location == NSNotFound) ? @"" : [path substringToIndex:range.location + 1];
|
||||
NSString *appDirFull = [appDir stringByAppendingString:appRealName];
|
||||
|
||||
openLog();
|
||||
pid_t procId = 0;
|
||||
|
@ -144,11 +150,12 @@ int main(int argc, const char * argv[]) {
|
|||
break;
|
||||
}
|
||||
NSString *pathPart = [srcPath substringFromIndex:r.length];
|
||||
if ([pathPart rangeOfString:appName].location != 0) {
|
||||
r = [pathPart rangeOfString:appName];
|
||||
if (r.location != 0) {
|
||||
writeLog([@"Skipping not app file " stringByAppendingString:srcPath]);
|
||||
continue;
|
||||
}
|
||||
NSString *dstPath = [appDir stringByAppendingString:pathPart];
|
||||
NSString *dstPath = [appDirFull stringByAppendingString:[pathPart substringFromIndex:r.length]];
|
||||
NSError *error;
|
||||
NSNumber *isDirectory = nil;
|
||||
writeLog([[NSArray arrayWithObjects: @"Copying file ", srcPath, @" to ", dstPath, nil] componentsJoinedByString:@""]);
|
||||
|
@ -180,7 +187,7 @@ int main(int argc, const char * argv[]) {
|
|||
delFolder();
|
||||
}
|
||||
|
||||
NSString *appPath = [[NSArray arrayWithObjects:appDir, appName, nil] componentsJoinedByString:@""];
|
||||
NSString *appPath = [[NSArray arrayWithObjects:appDir, appRealName, nil] componentsJoinedByString:@""];
|
||||
NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:@"-noupdate", nil];
|
||||
if (toSettings) [args addObject:@"-tosettings"];
|
||||
if (_debug) [args addObject:@"-debug"];
|
||||
|
|
|
@ -800,13 +800,23 @@ QString psCurrentExeDirectory(int argc, char *argv[]) {
|
|||
if (!first.isEmpty()) {
|
||||
QFileInfo info(first);
|
||||
if (info.exists()) {
|
||||
QDir result(info.absolutePath());
|
||||
return result.absolutePath() + '/';
|
||||
return QDir(info.absolutePath()).absolutePath() + '/';
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString psCurrentExeName(int argc, char *argv[]) {
|
||||
QString first = argc ? QString::fromLocal8Bit(argv[0]) : QString();
|
||||
if (!first.isEmpty()) {
|
||||
QFileInfo info(first);
|
||||
if (info.exists()) {
|
||||
return info.fileName();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void psDoCleanup() {
|
||||
try {
|
||||
psAutoStart(false, true);
|
||||
|
|
|
@ -167,6 +167,7 @@ QString psCurrentLanguage();
|
|||
QString psAppDataPath();
|
||||
QString psDownloadPath();
|
||||
QString psCurrentExeDirectory(int argc, char *argv[]);
|
||||
QString psCurrentExeName(int argc, char *argv[]);
|
||||
void psAutoStart(bool start, bool silent = false);
|
||||
void psSendToMenu(bool send, bool silent = false);
|
||||
|
||||
|
|
|
@ -984,13 +984,23 @@ QString psCurrentExeDirectory(int argc, char *argv[]) {
|
|||
if (!first.isEmpty()) {
|
||||
QFileInfo info(first);
|
||||
if (info.exists()) {
|
||||
QDir result(info.absolutePath() + qsl("/../../.."));
|
||||
return result.absolutePath() + '/';
|
||||
return QDir(info.absolutePath() + qsl("/../../..")).absolutePath() + '/';
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString psCurrentExeName(int argc, char *argv[]) {
|
||||
QString first = argc ? QString::fromLocal8Bit(argv[0]) : QString();
|
||||
if (!first.isEmpty()) {
|
||||
QFileInfo info(first);
|
||||
if (info.exists()) {
|
||||
return QDir(QDir(info.absolutePath() + qsl("/../..")).absolutePath()).dirName();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void psDoCleanup() {
|
||||
try {
|
||||
psAutoStart(false, true);
|
||||
|
@ -1042,11 +1052,11 @@ bool psCheckReadyUpdate() {
|
|||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QString curUpdater = (cExeDir() + "Updater.exe");
|
||||
QFileInfo updater(cWorkingDir() + "tupdates/ready/Updater.exe");
|
||||
QString curUpdater = (cExeDir() + qsl("Updater.exe"));
|
||||
QFileInfo updater(cWorkingDir() + qsl("tupdates/ready/Updater.exe"));
|
||||
#elif defined Q_OS_MAC
|
||||
QString curUpdater = (cExeDir() + "Telegram.app/Contents/Frameworks/Updater");
|
||||
QFileInfo updater(cWorkingDir() + "tupdates/ready/Telegram.app/Contents/Frameworks/Updater");
|
||||
QString curUpdater = (cExeDir() + cExeName() + qsl("/Contents/Frameworks/Updater"));
|
||||
QFileInfo updater(cWorkingDir() + qsl("tupdates/ready/Telegram.app/Contents/Frameworks/Updater"));
|
||||
#endif
|
||||
if (!updater.exists()) {
|
||||
QFileInfo current(curUpdater);
|
||||
|
@ -1069,8 +1079,8 @@ bool psCheckReadyUpdate() {
|
|||
return false;
|
||||
}
|
||||
#elif defined Q_OS_MAC
|
||||
QFileInfo to(curUpdater);
|
||||
QDir().mkpath(to.absolutePath());
|
||||
QDir().mkpath(QFileInfo(curUpdater).absolutePath());
|
||||
DEBUG_LOG(("Update Info: moving %1 to %2..").arg(updater.absoluteFilePath()).arg(curUpdater));
|
||||
if (!objc_moveFile(updater.absoluteFilePath(), curUpdater)) {
|
||||
PsUpdateDownloader::clearAll();
|
||||
return false;
|
||||
|
|
|
@ -200,6 +200,7 @@ QString psCurrentLanguage();
|
|||
QString psAppDataPath();
|
||||
QString psDownloadPath();
|
||||
QString psCurrentExeDirectory(int argc, char *argv[]);
|
||||
QString psCurrentExeName(int argc, char *argv[]);
|
||||
void psAutoStart(bool start, bool silent = false);
|
||||
void psSendToMenu(bool send, bool silent = false);
|
||||
|
||||
|
|
|
@ -1966,6 +1966,20 @@ QString psCurrentExeDirectory(int argc, char *argv[]) {
|
|||
return QString();
|
||||
}
|
||||
|
||||
QString psCurrentExeName(int argc, char *argv[]) {
|
||||
LPWSTR *args;
|
||||
int argsCount;
|
||||
args = CommandLineToArgvW(GetCommandLine(), &argsCount);
|
||||
if (args) {
|
||||
QFileInfo info(QDir::fromNativeSeparators(QString::fromWCharArray(args[0])));
|
||||
if (info.isFile()) {
|
||||
return info.fileName();
|
||||
}
|
||||
LocalFree(args);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void psDoCleanup() {
|
||||
try {
|
||||
psAutoStart(false, true);
|
||||
|
@ -2077,8 +2091,8 @@ bool psCheckReadyUpdate() {
|
|||
}
|
||||
}
|
||||
|
||||
QString curUpdater = (cExeDir() + "Updater.exe");
|
||||
QFileInfo updater(cWorkingDir() + "tupdates/ready/Updater.exe");
|
||||
QString curUpdater = (cExeDir() + qsl("Updater.exe"));
|
||||
QFileInfo updater(cWorkingDir() + qsl("tupdates/ready/Updater.exe"));
|
||||
if (!updater.exists()) {
|
||||
QFileInfo current(curUpdater);
|
||||
if (!current.exists()) {
|
||||
|
|
|
@ -178,6 +178,7 @@ QString psAppDataPath();
|
|||
QString psAppDataPathOld();
|
||||
QString psDownloadPath();
|
||||
QString psCurrentExeDirectory(int argc, char *argv[]);
|
||||
QString psCurrentExeName(int argc, char *argv[]);
|
||||
void psAutoStart(bool start, bool silent = false);
|
||||
void psSendToMenu(bool send, bool silent = false);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ bool gTestMode = false;
|
|||
bool gDebug = false;
|
||||
bool gManyInstance = false;
|
||||
QString gKeyFile;
|
||||
QString gWorkingDir, gExeDir;
|
||||
QString gWorkingDir, gExeDir, gExeName;
|
||||
|
||||
QStringList gSendPaths;
|
||||
|
||||
|
@ -106,6 +106,7 @@ void settingsParseArgs(int argc, char *argv[]) {
|
|||
}
|
||||
memset_rand(&gInstance, sizeof(gInstance));
|
||||
gExeDir = psCurrentExeDirectory(argc, argv);
|
||||
gExeName = psCurrentExeName(argc, argv);
|
||||
for (int32 i = 0; i < argc; ++i) {
|
||||
if (string("-release") == argv[i]) {
|
||||
gTestMode = false;
|
||||
|
|
|
@ -62,6 +62,7 @@ inline void cForceWorkingDir(const QString &newDir) {
|
|||
QDir dir;
|
||||
if (!gWorkingDir.isEmpty()) dir.mkpath(gWorkingDir);
|
||||
}
|
||||
DeclareReadSetting(QString, ExeName);
|
||||
DeclareReadSetting(QString, ExeDir);
|
||||
DeclareSetting(QString, DialogLastPath);
|
||||
DeclareSetting(QString, DialogHelperPath);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<key>CFBundleGetInfoString</key>
|
||||
<string>Telegram Desktop messaging app</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.tdesktop.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||
<string>com.tdesktop.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
|
|
Loading…
Reference in New Issue