M3UWriter.cpp 696 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "M3UWriter.h"
  2. #include "../nu/AutoChar.h"
  3. M3UWriter::~M3UWriter()
  4. {
  5. Close();
  6. }
  7. int M3UWriter::Open( const wchar_t *filename )
  8. {
  9. if ( fp != NULL )
  10. return 0;
  11. fp = _wfopen( filename, L"wt" );
  12. if ( !fp )
  13. return 0;
  14. fprintf( fp, "#EXTM3U\n" );
  15. return 1;
  16. }
  17. void M3UWriter::Write( const wchar_t *filename )
  18. {
  19. if ( fp != NULL )
  20. fprintf( fp, "%s\n", (char *)AutoChar( filename ) );
  21. }
  22. void M3UWriter::Write( const wchar_t *filename, const wchar_t *title, int length )
  23. {
  24. if ( fp != NULL )
  25. fprintf( fp, "#EXTINF:%d,%s\n%s\n", length, (char *)AutoChar( title ), (char *)AutoChar( filename ) );
  26. }
  27. void M3UWriter::Close()
  28. {
  29. if ( fp != NULL )
  30. {
  31. fclose( fp );
  32. fp = NULL;
  33. }
  34. }