moved from utf8 to QFile::encode/decodeName
This commit is contained in:
		
							parent
							
								
									839078d32f
								
							
						
					
					
						commit
						001f2e1fe7
					
				
					 5 changed files with 30 additions and 32 deletions
				
			
		| 
						 | 
					@ -149,7 +149,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
 | 
				
			||||||
, _updateChecker(0)
 | 
					, _updateChecker(0)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	QByteArray d(QDir(cWorkingDir()).absolutePath().toUtf8());
 | 
						QByteArray d(QFile::encodeName(QDir(cWorkingDir()).absolutePath()));
 | 
				
			||||||
	char h[33] = { 0 };
 | 
						char h[33] = { 0 };
 | 
				
			||||||
	hashMd5Hex(d.constData(), d.size(), h);
 | 
						hashMd5Hex(d.constData(), d.size(), h);
 | 
				
			||||||
	_localServerName = psServerPrefix() + h + '-' + cGUIDStr();
 | 
						_localServerName = psServerPrefix() + h + '-' + cGUIDStr();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,6 @@ void FlatLabel::setText(const QString &text) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FlatLabel::setRichText(const QString &text) {
 | 
					void FlatLabel::setRichText(const QString &text) {
 | 
				
			||||||
	textstyleSet(&_tst);
 | 
						textstyleSet(&_tst);
 | 
				
			||||||
    const char *t = text.toUtf8().constData();
 | 
					 | 
				
			||||||
	_text.setRichText(_st.font, text, _labelOptions);
 | 
						_text.setRichText(_st.font, text, _labelOptions);
 | 
				
			||||||
	int32 w = _st.width ? _st.width : _text.maxWidth(), h = _text.countHeight(w);
 | 
						int32 w = _st.width ? _st.width : _text.maxWidth(), h = _text.countHeight(w);
 | 
				
			||||||
	textstyleRestore();
 | 
						textstyleRestore();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -885,7 +885,7 @@ namespace SignalHandlers {
 | 
				
			||||||
#ifdef MAC_USE_BREAKPAD
 | 
					#ifdef MAC_USE_BREAKPAD
 | 
				
			||||||
#ifndef _DEBUG
 | 
					#ifndef _DEBUG
 | 
				
			||||||
		BreakpadExceptionHandler = new google_breakpad::ExceptionHandler(
 | 
							BreakpadExceptionHandler = new google_breakpad::ExceptionHandler(
 | 
				
			||||||
			dumpspath.toUtf8().toStdString(),
 | 
								QFile::encodeName(dumpspath).toStdString(),
 | 
				
			||||||
			/*FilterCallback*/ 0,
 | 
								/*FilterCallback*/ 0,
 | 
				
			||||||
			DumpCallback,
 | 
								DumpCallback,
 | 
				
			||||||
			/*context*/ 0,
 | 
								/*context*/ 0,
 | 
				
			||||||
| 
						 | 
					@ -897,7 +897,7 @@ namespace SignalHandlers {
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
		crashpad::CrashpadClient crashpad_client;
 | 
							crashpad::CrashpadClient crashpad_client;
 | 
				
			||||||
		std::string handler = (cExeDir() + cExeName() + qsl("/Contents/Helpers/crashpad_handler")).toUtf8().constData();
 | 
							std::string handler = (cExeDir() + cExeName() + qsl("/Contents/Helpers/crashpad_handler")).toUtf8().constData();
 | 
				
			||||||
		std::string database = dumpspath.toUtf8().constData();
 | 
							std::string database = QFile::encodeName(dumpspath).constData();
 | 
				
			||||||
		if (crashpad_client.StartHandler(base::FilePath(handler),
 | 
							if (crashpad_client.StartHandler(base::FilePath(handler),
 | 
				
			||||||
										 base::FilePath(database),
 | 
															 base::FilePath(database),
 | 
				
			||||||
										 std::string(),
 | 
															 std::string(),
 | 
				
			||||||
| 
						 | 
					@ -909,7 +909,7 @@ namespace SignalHandlers {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#elif defined Q_OS_LINUX64 || defined Q_OS_LINUX32
 | 
					#elif defined Q_OS_LINUX64 || defined Q_OS_LINUX32
 | 
				
			||||||
		BreakpadExceptionHandler = new google_breakpad::ExceptionHandler(
 | 
							BreakpadExceptionHandler = new google_breakpad::ExceptionHandler(
 | 
				
			||||||
			google_breakpad::MinidumpDescriptor(dumpspath.toUtf8().toStdString()),
 | 
								google_breakpad::MinidumpDescriptor(QFile::encodeName(dumpspath).toStdString()),
 | 
				
			||||||
			/*FilterCallback*/ 0,
 | 
								/*FilterCallback*/ 0,
 | 
				
			||||||
			DumpCallback,
 | 
								DumpCallback,
 | 
				
			||||||
			/*context*/ 0,
 | 
								/*context*/ 0,
 | 
				
			||||||
| 
						 | 
					@ -930,7 +930,7 @@ namespace SignalHandlers {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Status start() {
 | 
						Status start() {
 | 
				
			||||||
		CrashDumpPath = (cWorkingDir() + qsl("tdata/working")).toUtf8();
 | 
							CrashDumpPath = QFile::encodeName(cWorkingDir() + qsl("tdata/working"));
 | 
				
			||||||
		if (FILE *f = fopen(CrashDumpPath.constData(), "rb")) {
 | 
							if (FILE *f = fopen(CrashDumpPath.constData(), "rb")) {
 | 
				
			||||||
			QByteArray lastdump;
 | 
								QByteArray lastdump;
 | 
				
			||||||
			char buffer[64 * 1024] = { 0 };
 | 
								char buffer[64 * 1024] = { 0 };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,10 +43,10 @@ extern "C" {
 | 
				
			||||||
#include <unity/unity/unity.h>
 | 
					#include <unity/unity/unity.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
    QString escapeShell(const QString &str) {
 | 
					    QByteArray escapeShell(const QByteArray &str) {
 | 
				
			||||||
        QString result;
 | 
					        QByteArray result;
 | 
				
			||||||
        const QChar *b = str.constData(), *e = str.constEnd();
 | 
					        const char *b = str.constData(), *e = str.constEnd();
 | 
				
			||||||
        for (const QChar *ch = b; ch != e; ++ch) {
 | 
					        for (const char *ch = b; ch != e; ++ch) {
 | 
				
			||||||
            if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') {
 | 
					            if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') {
 | 
				
			||||||
                if (result.isEmpty()) {
 | 
					                if (result.isEmpty()) {
 | 
				
			||||||
                    result.reserve(str.size() * 2);
 | 
					                    result.reserve(str.size() * 2);
 | 
				
			||||||
| 
						 | 
					@ -974,13 +974,12 @@ QStringList addr2linestr(uint64 *addresses, int count) {
 | 
				
			||||||
	if (!count) return result;
 | 
						if (!count) return result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result.reserve(count);
 | 
						result.reserve(count);
 | 
				
			||||||
	QString cmdstr = "addr2line -e " + escapeShell(cExeDir() + cExeName());
 | 
						QByteArray cmd = "addr2line -e " + escapeShell(QFile::encodeName(cExeDir() + cExeName()));
 | 
				
			||||||
	for (int i = 0; i < count; ++i) {
 | 
						for (int i = 0; i < count; ++i) {
 | 
				
			||||||
		if (addresses[i]) {
 | 
							if (addresses[i]) {
 | 
				
			||||||
			cmdstr += qsl(" 0x%1").arg(addresses[i], 0, 16);
 | 
								cmd += qsl(" 0x%1").arg(addresses[i], 0, 16).toUtf8();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	QByteArray cmd = cmdstr.toUtf8();
 | 
					 | 
				
			||||||
	FILE *f = popen(cmd.constData(), "r");
 | 
						FILE *f = popen(cmd.constData(), "r");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QStringList addr2lineResult;
 | 
						QStringList addr2lineResult;
 | 
				
			||||||
| 
						 | 
					@ -1165,7 +1164,7 @@ QString psCurrentLanguage() {
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
    QString _psHomeDir() {
 | 
					    QString _psHomeDir() {
 | 
				
			||||||
        struct passwd *pw = getpwuid(getuid());
 | 
					        struct passwd *pw = getpwuid(getuid());
 | 
				
			||||||
        return (pw && pw->pw_dir && strlen(pw->pw_dir)) ? (fromUtf8Safe(pw->pw_dir) + '/') : QString();
 | 
					        return (pw && pw->pw_dir && strlen(pw->pw_dir)) ? (QFile::decodeName(pw->pw_dir) + '/') : QString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1179,7 +1178,7 @@ QString psDownloadPath() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString psCurrentExeDirectory(int argc, char *argv[]) {
 | 
					QString psCurrentExeDirectory(int argc, char *argv[]) {
 | 
				
			||||||
    QString first = argc ? fromUtf8Safe(argv[0]) : QString();
 | 
					    QString first = argc ? QFile::decodeName(argv[0]) : QString();
 | 
				
			||||||
    if (!first.isEmpty()) {
 | 
					    if (!first.isEmpty()) {
 | 
				
			||||||
        QFileInfo info(first);
 | 
					        QFileInfo info(first);
 | 
				
			||||||
        if (info.isSymLink()) {
 | 
					        if (info.isSymLink()) {
 | 
				
			||||||
| 
						 | 
					@ -1193,7 +1192,7 @@ QString psCurrentExeDirectory(int argc, char *argv[]) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString psCurrentExeName(int argc, char *argv[]) {
 | 
					QString psCurrentExeName(int argc, char *argv[]) {
 | 
				
			||||||
	QString first = argc ? fromUtf8Safe(argv[0]) : QString();
 | 
						QString first = argc ? QFile::decodeName(argv[0]) : QString();
 | 
				
			||||||
	if (!first.isEmpty()) {
 | 
						if (!first.isEmpty()) {
 | 
				
			||||||
		QFileInfo info(first);
 | 
							QFileInfo info(first);
 | 
				
			||||||
        if (info.isSymLink()) {
 | 
					        if (info.isSymLink()) {
 | 
				
			||||||
| 
						 | 
					@ -1236,7 +1235,7 @@ void psOpenFile(const QString &name, bool openWith) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void psShowInFolder(const QString &name) {
 | 
					void psShowInFolder(const QString &name) {
 | 
				
			||||||
    Ui::hideLayer(true);
 | 
					    Ui::hideLayer(true);
 | 
				
			||||||
    system((qsl("xdg-open ") + escapeShell(QFileInfo(name).absoluteDir().absolutePath())).toUtf8().constData());
 | 
					    system(("xdg-open " + escapeShell(QFile::encodeName(QFileInfo(name).absoluteDir().absolutePath()))).constData());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace PlatformSpecific {
 | 
					namespace PlatformSpecific {
 | 
				
			||||||
| 
						 | 
					@ -1262,13 +1261,13 @@ namespace PlatformSpecific {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
    bool _psRunCommand(const QString &command) {
 | 
					    bool _psRunCommand(const QByteArray &command) {
 | 
				
			||||||
        int result = system(command.toUtf8().constData());
 | 
					        int result = system(command.constData());
 | 
				
			||||||
        if (result) {
 | 
					        if (result) {
 | 
				
			||||||
            DEBUG_LOG(("App Error: command failed, code: %1, command (in utf8): %2").arg(result).arg(command));
 | 
					            DEBUG_LOG(("App Error: command failed, code: %1, command (in utf8): %2").arg(result).arg(command.constData()));
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        DEBUG_LOG(("App Info: command succeeded, command (in utf8): %1").arg(command));
 | 
					        DEBUG_LOG(("App Info: command succeeded, command (in utf8): %1").arg(command.constData()));
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1304,7 +1303,7 @@ void psRegisterCustomScheme() {
 | 
				
			||||||
            s << "Version=1.0\n";
 | 
					            s << "Version=1.0\n";
 | 
				
			||||||
            s << "Name=Telegram Desktop\n";
 | 
					            s << "Name=Telegram Desktop\n";
 | 
				
			||||||
            s << "Comment=Official desktop version of Telegram messaging app\n";
 | 
					            s << "Comment=Official desktop version of Telegram messaging app\n";
 | 
				
			||||||
            s << "Exec=" << escapeShell(cExeDir() + cExeName()) << " -- %u\n";
 | 
					            s << "Exec=" << escapeShell(QFile::encodeName(cExeDir() + cExeName())) << " -- %u\n";
 | 
				
			||||||
            s << "Icon=telegram\n";
 | 
					            s << "Icon=telegram\n";
 | 
				
			||||||
            s << "Terminal=false\n";
 | 
					            s << "Terminal=false\n";
 | 
				
			||||||
            s << "StartupWMClass=Telegram\n";
 | 
					            s << "StartupWMClass=Telegram\n";
 | 
				
			||||||
| 
						 | 
					@ -1313,12 +1312,12 @@ void psRegisterCustomScheme() {
 | 
				
			||||||
            s << "MimeType=application/x-xdg-protocol-tg;x-scheme-handler/tg;\n";
 | 
					            s << "MimeType=application/x-xdg-protocol-tg;x-scheme-handler/tg;\n";
 | 
				
			||||||
            f.close();
 | 
					            f.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (_psRunCommand(qsl("desktop-file-install --dir=%1 --delete-original %2").arg(escapeShell(home + qsl(".local/share/applications"))).arg(escapeShell(file)))) {
 | 
					            if (_psRunCommand("desktop-file-install --dir=" + escapeShell(QFile::encodeName(home + qsl(".local/share/applications"))) + " --delete-original " + escapeShell(QFile::encodeName(file)))) {
 | 
				
			||||||
                DEBUG_LOG(("App Info: removing old .desktop file"));
 | 
					                DEBUG_LOG(("App Info: removing old .desktop file"));
 | 
				
			||||||
                QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove();
 | 
					                QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                _psRunCommand(qsl("update-desktop-database %1").arg(escapeShell(home + qsl(".local/share/applications"))));
 | 
					                _psRunCommand("update-desktop-database " + escapeShell(QFile::encodeName(home + qsl(".local/share/applications"))));
 | 
				
			||||||
                _psRunCommand(qsl("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg"));
 | 
					                _psRunCommand("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            LOG(("App Error: Could not open '%1' for write").arg(file));
 | 
					            LOG(("App Error: Could not open '%1' for write").arg(file));
 | 
				
			||||||
| 
						 | 
					@ -1326,9 +1325,9 @@ void psRegisterCustomScheme() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DEBUG_LOG(("App Info: registerting for Gnome"));
 | 
					    DEBUG_LOG(("App Info: registerting for Gnome"));
 | 
				
			||||||
    if (_psRunCommand(qsl("gconftool-2 -t string -s /desktop/gnome/url-handlers/tg/command %1").arg(escapeShell(qsl("%1 -- %s").arg(escapeShell(cExeDir() + cExeName())))))) {
 | 
					    if (_psRunCommand("gconftool-2 -t string -s /desktop/gnome/url-handlers/tg/command " + escapeShell(escapeShell(QFile::encodeName(cExeDir() + cExeName())) + " -- %s"))) {
 | 
				
			||||||
        _psRunCommand(qsl("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/needs_terminal false"));
 | 
					        _psRunCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/needs_terminal false");
 | 
				
			||||||
        _psRunCommand(qsl("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/enabled true"));
 | 
					        _psRunCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/enabled true");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DEBUG_LOG(("App Info: placing .protocol file"));
 | 
					    DEBUG_LOG(("App Info: placing .protocol file"));
 | 
				
			||||||
| 
						 | 
					@ -1347,7 +1346,7 @@ void psRegisterCustomScheme() {
 | 
				
			||||||
            QTextStream s(&f);
 | 
					            QTextStream s(&f);
 | 
				
			||||||
            s.setCodec("UTF-8");
 | 
					            s.setCodec("UTF-8");
 | 
				
			||||||
            s << "[Protocol]\n";
 | 
					            s << "[Protocol]\n";
 | 
				
			||||||
            s << "exec=" << escapeShell(cExeDir() + cExeName()) << " -- %u\n";
 | 
					            s << "exec=" << QFile::decodeName(escapeShell(QFile::encodeName(cExeDir() + cExeName()))) << " -- %u\n";
 | 
				
			||||||
            s << "protocol=tg\n";
 | 
					            s << "protocol=tg\n";
 | 
				
			||||||
            s << "input=none\n";
 | 
					            s << "input=none\n";
 | 
				
			||||||
            s << "output=none\n";
 | 
					            s << "output=none\n";
 | 
				
			||||||
| 
						 | 
					@ -1396,14 +1395,14 @@ bool _execUpdater(bool update = true, const QString &crashreport = QString()) {
 | 
				
			||||||
            args[argIndex++] = p_datafile;
 | 
					            args[argIndex++] = p_datafile;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    QByteArray pathf = cWorkingDir().toUtf8();
 | 
					    QByteArray pathf = QFile::encodeName(cWorkingDir());
 | 
				
			||||||
    if (pathf.size() < MaxLen) {
 | 
					    if (pathf.size() < MaxLen) {
 | 
				
			||||||
        memcpy(p_pathbuf, pathf.constData(), pathf.size());
 | 
					        memcpy(p_pathbuf, pathf.constData(), pathf.size());
 | 
				
			||||||
        args[argIndex++] = p_path;
 | 
					        args[argIndex++] = p_path;
 | 
				
			||||||
        args[argIndex++] = p_pathbuf;
 | 
					        args[argIndex++] = p_pathbuf;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
	if (!crashreport.isEmpty()) {
 | 
						if (!crashreport.isEmpty()) {
 | 
				
			||||||
		QByteArray crashreportf = crashreport.toUtf8();
 | 
							QByteArray crashreportf = QFile::encodeName(crashreport);
 | 
				
			||||||
		if (crashreportf.size() < MaxLen) {
 | 
							if (crashreportf.size() < MaxLen) {
 | 
				
			||||||
			memcpy(p_crashreportbuf, crashreportf.constData(), crashreportf.size());
 | 
								memcpy(p_crashreportbuf, crashreportf.constData(), crashreportf.size());
 | 
				
			||||||
			args[argIndex++] = p_crashreport;
 | 
								args[argIndex++] = p_crashreport;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2919,7 +2919,7 @@ int showCrashReportWindow(const QString &crashdump) {
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QByteArray args[] = { QDir::toNativeSeparators(cExeDir() + cExeName()).toUtf8() };
 | 
						QByteArray args[] = { QFile::encodeName(QDir::toNativeSeparators(cExeDir() + cExeName())) };
 | 
				
			||||||
	int a_argc = 1;
 | 
						int a_argc = 1;
 | 
				
			||||||
	char *a_argv[1] = { args[0].data() };
 | 
						char *a_argv[1] = { args[0].data() };
 | 
				
			||||||
	QApplication app(a_argc, a_argv);
 | 
						QApplication app(a_argc, a_argv);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue