mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-29 15:22:08 +00:00
- use FileReader for reading the play list.
This commit is contained in:
parent
ab58e4acb0
commit
37dc3211f7
2 changed files with 9 additions and 8 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include "s_playlist.h"
|
#include "s_playlist.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "v_text.h"
|
#include "v_text.h"
|
||||||
|
#include "files.h"
|
||||||
|
|
||||||
FPlayList::FPlayList (const char *path)
|
FPlayList::FPlayList (const char *path)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +54,7 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
{
|
{
|
||||||
FString playlistdir;
|
FString playlistdir;
|
||||||
FString song;
|
FString song;
|
||||||
FILE *file;
|
FileReader fr;
|
||||||
bool first;
|
bool first;
|
||||||
bool pls;
|
bool pls;
|
||||||
int i;
|
int i;
|
||||||
|
@ -61,7 +62,7 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
Songs.Clear();
|
Songs.Clear();
|
||||||
Position = 0;
|
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));
|
Printf ("Could not open " TEXTCOLOR_BOLD "%s" TEXTCOLOR_NORMAL ": %s\n", path, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
@ -70,7 +71,7 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
first = true;
|
first = true;
|
||||||
pls = false;
|
pls = false;
|
||||||
playlistdir = ExtractFilePath(path);
|
playlistdir = ExtractFilePath(path);
|
||||||
while ((song = NextLine(file)).IsNotEmpty())
|
while ((song = NextLine(&fr)).IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
|
@ -129,19 +130,17 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
Songs.Push(song);
|
Songs.Push(song);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (file);
|
|
||||||
|
|
||||||
return Songs.Size() != 0;
|
return Songs.Size() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FString FPlayList::NextLine (FILE *file)
|
FString FPlayList::NextLine (FileReader *file)
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
char *skipper;
|
char *skipper;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (NULL == fgets (buffer, countof(buffer), file))
|
if (NULL == file->Gets (buffer, countof(buffer)))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
for (skipper = buffer; *skipper != 0 && *skipper <= ' '; skipper++)
|
for (skipper = buffer; *skipper != 0 && *skipper <= ' '; skipper++)
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#ifndef __S_PLAYLIST_H__
|
#ifndef __S_PLAYLIST_H__
|
||||||
#define __S_PLAYLIST_H__
|
#define __S_PLAYLIST_H__
|
||||||
|
|
||||||
|
class FileReader;
|
||||||
|
|
||||||
class FPlayList
|
class FPlayList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -51,7 +53,7 @@ public:
|
||||||
const char *GetSong (int position) const;
|
const char *GetSong (int position) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static FString NextLine (FILE *file);
|
static FString NextLine (FileReader *file);
|
||||||
|
|
||||||
unsigned int Position;
|
unsigned int Position;
|
||||||
TArray<FString> Songs;
|
TArray<FString> Songs;
|
||||||
|
|
Loading…
Reference in a new issue