- use FileReader for reading the play list.

This commit is contained in:
Christoph Oelckers 2017-12-02 12:02:36 +01:00
parent ab58e4acb0
commit 37dc3211f7
2 changed files with 9 additions and 8 deletions

View File

@ -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++)

View File

@ -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<FString> Songs;