mirror of
https://github.com/Team-Resurgent/XBMC4Xbox.git
synced 2026-08-15 11:18:13 -07:00
If ever adding the XBMC4Xbox source to GitHub use "git add -f -A" or it wont add all the files.
165 lines
4.5 KiB
C++
165 lines
4.5 KiB
C++
/*
|
|
* Copyright (C) 2005-2013 Team XBMC
|
|
* http://xbmc.org
|
|
*
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This Program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with XBMC; see the file COPYING. If not, see
|
|
* <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#include "SndtrkDirectory.h"
|
|
#include "xbox/IoSupport.h"
|
|
#include "FileItem.h"
|
|
|
|
SOUNDTRACK datastorage; //created a vector of the XSOUNDTRACK_DATA class to keep track of each album
|
|
|
|
using namespace XFILE;
|
|
|
|
CSndtrkDirectory::CSndtrkDirectory(void)
|
|
{}
|
|
|
|
CSndtrkDirectory::~CSndtrkDirectory(void)
|
|
{}
|
|
|
|
|
|
bool CSndtrkDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
|
|
{
|
|
CStdString strRoot = strPath;
|
|
if (IsAlone(strRoot))
|
|
{
|
|
// Add each user provided soundtrack to the soundtrack vector
|
|
// Took code from samples in XDK
|
|
XSOUNDTRACK_DATA stData;
|
|
HANDLE hSoundtrack = XFindFirstSoundtrack( &stData );
|
|
if ( INVALID_HANDLE_VALUE != hSoundtrack )
|
|
{
|
|
do
|
|
{
|
|
// Ignore empty soundtracks && parent directories
|
|
if ( stData.uSongCount > 0 && strRoot != "..")
|
|
{
|
|
CSoundtrack stInfo;
|
|
stInfo.uSoundtrackId = stData.uSoundtrackId;
|
|
stInfo.uSongCount = stData.uSongCount;
|
|
wcscpy(stInfo.strName, stData.szName );
|
|
|
|
ISOUNDTRACK it=datastorage.find(stData.uSoundtrackId);
|
|
if (it==datastorage.end())
|
|
datastorage.insert(SOUNDTRACK_PAIR(stInfo.uSoundtrackId, stInfo));
|
|
else
|
|
it->second=stInfo;
|
|
|
|
CFileItemPtr pItem(new CFileItem(stData.szName));
|
|
pItem->SetLabelPreformated(true);
|
|
char tmpvar[4];
|
|
itoa (stData.uSoundtrackId, tmpvar, 10);
|
|
pItem->SetPath(strRoot + tmpvar);
|
|
pItem->m_bIsFolder = true;
|
|
items.Add(pItem);
|
|
}
|
|
}
|
|
while ( XFindNextSoundtrack( hSoundtrack, &stData ) );
|
|
|
|
XFindClose(hSoundtrack);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
char *ptr = strstr(strRoot, "//");
|
|
ptr += 2;
|
|
int m_iconvert = atoi(ptr); //convert from char back to int to compare to data
|
|
|
|
ISOUNDTRACK it=datastorage.find(m_iconvert);
|
|
if (it == datastorage.end())
|
|
return false;
|
|
|
|
CSoundtrack stInfo = it->second;
|
|
for ( UINT i = 0; i < stInfo.uSongCount; ++i )
|
|
{
|
|
DWORD dwSongId;
|
|
DWORD dwSongLength;
|
|
WCHAR strSong[64];
|
|
if ( XGetSoundtrackSongInfo( stInfo.uSoundtrackId, i, &dwSongId,
|
|
&dwSongLength, strSong, MAX_SONG_NAME ) )
|
|
{
|
|
// Add it to the list
|
|
CFileItemPtr pItem(new CFileItem(strSong));
|
|
CStdString strPath("E:\\TDATA\\fffe0000\\music\\");
|
|
char tmpvar[16];
|
|
*tmpvar = NULL;
|
|
sprintf(tmpvar, "%04x", stInfo.uSoundtrackId);
|
|
strPath += tmpvar;
|
|
strPath += "\\";
|
|
*tmpvar = NULL;
|
|
sprintf(tmpvar, "%08x", dwSongId);
|
|
strPath += tmpvar;
|
|
strPath += ".wma";
|
|
pItem->SetPath(strPath);
|
|
pItem->m_bIsFolder = false;
|
|
items.Add(pItem);
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool CSndtrkDirectory::IsAlone(const CStdString& strPath)
|
|
{
|
|
return (strcmp("soundtrack://", strPath) == 0);
|
|
}
|
|
|
|
bool CSndtrkDirectory::FindTrackName(const CStdString& strPath, char *NameOfSong)
|
|
{
|
|
char* ptr = strstr(strPath.c_str(), "E:\\TDATA\\fffe0000\\music\\");
|
|
if (ptr == NULL) return false;
|
|
ptr += strlen("E:\\TDATA\\fffe0000\\music\\");
|
|
char album[5];
|
|
int x = 0;
|
|
for (x = 0;x < 4;x++)
|
|
{
|
|
album[x] = *ptr;
|
|
ptr += 1;
|
|
}
|
|
album[4] = '\0';
|
|
ptr += 1;
|
|
char trackno[9];
|
|
for (x = 0;x < 8;x++)
|
|
{
|
|
trackno[x] = *ptr;
|
|
ptr += 1;
|
|
}
|
|
trackno[8] = '\0';
|
|
int AlbumID, SongID;
|
|
sscanf(album, "%x", &AlbumID);
|
|
sscanf(trackno, "%x", &SongID);
|
|
x = 0;
|
|
bool test = true;
|
|
while (test == true)
|
|
{
|
|
DWORD dwSongId;
|
|
DWORD dwSongLength;
|
|
WCHAR Songname[64];
|
|
if ( XGetSoundtrackSongInfo( AlbumID, x, &dwSongId, &dwSongLength, Songname, MAX_SONG_NAME ) == false)
|
|
test = false;
|
|
if (dwSongId == SongID)
|
|
{
|
|
wcstombs(NameOfSong, Songname, 64);
|
|
return true;
|
|
}
|
|
x++;
|
|
}
|
|
return false;
|
|
}
|
|
|