mirror of https://github.com/procxx/kepka.git
Use base::FileNameFromUserString.
This commit is contained in:
parent
3ae7f9f93d
commit
27a83a7a09
|
@ -160,53 +160,6 @@ QString DefaultDownloadPath() {
|
||||||
+ '/';
|
+ '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NameFromUserString(QString name) {
|
|
||||||
static const auto Bad = { '/', '\\', '<', '>', ':', '"', '|', '?', '*' };
|
|
||||||
for (auto &ch : name) {
|
|
||||||
if (ch < 32 || ranges::find(Bad, ch.unicode()) != end(Bad)) {
|
|
||||||
ch = '_';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name.isEmpty() || name.endsWith(' ') || name.endsWith('.')) {
|
|
||||||
name.append('_');
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
static const auto BadNames = {
|
|
||||||
qstr("CON"),
|
|
||||||
qstr("PRN"),
|
|
||||||
qstr("AUX"),
|
|
||||||
qstr("NUL"),
|
|
||||||
qstr("COM1"),
|
|
||||||
qstr("COM2"),
|
|
||||||
qstr("COM3"),
|
|
||||||
qstr("COM4"),
|
|
||||||
qstr("COM5"),
|
|
||||||
qstr("COM6"),
|
|
||||||
qstr("COM7"),
|
|
||||||
qstr("COM8"),
|
|
||||||
qstr("COM9"),
|
|
||||||
qstr("LPT1"),
|
|
||||||
qstr("LPT2"),
|
|
||||||
qstr("LPT3"),
|
|
||||||
qstr("LPT4"),
|
|
||||||
qstr("LPT5"),
|
|
||||||
qstr("LPT6"),
|
|
||||||
qstr("LPT7"),
|
|
||||||
qstr("LPT8"),
|
|
||||||
qstr("LPT9")
|
|
||||||
};
|
|
||||||
for (const auto bad : BadNames) {
|
|
||||||
if (name.startsWith(bad, Qt::CaseInsensitive)) {
|
|
||||||
if (name.size() == bad.size() || name[bad.size()] == '.') {
|
|
||||||
name = '_' + name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // Q_OS_WIN
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
void UnsafeOpenEmailLinkDefault(const QString &email) {
|
void UnsafeOpenEmailLinkDefault(const QString &email) {
|
||||||
|
|
|
@ -37,8 +37,6 @@ void ShowInFolder(const QString &filepath);
|
||||||
|
|
||||||
[[nodiscard]] QString DefaultDownloadPath();
|
[[nodiscard]] QString DefaultDownloadPath();
|
||||||
|
|
||||||
[[nodiscard]] QString NameFromUserString(QString name);
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
inline QString UrlToLocalDefault(const QUrl &url) {
|
inline QString UrlToLocalDefault(const QUrl &url) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
#include "ui/image/image_source.h"
|
#include "ui/image/image_source.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
#include "base/base_file_utilities.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "lottie/lottie_animation.h"
|
#include "lottie/lottie_animation.h"
|
||||||
|
@ -136,13 +137,7 @@ QString FileNameUnsafe(
|
||||||
QString name,
|
QString name,
|
||||||
bool savingAs,
|
bool savingAs,
|
||||||
const QDir &dir) {
|
const QDir &dir) {
|
||||||
#ifdef Q_OS_WIN
|
name = base::FileNameFromUserString(name);
|
||||||
name = name.replace(QRegularExpression(qsl("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|]")), qsl("_"));
|
|
||||||
#elif defined Q_OS_MAC
|
|
||||||
name = name.replace(QRegularExpression(qsl("[\\:]")), qsl("_"));
|
|
||||||
#elif defined Q_OS_LINUX
|
|
||||||
name = name.replace(QRegularExpression(qsl("[\\/]")), qsl("_"));
|
|
||||||
#endif
|
|
||||||
if (Global::AskDownloadPath() || savingAs) {
|
if (Global::AskDownloadPath() || savingAs) {
|
||||||
if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) {
|
if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) {
|
||||||
name = filedialogDefaultName(prefix, name);
|
name = filedialogDefaultName(prefix, name);
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "export/export_settings.h"
|
#include "export/export_settings.h"
|
||||||
#include "export/output/export_output_file.h"
|
#include "export/output/export_output_file.h"
|
||||||
|
#include "base/base_file_utilities.h"
|
||||||
#include "core/mime_type.h"
|
#include "core/mime_type.h"
|
||||||
#include "core/utils.h"
|
#include "core/utils.h"
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
|
@ -337,53 +338,6 @@ QString ComputeDocumentName(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CleanDocumentName(QString name) {
|
|
||||||
// We don't want LTR/RTL mark/embedding/override/isolate chars
|
|
||||||
// in filenames, because they introduce a security issue, when
|
|
||||||
// an executable "Fil[x]gepj.exe" may look like "Filexe.jpeg".
|
|
||||||
QChar controls[] = {
|
|
||||||
0x200E, // LTR Mark
|
|
||||||
0x200F, // RTL Mark
|
|
||||||
0x202A, // LTR Embedding
|
|
||||||
0x202B, // RTL Embedding
|
|
||||||
0x202D, // LTR Override
|
|
||||||
0x202E, // RTL Override
|
|
||||||
0x2066, // LTR Isolate
|
|
||||||
0x2067, // RTL Isolate
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
'\\',
|
|
||||||
'/',
|
|
||||||
':',
|
|
||||||
'*',
|
|
||||||
'?',
|
|
||||||
'"',
|
|
||||||
'<',
|
|
||||||
'>',
|
|
||||||
'|',
|
|
||||||
#elif defined Q_OS_MAC // Q_OS_WIN
|
|
||||||
':',
|
|
||||||
#elif defined Q_OS_LINUX // Q_OS_WIN || Q_OS_MAC
|
|
||||||
'/',
|
|
||||||
#endif // Q_OS_WIN || Q_OS_MAC || Q_OS_LINUX
|
|
||||||
};
|
|
||||||
for (const auto ch : controls) {
|
|
||||||
name = std::move(name).replace(ch, '_');
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
const auto lower = name.trimmed().toLower();
|
|
||||||
const auto kBadExtensions = { qstr(".lnk"), qstr(".scf") };
|
|
||||||
const auto kMaskExtension = qsl(".download");
|
|
||||||
for (const auto extension : kBadExtensions) {
|
|
||||||
if (lower.endsWith(extension)) {
|
|
||||||
return name + kMaskExtension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // Q_OS_WIN
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DocumentFolder(const Document &data) {
|
QString DocumentFolder(const Document &data) {
|
||||||
if (data.isVideoFile) {
|
if (data.isVideoFile) {
|
||||||
return "video_files";
|
return "video_files";
|
||||||
|
@ -469,7 +423,8 @@ Document ParseDocument(
|
||||||
MTP_string());
|
MTP_string());
|
||||||
result.file.suggestedPath = suggestedFolder
|
result.file.suggestedPath = suggestedFolder
|
||||||
+ DocumentFolder(result) + '/'
|
+ DocumentFolder(result) + '/'
|
||||||
+ CleanDocumentName(ComputeDocumentName(context, result, date));
|
+ base::FileNameFromUserString(
|
||||||
|
ComputeDocumentName(context, result, date));
|
||||||
|
|
||||||
result.thumb = ParseDocumentThumb(
|
result.thumb = ParseDocumentThumb(
|
||||||
data,
|
data,
|
||||||
|
|
|
@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "base/event_filter.h"
|
#include "base/event_filter.h"
|
||||||
|
#include "base/base_file_utilities.h"
|
||||||
#include "base/zlib_help.h"
|
#include "base/zlib_help.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -435,7 +436,7 @@ SendMediaReady PrepareThemeMedia(
|
||||||
};
|
};
|
||||||
push("s", std::move(thumbnail));
|
push("s", std::move(thumbnail));
|
||||||
|
|
||||||
const auto filename = File::NameFromUserString(name)
|
const auto filename = base::FileNameFromUserString(name)
|
||||||
+ qsl(".tdesktop-theme");
|
+ qsl(".tdesktop-theme");
|
||||||
auto attributes = QVector<MTPDocumentAttribute>(
|
auto attributes = QVector<MTPDocumentAttribute>(
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit dd5ca832f9b212e553ea5afee9a2dab2c3acd982
|
Subproject commit 2169055d740dc069924e609fcc473006e5511134
|
|
@ -1 +1 @@
|
||||||
Subproject commit bc62f87f0ec7a0ef21ad4f676ef65cbb3d3631a4
|
Subproject commit 37f777e230215aeba0ee6eba149cff7b64d7ed0d
|
Loading…
Reference in New Issue