Skip to content

Commit

Permalink
Add M3U file support for automatic disc switching
Browse files Browse the repository at this point in the history
  • Loading branch information
JosJuice committed Jan 4, 2019
1 parent 63c9831 commit 0c62292
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
71 changes: 59 additions & 12 deletions Source/Core/Core/Boot/Boot.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@


#include "Core/Boot/Boot.h" #include "Core/Boot/Boot.h"


#ifdef _MSC_VER
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#define HAS_STD_FILESYSTEM
#endif

#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cstring> #include <cstring>
Expand Down Expand Up @@ -54,10 +60,52 @@
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"


std::vector<std::string> ReadM3UFile(const std::string& path) std::vector<std::string> ReadM3UFile(const std::string& m3u_path, const std::string& folder_path)
{ {
// TODO #ifndef HAS_STD_FILESYSTEM
return {}; ASSERT(folder_path.back() == '/');
#endif

std::vector<std::string> result;
std::vector<std::string> nonexistent;

std::ifstream s;
File::OpenFStream(s, m3u_path, std::ios_base::in);

std::string line;
while (std::getline(s, line))
{
if (StringBeginsWith(line, u8"\uFEFF"))
{
WARN_LOG(BOOT, "UTF-8 BOM in file: %s", m3u_path.c_str());
line.erase(0, 3);
}

if (!line.empty() && line.front() != '#') // Comments start with #
{
#ifdef HAS_STD_FILESYSTEM
const fs::path path_line = fs::u8path(line);
const std::string path_to_add =
path_line.is_relative() ? fs::u8path(folder_path).append(path_line).u8string() : line;
#else
const std::string path_to_add = line.front() != '/' ? folder_path + line : line;
#endif

(File::Exists(path_to_add) ? result : nonexistent).push_back(path_to_add);
}
}

if (!nonexistent.empty())
{
PanicAlertT("Files specified in the M3U file \"%s\" were not found:\n%s", m3u_path.c_str(),
JoinStrings(nonexistent, "\n").c_str());
return {};
}

if (result.empty())
PanicAlertT("No paths found in the M3U file \"%s\"", m3u_path.c_str());

return result;
} }


BootParameters::BootParameters(Parameters&& parameters_, BootParameters::BootParameters(Parameters&& parameters_,
Expand Down Expand Up @@ -88,20 +136,19 @@ BootParameters::GenerateFromFile(std::vector<std::string> paths,
return {}; return {};
} }


std::string folder_path;
std::string extension; std::string extension;
SplitPath(paths.front(), nullptr, nullptr, &extension); SplitPath(paths.front(), &folder_path, nullptr, &extension);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);


if (extension == ".m3u") if (extension == ".m3u" || extension == ".m3u8")
{ {
std::vector<std::string> new_paths = ReadM3UFile(paths.front()); paths = ReadM3UFile(paths.front(), folder_path);
if (!new_paths.empty()) if (paths.empty())
{ return {};
paths = new_paths;


SplitPath(paths.front(), nullptr, nullptr, &extension); SplitPath(paths.front(), nullptr, nullptr, &extension);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
}
} }


const std::string path = paths.front(); const std::string path = paths.front();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Info.plist.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string>gcm</string> <string>gcm</string>
<string>gcz</string> <string>gcz</string>
<string>iso</string> <string>iso</string>
<string>m3u</string>
<string>tgc</string> <string>tgc</string>
<string>wad</string> <string>wad</string>
<string>wbfs</string> <string>wbfs</string>
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/MainWindow.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ QStringList MainWindow::PromptFileNames()
QStringList paths = QFileDialog::getOpenFileNames( QStringList paths = QFileDialog::getOpenFileNames(
this, tr("Select a File"), this, tr("Select a File"),
settings.value(QStringLiteral("mainwindow/lastdir"), QStringLiteral("")).toString(), settings.value(QStringLiteral("mainwindow/lastdir"), QStringLiteral("")).toString(),
tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad *.dff);;" tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad *.dff *.m3u);;"
"All Files (*)")); "All Files (*)"));


if (!paths.isEmpty()) if (!paths.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Settings/PathPane.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void PathPane::BrowseDefaultGame()
{ {
QString file = QDir::toNativeSeparators(QFileDialog::getOpenFileName( QString file = QDir::toNativeSeparators(QFileDialog::getOpenFileName(
this, tr("Select a Game"), Settings::Instance().GetDefaultGame(), this, tr("Select a Game"), Settings::Instance().GetDefaultGame(),
tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad);;" tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad *.m3u);;"
"All Files (*)"))); "All Files (*)")));


if (!file.isEmpty()) if (!file.isEmpty())
Expand Down

0 comments on commit 0c62292

Please sign in to comment.