[ai] random mode now really working
This commit is contained in:
@@ -270,29 +270,58 @@ DirectoryNode *DirectoryNode::advanceToMP3(const String *songName)
|
||||
|
||||
// Check if the input is an absolute path (starts with '/') or just a filename
|
||||
bool isAbsolutePath = songName->startsWith("/");
|
||||
// Normalize trailing slash for absolute folder path targets
|
||||
String normalizedPath = *songName;
|
||||
if (isAbsolutePath && normalizedPath.length() > 1 && normalizedPath.endsWith("/"))
|
||||
{
|
||||
normalizedPath.remove(normalizedPath.length() - 1);
|
||||
}
|
||||
// Lowercased copies for case-insensitive comparisons (FAT can uppercase names)
|
||||
String lowTarget = *songName;
|
||||
lowTarget.toLowerCase();
|
||||
String lowNormPath = normalizedPath;
|
||||
lowNormPath.toLowerCase();
|
||||
|
||||
// First, search in the current directory's MP3 files
|
||||
for (size_t i = 0; i < mp3Files.size(); i++)
|
||||
{
|
||||
if (isAbsolutePath)
|
||||
{
|
||||
if (*songName == mp3Files[i])
|
||||
if (mp3Files[i].equalsIgnoreCase(*songName))
|
||||
{
|
||||
setCurrentPlaying(&mp3Files[i]);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
else if (mp3Files[i].endsWith(*songName))
|
||||
else
|
||||
{
|
||||
setCurrentPlaying(&mp3Files[i]);
|
||||
return this;
|
||||
String f = mp3Files[i];
|
||||
f.toLowerCase();
|
||||
if (f.endsWith(lowTarget))
|
||||
{
|
||||
setCurrentPlaying(&mp3Files[i]);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then search in subdirectories
|
||||
for (auto subdir : subdirectories)
|
||||
{
|
||||
if (!isAbsolutePath && subdir->getName() == *songName)
|
||||
// Absolute folder target: match directory by its full path derived from its files
|
||||
if (isAbsolutePath && subdir->mp3Files.size() > 0)
|
||||
{
|
||||
String anyFile = subdir->mp3Files[0];
|
||||
int lastSlash = anyFile.lastIndexOf('/');
|
||||
String subdirPath = (lastSlash >= 0) ? anyFile.substring(0, lastSlash) : String();
|
||||
if (subdirPath.equalsIgnoreCase(normalizedPath))
|
||||
{
|
||||
subdir->advanceToFirstMP3InThisNode();
|
||||
return subdir;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAbsolutePath && subdir->getName().equalsIgnoreCase(*songName))
|
||||
{
|
||||
subdir->advanceToFirstMP3InThisNode();
|
||||
return subdir;
|
||||
@@ -304,18 +333,29 @@ DirectoryNode *DirectoryNode::advanceToMP3(const String *songName)
|
||||
|
||||
if (isAbsolutePath)
|
||||
{
|
||||
if (*songName == subdir->mp3Files[i])
|
||||
if (subdir->mp3Files[i].equalsIgnoreCase(*songName))
|
||||
{
|
||||
subdir->setCurrentPlaying(&subdir->mp3Files[i]);
|
||||
return subdir;
|
||||
}
|
||||
}
|
||||
else if (subdir->mp3Files[i].endsWith(*songName))
|
||||
else
|
||||
{
|
||||
subdir->setCurrentPlaying(&subdir->mp3Files[i]);
|
||||
return subdir;
|
||||
String f = subdir->mp3Files[i];
|
||||
f.toLowerCase();
|
||||
if (f.endsWith(lowTarget))
|
||||
{
|
||||
subdir->setCurrentPlaying(&subdir->mp3Files[i]);
|
||||
return subdir;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Recurse into deeper subdirectories to support nested folders and files
|
||||
DirectoryNode* deeper = subdir->advanceToMP3(songName);
|
||||
if (deeper != nullptr)
|
||||
{
|
||||
return deeper;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, no matching song was found
|
||||
|
||||
Reference in New Issue
Block a user