Skip to content

Commit

Permalink
libretro: support relative paths in m3u playlists.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
  • Loading branch information
audetto committed Nov 28, 2021
1 parent e08363f commit 97c3472
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 2 additions & 0 deletions source/frontends/libretro/CMakeLists.txt
Expand Up @@ -35,6 +35,8 @@ add_library(applewin_libretro SHARED
${HEADER_FILES}
)

target_compile_features(applewin_libretro PUBLIC cxx_std_17)

target_include_directories(applewin_libretro PRIVATE
libretro-common/include
)
Expand Down
19 changes: 11 additions & 8 deletions source/frontends/libretro/diskcontrol.cpp
Expand Up @@ -33,21 +33,28 @@ namespace ra2

bool DiskControl::insertPlaylist(const std::string & filename)
{
std::ifstream playlist(filename);
const std::filesystem::path path(filename);
std::ifstream playlist(path);
if (!playlist)
{
return false;
}

myImages.clear();
const std::filesystem::path parent = path.parent_path();

std::string line;
while (std::getline(playlist, line))
{
// should we trim initial spaces?
if (!line.empty() && line[0] != '#')
{
myImages.push_back(line);
std::filesystem::path image(line);
if (image.is_relative())
{
image = parent / image;
}
myImages.push_back(image);
}
}

Expand Down Expand Up @@ -227,12 +234,8 @@ namespace ra2
{
if (index < myImages.size())
{
size_t pos = myImages[index].rfind('/');
if (pos == std::string::npos)
{
pos = 0;
}
strncpy(label, myImages[index].c_str() + pos + 1, len);
const std::string filename = myImages[index].filename();
strncpy(label, filename.c_str(), len);
label[len - 1] = 0;
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion source/frontends/libretro/diskcontrol.h
@@ -1,5 +1,6 @@
#include <vector>
#include <string>
#include <filesystem>

namespace ra2
{
Expand Down Expand Up @@ -31,7 +32,7 @@ namespace ra2
static void setInitialPath(unsigned index, const char *path);

private:
std::vector<std::string> myImages;
std::vector<std::filesystem::path> myImages;

bool myEjected;
size_t myIndex;
Expand Down
2 changes: 0 additions & 2 deletions source/frontends/libretro/environment.cpp
Expand Up @@ -25,8 +25,6 @@ namespace ra2
retro_audio_sample_t audio_cb;
retro_audio_sample_batch_t audio_batch_cb;

std::string retro_base_directory;

void display_message(const std::string & message)
{
retro_message rmsg;
Expand Down
2 changes: 0 additions & 2 deletions source/frontends/libretro/environment.h
Expand Up @@ -15,8 +15,6 @@ namespace ra2
extern retro_audio_sample_t audio_cb;
extern retro_audio_sample_batch_t audio_batch_cb;

extern std::string retro_base_directory;

#define MAX_PADS 1

void display_message(const std::string & message);
Expand Down
5 changes: 0 additions & 5 deletions source/frontends/libretro/libretro.cpp
Expand Up @@ -106,11 +106,6 @@ namespace
void retro_init(void)
{
ra2::log_cb(RETRO_LOG_INFO, "RA2: %s\n", __FUNCTION__);
const char *dir = NULL;
if (ra2::environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
{
ra2::retro_base_directory = dir;
}
}

void retro_deinit(void)
Expand Down

0 comments on commit 97c3472

Please sign in to comment.