PLSLoader.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "PLSLoader.h"
  2. #include "../nu/AutoChar.h"
  3. #include "../nu/AutoWide.h"
  4. #include <shlwapi.h>
  5. #include <strsafe.h>
  6. class PLSInfo : public ifc_plentryinfo
  7. {
  8. public:
  9. PLSInfo( const wchar_t *_filename, int _entryNum ) : filename( _filename ), entryNum( _entryNum )
  10. {}
  11. const wchar_t *GetExtendedInfo( const wchar_t *parameter )
  12. {
  13. static wchar_t data[ 1024 ];
  14. wchar_t fieldbuf[ 100 ] = { 0 };
  15. StringCchPrintfW( fieldbuf, 100, L"%s%d", parameter, entryNum );
  16. GetPrivateProfileStringW( L"playlist", fieldbuf, L"", data, 1024, filename );
  17. if ( data[ 0 ] )
  18. return data;
  19. else
  20. return 0;
  21. }
  22. private:
  23. RECVS_DISPATCH;
  24. const wchar_t *filename;
  25. int entryNum;
  26. };
  27. #define CBCLASS PLSInfo
  28. START_DISPATCH;
  29. CB( IFC_PLENTRYINFO_GETEXTENDEDINFO, GetExtendedInfo )
  30. END_DISPATCH;
  31. #undef CBCLASS
  32. int PLSLoader::OnFileHelper( ifc_playlistloadercallback *playlist, const wchar_t *trackName, const wchar_t *title, int length, const wchar_t *rootPath, ifc_plentryinfo *extraInfo )
  33. {
  34. if ( length == -1000 )
  35. length = -1;
  36. int ret;
  37. if ( wcsstr( trackName, L"://" ) || PathIsRootW( trackName ) )
  38. {
  39. ret = playlist->OnFile( trackName, title, length, extraInfo );
  40. }
  41. else
  42. {
  43. wchar_t fullPath[ MAX_PATH ] = { 0 };
  44. if ( PathCombineW( fullPath, rootPath, trackName ) )
  45. {
  46. wchar_t canonicalizedPath[ MAX_PATH ] = { 0 };
  47. PathCanonicalizeW( canonicalizedPath, fullPath );
  48. ret = playlist->OnFile( canonicalizedPath, title, length, extraInfo );
  49. }
  50. else
  51. {
  52. ret = ifc_playlistloadercallback::LOAD_CONTINUE;
  53. }
  54. }
  55. return ret;
  56. }
  57. int PLSLoader::Load( const wchar_t *filename, ifc_playlistloadercallback *playlist )
  58. {
  59. int x, numfiles;
  60. int ext = 0;
  61. char fieldbuf[ 100 ] = { 0 };
  62. char fnbuf[ FILENAME_SIZE ] = { 0 };
  63. char tmp[ MAX_PATH ] = { 0 };
  64. wchar_t rootPath[ MAX_PATH ] = { 0 };
  65. const wchar_t *callbackPath = playlist->GetBasePath();
  66. if ( callbackPath )
  67. lstrcpynW( rootPath, callbackPath, MAX_PATH );
  68. else
  69. {
  70. lstrcpynW( rootPath, filename, MAX_PATH );
  71. PathRemoveFileSpecW( rootPath );
  72. }
  73. tmp[ 0 ] = (char)rootPath[ 0 ];
  74. tmp[ 1 ] = (char)rootPath[ 1 ];
  75. tmp[ 2 ] = (char)rootPath[ 2 ];
  76. AutoChar fn( filename );
  77. numfiles = GetPrivateProfileIntA( "playlist", "NumberOfEntries", 0, fn );
  78. ext = GetPrivateProfileIntA( "playlist", "Version", 1, fn );
  79. if ( numfiles == 0 )
  80. return IFC_PLAYLISTLOADER_FAILED;
  81. for ( x = 1; x <= numfiles; x++ )
  82. {
  83. int flen = -1;
  84. char ftitle[ FILETITLE_SIZE ] = "";
  85. StringCchPrintfA( fieldbuf, 100, "File%d", x );
  86. GetPrivateProfileStringA( "playlist", fieldbuf, "", fnbuf, FILENAME_SIZE, fn );
  87. if ( ext )
  88. {
  89. StringCchPrintfA( fieldbuf, 100, "Title%d", x );
  90. GetPrivateProfileStringA( "playlist", fieldbuf, "", ftitle, FILETITLE_SIZE, fn );
  91. StringCchPrintfA( fieldbuf, 100, "Length%d", x );
  92. flen = GetPrivateProfileIntA( "playlist", fieldbuf, -1, fn );
  93. }
  94. if ( *fnbuf )
  95. {
  96. char *p;
  97. char buf[ 512 ] = { 0 };
  98. p = fnbuf;
  99. if ( strncmp( p, "\\\\", 2 ) && strncmp( p + 1, ":\\", 2 ) && !strstr( p, ":/" ) )
  100. {
  101. if ( p[ 0 ] == '\\' )
  102. {
  103. buf[ 0 ] = tmp[ 0 ];
  104. buf[ 1 ] = tmp[ 1 ];
  105. lstrcpynA( buf + 2, p, 510 );
  106. buf[ 511 ] = 0;
  107. p = buf;
  108. }
  109. }
  110. PLSInfo info( filename, x );
  111. int ret;
  112. if ( ftitle[ 0 ] )
  113. {
  114. ret = OnFileHelper( playlist, AutoWide( p ), AutoWide( ftitle ), flen * 1000, rootPath, &info );
  115. }
  116. else
  117. {
  118. ret = OnFileHelper( playlist, AutoWide( p ), 0, -1, rootPath, &info );
  119. }
  120. if ( ret != ifc_playlistloadercallback::LOAD_CONTINUE )
  121. {
  122. break;
  123. }
  124. }
  125. }
  126. return IFC_PLAYLISTLOADER_SUCCESS;
  127. }
  128. #define CBCLASS PLSLoader
  129. START_DISPATCH;
  130. CB( IFC_PLAYLISTLOADER_LOAD, Load )
  131. END_DISPATCH;
  132. #undef CBCLASS