diff --git a/src/s_playlist.cpp b/src/s_playlist.cpp index e1b0fd5b61..315a2ac763 100644 --- a/src/s_playlist.cpp +++ b/src/s_playlist.cpp @@ -39,6 +39,7 @@ #include "s_playlist.h" #include "templates.h" #include "v_text.h" +#include "files.h" FPlayList::FPlayList (const char *path) { @@ -53,7 +54,7 @@ bool FPlayList::ChangeList (const char *path) { FString playlistdir; FString song; - FILE *file; + FileReader fr; bool first; bool pls; int i; @@ -61,7 +62,7 @@ bool FPlayList::ChangeList (const char *path) Songs.Clear(); Position = 0; - if ( (file = fopen (path, "rb")) == NULL) + if (!fr.Open(path)) { Printf ("Could not open " TEXTCOLOR_BOLD "%s" TEXTCOLOR_NORMAL ": %s\n", path, strerror(errno)); return false; @@ -70,7 +71,7 @@ bool FPlayList::ChangeList (const char *path) first = true; pls = false; playlistdir = ExtractFilePath(path); - while ((song = NextLine(file)).IsNotEmpty()) + while ((song = NextLine(&fr)).IsNotEmpty()) { if (first) { @@ -129,19 +130,17 @@ bool FPlayList::ChangeList (const char *path) Songs.Push(song); } } - fclose (file); - return Songs.Size() != 0; } -FString FPlayList::NextLine (FILE *file) +FString FPlayList::NextLine (FileReader *file) { char buffer[512]; char *skipper; do { - if (NULL == fgets (buffer, countof(buffer), file)) + if (NULL == file->Gets (buffer, countof(buffer))) return ""; for (skipper = buffer; *skipper != 0 && *skipper <= ' '; skipper++) diff --git a/src/s_playlist.h b/src/s_playlist.h index 74c06f8578..859f0bce41 100644 --- a/src/s_playlist.h +++ b/src/s_playlist.h @@ -34,6 +34,8 @@ #ifndef __S_PLAYLIST_H__ #define __S_PLAYLIST_H__ +class FileReader; + class FPlayList { public: @@ -51,7 +53,7 @@ public: const char *GetSong (int position) const; private: - static FString NextLine (FILE *file); + static FString NextLine (FileReader *file); unsigned int Position; TArray Songs;