diff --git a/src/helpers.cpp b/src/helpers.cpp index 9279ac15..0baa55b9 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -162,6 +162,22 @@ void WindowTitle(const string &status) printf("\033]0;%s\7",status.c_str()); } +void EscapeUnallowedChars(string &s) +{ + const string unallowed_chars = "\"*/:<>?\\|"; + for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++) + { + for (int i = 0; i < s.length(); i++) + { + if (s[i] == *it) + { + s.erase(s.begin()+i); + i--; + } + } + } +} + string FindSharedDir(const string &one, const string &two) { if (one == two) diff --git a/src/helpers.h b/src/helpers.h index 0559d1d0..d9297d41 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -46,6 +46,7 @@ void UpdateSongList(Menu *); bool Keypressed(int, const int *); void WindowTitle(const string &); +void EscapeUnallowedChars(string &); string FindSharedDir(const string &, const string &); string TotalPlaylistLength(); diff --git a/src/lyrics.cpp b/src/lyrics.cpp index ca04317b..4ae0f64a 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -19,12 +19,14 @@ ***************************************************************************/ #include +#include "helpers.h" #include "lyrics.h" #include "settings.h" #include "song.h" extern ncmpcpp_config Config; +const string artists_folder = home_folder + "/" + ".ncmpcpp/artists"; const string lyrics_folder = home_folder + "/" + ".lyrics"; #ifdef HAVE_CURL_CURL_H @@ -68,9 +70,12 @@ void * GetArtistInfo(void *ptr) string artist = *strptr; delete strptr; - const string filename = artist + ".txt"; - const string fullpath = lyrics_folder + "/" + filename; - mkdir(lyrics_folder.c_str(), 0755); + string filename = artist + ".txt"; + transform(filename.begin(), filename.end(), filename.begin(), tolower); + EscapeUnallowedChars(filename); + + const string fullpath = artists_folder + "/" + filename; + mkdir(artists_folder.c_str(), 0755); string *result = new string(); std::ifstream input(fullpath.c_str()); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index a3d13e6b..bdb3ec1c 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -139,6 +139,7 @@ const string message_part_of_songs_added = "Only part of requested songs' list a int main(int argc, char *argv[]) { + CreateConfigDir(); DefaultConfiguration(Config); DefaultKeys(Key); ReadConfiguration(Config); diff --git a/src/settings.cpp b/src/settings.cpp index c11afc5e..ae7b2c8a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -18,13 +18,19 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include #include "settings.h" -const string config_file = home_folder + "/.ncmpcpp/config"; -const string keys_config_file = home_folder + "/.ncmpcpp/keys"; +const string config_file = config_dir + "config"; +const string keys_config_file = config_dir + "keys"; using std::ifstream; +void CreateConfigDir() +{ + mkdir(config_dir.c_str(), 0755); +} + void DefaultKeys(ncmpcpp_keys &keys) { keys.Up[0] = KEY_UP; diff --git a/src/settings.h b/src/settings.h index 7eabe3f3..1aeabf5c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -25,6 +25,7 @@ #include "ncmpcpp.h" +const string config_dir = home_folder + "/.ncmpcpp/"; const int null_key = 0x0fffffff; struct ncmpcpp_keys @@ -146,6 +147,7 @@ struct ncmpcpp_config int message_delay_time; }; +void CreateConfigDir(); void DefaultKeys(ncmpcpp_keys &); void DefaultConfiguration(ncmpcpp_config &); void ReadKeys(ncmpcpp_keys &); diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 064e3f47..0448e30e 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -222,16 +222,8 @@ namespace string GenerateFilename(const Song &s, string &pattern) { - const string unallowed_chars = "\"*/:<>?\\|"; string result = Window::OmitBBCodes(DisplaySong(s, &pattern)); - for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++) - { - for (int i = 0; i < result.length(); i++) - { - if (result[i] == *it) - result.erase(result.begin()+i); - } - } + EscapeUnallowedChars(result); return result; }