diff --git a/Telegram/SourceFiles/layout.cpp b/Telegram/SourceFiles/layout.cpp index 54a7d259dd..2dcd973d7b 100644 --- a/Telegram/SourceFiles/layout.cpp +++ b/Telegram/SourceFiles/layout.cpp @@ -215,3 +215,23 @@ style::sprite documentCorner(int32 colorIndex) { RoundCorners documentCorners(int32 colorIndex) { return RoundCorners(DocBlueCorners + (colorIndex & 3)); } + +bool documentIsValidMediaFile(const QString &filepath) { + static StaticNeverFreedPointer> validMediaTypes(([] { + std_::unique_ptr> result = std_::make_unique>(); + *result = qsl("\ +webm mkv flv vob ogv ogg drc gif gifv mng avi mov qt wmv yuv rm rmvb asf amv mp4 m4p \ +m4v mpg mp2 mpeg mpe mpv m2v svi 3gp 3g2 mxf roq nsv f4v f4p f4a f4b wma divx evo mk3d \ +mka mks mcf m2p ps ts m2ts ifo aaf avchd cam dat dsh dvr-ms m1v fla flr sol wrap smi swf \ +wtv 8svx 16svx iff aiff aif aifc au bwf cdda raw wav flac la pac m4a ape ofr ofs off rka \ +shn tak tta wv brstm dts dtshd dtsma ast amr mp3 spx gsm aac mpc vqf ra ots swa vox voc \ +dwd smp aup cust mid mus sib sid ly gym vgm psf nsf mod ptb s3m xm it mt2 minipsf psflib \ +2sf dsf gsf psf2 qsf ssf usf rmj spc niff mxl xml txm ym jam mp1 mscz \ +").split(' '); + return result.release(); + })()); + + QFileInfo info(filepath); + auto parts = info.fileName().split('.', QString::SkipEmptyParts); + return !parts.isEmpty() && (validMediaTypes->indexOf(parts.back().toLower()) >= 0); +} diff --git a/Telegram/SourceFiles/layout.h b/Telegram/SourceFiles/layout.h index 86e6298e2f..7ac05fdeb0 100644 --- a/Telegram/SourceFiles/layout.h +++ b/Telegram/SourceFiles/layout.h @@ -81,6 +81,7 @@ style::color documentOverColor(int32 colorIndex); style::color documentSelectedColor(int32 colorIndex); style::sprite documentCorner(int32 colorIndex); RoundCorners documentCorners(int32 colorIndex); +bool documentIsValidMediaFile(const QString &filepath); class PaintContextBase { public: diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index fab6779307..99dd01174d 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1541,7 +1541,11 @@ void MainWidget::audioPlayProgress(const AudioMsgId &audioId) { DocumentData *audio = audioId.audio; QString filepath = audio->filepath(DocumentData::FilePathResolveSaveFromData); if (!filepath.isEmpty()) { - psOpenFile(filepath); + if (documentIsValidMediaFile(filepath)) { + psOpenFile(filepath); + } else { + psShowInFolder(filepath); + } } } @@ -1568,7 +1572,11 @@ void MainWidget::documentPlayProgress(const SongMsgId &songId) { DocumentData *document = songId.song; QString filepath = document->filepath(DocumentData::FilePathResolveSaveFromData); if (!filepath.isEmpty()) { - psOpenFile(filepath); + if (documentIsValidMediaFile(filepath)) { + psOpenFile(filepath); + } else { + psShowInFolder(filepath); + } } } diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 4b3e006d7d..54b8f78005 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -975,8 +975,13 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, ActionOnLoad action) { audioPlayer()->play(song); if (App::main()) App::main()->documentPlayProgress(song); } - } else if (data->voice() || data->isVideo()) { - psOpenFile(location.name()); + } else if (data->voice() || data->song() || data->isVideo()) { + auto filepath = location.name(); + if (documentIsValidMediaFile(filepath)) { + psOpenFile(filepath); + } else { + psShowInFolder(filepath); + } if (App::main()) App::main()->mediaMarkRead(data); } else if (data->size < MediaViewImageSizeLimit) { if (!data->data().isEmpty() && playAnimation) { @@ -1270,8 +1275,12 @@ void DocumentData::performActionOnLoad() { psOpenFile(already, true); } } else if (_actionOnLoad == ActionOnLoadOpen || _actionOnLoad == ActionOnLoadPlayInline) { - if (voice() || isVideo()) { - psOpenFile(already); + if (voice() || song() || isVideo()) { + if (documentIsValidMediaFile(already)) { + psOpenFile(already); + } else { + psShowInFolder(already); + } if (App::main()) App::main()->mediaMarkRead(this); } else if (loc.accessEnable()) { if (showImage && QImageReader(loc.name()).canRead()) {