@@ -1236,6 +1236,37 @@ bool VMManager::HasBootedELF()
12361236 return s_current_crc != 0 && s_elf_executed;
12371237}
12381238
1239+ static std::string s_current_m3u_playlist_source;
1240+ static std::vector<std::string> s_current_m3u_playlist_entries;
1241+ static int s_current_m3u_playlist_index = -1 ;
1242+
1243+ static void ClearM3UPlaylist ()
1244+ {
1245+ s_current_m3u_playlist_source.clear ();
1246+ s_current_m3u_playlist_entries.clear ();
1247+ s_current_m3u_playlist_index = -1 ;
1248+ }
1249+
1250+ static void SetM3UPlaylist (const std::string& m3u_path, std::vector<std::string> entries, int current_index)
1251+ {
1252+ s_current_m3u_playlist_source = m3u_path;
1253+ s_current_m3u_playlist_entries = std::move (entries);
1254+ s_current_m3u_playlist_index = current_index;
1255+ }
1256+
1257+ static void UpdateM3UPlaylistCurrentIndex (const std::string& current_disc_path)
1258+ {
1259+ s_current_m3u_playlist_index = -1 ;
1260+ for (size_t i = 0 ; i < s_current_m3u_playlist_entries.size (); ++i)
1261+ {
1262+ if (s_current_m3u_playlist_entries[i] == current_disc_path)
1263+ {
1264+ s_current_m3u_playlist_index = static_cast <int >(i);
1265+ return ;
1266+ }
1267+ }
1268+ }
1269+
12391270static std::vector<std::string> ParseM3UPlaylist (const std::string& m3u_path)
12401271{
12411272 std::vector<std::string> disc_paths;
@@ -1273,14 +1304,15 @@ static std::vector<std::string> ParseM3UPlaylist(const std::string& m3u_path)
12731304
12741305bool VMManager::AutoDetectSource (const std::string& filename, Error* error)
12751306{
1307+ ClearM3UPlaylist ();
12761308 if (!filename.empty ())
12771309 {
12781310 if (!FileSystem::FileExists (filename.c_str ()))
12791311 {
12801312 Error::SetStringFmt (error, TRANSLATE_FS (" VMManager" , " Requested filename '{}' does not exist." ), filename);
12811313 return false ;
12821314 }
1283-
1315+
12841316 if (IsGSDumpFileName (filename))
12851317 {
12861318 CDVDsys_ChangeSource (CDVD_SourceType::NoDisc);
@@ -1313,8 +1345,8 @@ bool VMManager::AutoDetectSource(const std::string& filename, Error* error)
13131345 return false ;
13141346 }
13151347
1316- // For now, just load the first disc
1317- CDVDsys_SetFile (CDVD_SourceType::Iso, disc_paths [0 ]);
1348+ SetM3UPlaylist (filename, disc_paths, 0 );
1349+ CDVDsys_SetFile (CDVD_SourceType::Iso, s_current_m3u_playlist_entries [0 ]);
13181350 CDVDsys_ChangeSource (CDVD_SourceType::Iso);
13191351 return true ;
13201352 }
@@ -2367,6 +2399,28 @@ bool VMManager::ChangeDisc(CDVD_SourceType source, std::string path)
23672399 const CDVD_SourceType old_type = CDVDsys_GetSourceType ();
23682400 const std::string old_path (CDVDsys_GetFile (old_type));
23692401
2402+ if (source == CDVD_SourceType::Iso && StringUtil::EndsWithNoCase (path, " .m3u" ))
2403+ {
2404+ const std::vector<std::string> disc_paths = ParseM3UPlaylist (path);
2405+ if (disc_paths.empty ())
2406+ {
2407+ return false ;
2408+ }
2409+
2410+ SetM3UPlaylist (path, disc_paths, 0 );
2411+ path = s_current_m3u_playlist_entries[0 ];
2412+ }
2413+ else if (source != CDVD_SourceType::Iso)
2414+ {
2415+ ClearM3UPlaylist ();
2416+ }
2417+ else if (!path.empty ())
2418+ {
2419+ UpdateM3UPlaylistCurrentIndex (path);
2420+ if (s_current_m3u_playlist_index < 0 )
2421+ ClearM3UPlaylist ();
2422+ }
2423+
23702424 CDVDsys_ChangeSource (source);
23712425 if (!path.empty ())
23722426 CDVDsys_SetFile (source, path);
@@ -2421,6 +2475,16 @@ bool VMManager::ChangeDisc(CDVD_SourceType source, std::string path)
24212475 return result;
24222476}
24232477
2478+ const std::vector<std::string>& VMManager::GetM3UPlaylistEntries ()
2479+ {
2480+ return s_current_m3u_playlist_entries;
2481+ }
2482+
2483+ int VMManager::GetM3UPlaylistCurrentIndex ()
2484+ {
2485+ return s_current_m3u_playlist_index;
2486+ }
2487+
24242488bool VMManager::SetELFOverride (std::string path)
24252489{
24262490 if (!HasValidVM () || (!path.empty () && !FileSystem::FileExists (path.c_str ())))
0 commit comments