diff --git a/Telegram/SourceFiles/_other/updater_osx.m b/Telegram/SourceFiles/_other/updater_osx.m index 7431908f7d..ea6f0d68b8 100644 --- a/Telegram/SourceFiles/_other/updater_osx.m +++ b/Telegram/SourceFiles/_other/updater_osx.m @@ -6,6 +6,7 @@ For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #import +#include NSString *appName = @"Telegram.app"; NSString *appDir = nil; @@ -44,6 +45,20 @@ void writeLog(NSString *msg) { [_logFile synchronizeFile]; } +void RemoveQuarantineAttribute(NSString *path) { + const char *kQuarantineAttribute = "com.apple.quarantine"; + + writeLog([@"Removing quarantine: " stringByAppendingString:path]); + removexattr([path fileSystemRepresentation], kQuarantineAttribute, 0); +} + +void RemoveQuarantineFromBundle(NSString *path) { + RemoveQuarantineAttribute(path); + RemoveQuarantineAttribute([path stringByAppendingString:@"/Contents/MacOS/Telegram"]); + RemoveQuarantineAttribute([path stringByAppendingString:@"/Contents/Helpers/crashpad_handler"]); + RemoveQuarantineAttribute([path stringByAppendingString:@"/Contents/Frameworks/Updater"]); +} + void delFolder() { writeLog([@"Fully clearing old path: " stringByAppendingString:[workDir stringByAppendingString:@"tupdates/ready"]]); if (![[NSFileManager defaultManager] removeItemAtPath:[workDir stringByAppendingString:@"tupdates/ready"] error:nil]) { @@ -232,6 +247,9 @@ int main(int argc, const char * argv[]) { } NSString *appPath = [[NSArray arrayWithObjects:appDir, appRealName, nil] componentsJoinedByString:@""]; + + RemoveQuarantineFromBundle(appPath); + NSMutableArray *args = [[NSMutableArray alloc] initWithObjects: @"-noupdate", nil]; if (toSettings) [args addObject:@"-tosettings"]; if (_debug) [args addObject:@"-debug"]; diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 078f974f99..021da0cf5c 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -1547,6 +1547,12 @@ bool checkReadyUpdate() { return false; } #endif // Q_OS_LINUX + +#ifdef Q_OS_MAC + Platform::RemoveQuarantine(QFileInfo(curUpdater).absolutePath()); + Platform::RemoveQuarantine(updater.absolutePath()); +#endif // Q_OS_MAC + return true; } diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index d9964a715e..9b256e5b25 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -158,68 +158,6 @@ QAbstractNativeEventFilter *psNativeEventFilter() { void psWriteDump() { } -QString demanglestr(const QString &mangled) { - if (mangled.isEmpty()) return mangled; - - QByteArray cmd = ("c++filt -n " + mangled).toUtf8(); - FILE *f = popen(cmd.constData(), "r"); - if (!f) return "BAD_SYMBOL_" + mangled; - - QString result; - char buffer[4096] = { 0 }; - while (!feof(f)) { - if (fgets(buffer, 4096, f) != NULL) { - result += buffer; - } - } - pclose(f); - return result.trimmed(); -} - -QStringList addr2linestr(uint64 *addresses, int count) { - QStringList result; - if (!count || cExeName().isEmpty()) return result; - - result.reserve(count); - QByteArray cmd = "addr2line -e " + EscapeShell(QFile::encodeName(cExeDir() + cExeName())); - for (int i = 0; i < count; ++i) { - if (addresses[i]) { - cmd += qsl(" 0x%1").arg(addresses[i], 0, 16).toUtf8(); - } - } - FILE *f = popen(cmd.constData(), "r"); - - QStringList addr2lineResult; - if (f) { - char buffer[4096] = {0}; - while (!feof(f)) { - if (fgets(buffer, 4096, f) != NULL) { - addr2lineResult.push_back(QString::fromUtf8(buffer)); - } - } - pclose(f); - } - for (int i = 0, j = 0; i < count; ++i) { - if (addresses[i]) { - if (j < addr2lineResult.size() && !addr2lineResult.at(j).isEmpty() && !addr2lineResult.at(j).startsWith(qstr("0x"))) { - QString res = addr2lineResult.at(j).trimmed(); - if (int index = res.indexOf(qstr("/Telegram/"))) { - if (index > 0) { - res = res.mid(index + qstr("/Telegram/").size()); - } - } - result.push_back(res); - } else { - result.push_back(QString()); - } - ++j; - } else { - result.push_back(QString()); - } - } - return result; -} - bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c QByteArray pathRaw = QFile::encodeName(path); DIR *d = opendir(pathRaw.constData()); diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.mm b/Telegram/SourceFiles/platform/mac/launcher_mac.mm index 5553d52be7..bb3d94470a 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "core/update_checker.h" #include "platform/mac/mac_utilities.h" +#include "platform/platform_specific.h" #include #include @@ -117,6 +118,7 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { return false; } path = [path stringByAppendingString:@"/Contents/Frameworks/Updater"]; + RemoveQuarantine(QFile::decodeName([path fileSystemRepresentation])); NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:@"-workpath", Q2NSString(cWorkingDir()), @"-procid", nil]; [args addObject:[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]]; diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index 3f56c1f28f..4faaa2ebf7 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -19,6 +19,8 @@ inline bool TranslucentWindowsSupported(QPoint globalPosition) { QString CurrentExecutablePath(int argc, char *argv[]); +void RemoveQuarantine(const QString &path); + namespace ThirdParty { inline void start() { diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 30829bc89f..2fbf860b91 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +#include #include #include @@ -85,85 +86,6 @@ void psWriteDump() { #endif // TDESKTOP_DISABLE_CRASH_REPORTS } -QString demanglestr(const QString &mangled) { - QByteArray cmd = ("c++filt -n " + mangled).toUtf8(); - FILE *f = popen(cmd.constData(), "r"); - if (!f) return "BAD_SYMBOL_" + mangled; - - QString result; - char buffer[4096] = {0}; - while (!feof(f)) { - if (fgets(buffer, 4096, f) != NULL) { - result += buffer; - } - } - pclose(f); - return result.trimmed(); -} - -QString escapeShell(const QString &str) { - QString result; - const QChar *b = str.constData(), *e = str.constEnd(); - for (const QChar *ch = b; ch != e; ++ch) { - if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') { - if (result.isEmpty()) { - result.reserve(str.size() * 2); - } - if (ch > b) { - result.append(b, ch - b); - } - result.append('\\'); - b = ch; - } - } - if (result.isEmpty()) return str; - - if (e > b) { - result.append(b, e - b); - } - return result; -} - -QStringList atosstr(uint64 *addresses, int count, uint64 base) { - QStringList result; - if (!count || cExeName().isEmpty()) return result; - - result.reserve(count); - QString cmdstr = "atos -o " + escapeShell(cExeDir() + cExeName()) + qsl("/Contents/MacOS/Telegram -l 0x%1").arg(base, 0, 16); - for (int i = 0; i < count; ++i) { - if (addresses[i]) { - cmdstr += qsl(" 0x%1").arg(addresses[i], 0, 16); - } - } - QByteArray cmd = cmdstr.toUtf8(); - FILE *f = popen(cmd.constData(), "r"); - - QStringList atosResult; - if (f) { - char buffer[4096] = {0}; - while (!feof(f)) { - if (fgets(buffer, 4096, f) != NULL) { - atosResult.push_back(QString::fromUtf8(buffer)); - } - } - pclose(f); - } - for (int i = 0, j = 0; i < count; ++i) { - if (addresses[i]) { - if (j < atosResult.size() && !atosResult.at(j).isEmpty() && !atosResult.at(j).startsWith(qstr("0x"))) { - result.push_back(atosResult.at(j).trimmed()); - } else { - result.push_back(QString()); - } - ++j; - } else { - result.push_back(QString()); - } - } - return result; - -} - void psDeleteDir(const QString &dir) { objc_deleteDir(dir); } @@ -272,6 +194,14 @@ QString CurrentExecutablePath(int argc, char *argv[]) { return NS2QString([[NSBundle mainBundle] bundlePath]); } +void RemoveQuarantine(const QString &path) { + const auto kQuarantineAttribute = "com.apple.quarantine"; + + DEBUG_LOG(("Removing quarantine attribute: %1").arg(path)); + const auto local = QFile::encodeName(path); + removexattr(local.data(), kQuarantineAttribute, 0); +} + void RegisterCustomScheme() { #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME OSStatus result = LSSetDefaultHandlerForURLScheme(CFSTR("tg"), (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]); diff --git a/Telegram/Telegram.plist b/Telegram/Telegram.plist index 47bdf4d774..af4435e35a 100644 --- a/Telegram/Telegram.plist +++ b/Telegram/Telegram.plist @@ -35,6 +35,8 @@ public.app-category.social-networking LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) + LSFileQuarantineEnabled + NOTE NSMicrophoneUsageDescription