1
0

M3UWriter.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "M3UWriter.h"
  2. #include <shlwapi.h>
  3. static void MakeRelativePathName( const char *filename, char *outFile, const char *path )
  4. {
  5. char outPath[ MAX_PATH ] = { 0 };
  6. int common = PathCommonPrefixA( path, filename, outPath );
  7. if ( common && common == lstrlenA( path ) )
  8. {
  9. PathAddBackslashA( outPath );
  10. const char *p = filename + lstrlenA( outPath );
  11. lstrcpyA( outFile, p );
  12. }
  13. else if ( !PathIsUNCA( filename ) && PathIsSameRootA( filename, path ) )
  14. {
  15. lstrcpyA( outFile, filename + 2 );
  16. }
  17. }
  18. M3UWriter::M3UWriter()
  19. {
  20. memset( basePath, 0, sizeof( basePath ) );
  21. }
  22. M3UWriter::~M3UWriter()
  23. {
  24. Close();
  25. }
  26. int M3UWriter::Open( char *filename, int extendedMode )
  27. {
  28. fp = fopen( filename, "wt" );
  29. if ( !fp )
  30. return 0;
  31. if ( extendedMode )
  32. fprintf( fp, "#EXTM3U\n" );
  33. extended = extendedMode;
  34. lstrcpynA( basePath, filename, MAX_PATH );
  35. PathRemoveFileSpecA( basePath );
  36. return 1;
  37. }
  38. int M3UWriter::Open( FILE *_fp, char *filename, int extendedMode )
  39. {
  40. fp = _fp;
  41. if ( !fp )
  42. return 0;
  43. if ( extendedMode )
  44. fprintf( fp, "#EXTM3U\n" );
  45. extended = extendedMode;
  46. lstrcpynA( basePath, filename, MAX_PATH );
  47. PathRemoveFileSpecA( basePath );
  48. return 1;
  49. }
  50. void M3UWriter::SetFilename( char *filename )
  51. {
  52. //char temp[ MAX_PATH ] = { 0 };
  53. //MakeRelativePathName( filename, temp, basePath );
  54. fprintf( fp, "%s\n", filename );
  55. }
  56. void M3UWriter::SetExtended( char *filename, char *title, int length )
  57. {
  58. if ( !extended )
  59. SetFilename( filename );
  60. else
  61. {
  62. //char temp[ MAX_PATH ] = { 0 };
  63. //MakeRelativePathName( filename, temp, basePath );
  64. fprintf( fp, "#EXTINF:%d,%s\n%s\n", length, title, filename );
  65. }
  66. }
  67. void M3UWriter::Close()
  68. {
  69. if ( fp != NULL )
  70. {
  71. fclose( fp );
  72. fp = NULL;
  73. }
  74. }