From 532727b034d42f9414a7b7699be4134334e9b406 Mon Sep 17 00:00:00 2001 From: usermeme Date: Mon, 25 Dec 2017 19:23:24 +0300 Subject: [PATCH] Fix add music --- sync/mysql.cpp | 4 ++++ sync/song.cpp | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sync/mysql.cpp b/sync/mysql.cpp index ddcdc2b..5035982 100644 --- a/sync/mysql.cpp +++ b/sync/mysql.cpp @@ -166,6 +166,10 @@ int MySql::save(const QString &url){ song.size = bytes.size(); song.source = bytes; + if(!song.isValid()){ + return -1; + } + return save(song); } diff --git a/sync/song.cpp b/sync/song.cpp index 5c22512..33e672c 100644 --- a/sync/song.cpp +++ b/sync/song.cpp @@ -1,7 +1,8 @@ #include "song.h" - +#include namespace syncLib{ +static const QStringList ValidSongs = {".mp3", ".wav", ".ogg"}; SongHeader::SongHeader() { this->id = -1; @@ -28,8 +29,11 @@ unsigned int SongHeader::getSize() const{ } bool SongHeader::isValid() const{ - - return id > -1 && !name.isEmpty() && size > 0 && name.endsWith(".mp3"); + bool CheckSongs = false; + for (QString i: ValidSongs){ + CheckSongs = CheckSongs || name.endsWith(i); + } + return id > -1 && !name.isEmpty() && size > 0 && CheckSongs; }