diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/Library/ml_disc/M3UWriter.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/Plugins/Library/ml_disc/M3UWriter.cpp')
-rw-r--r-- | Src/Plugins/Library/ml_disc/M3UWriter.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Src/Plugins/Library/ml_disc/M3UWriter.cpp b/Src/Plugins/Library/ml_disc/M3UWriter.cpp new file mode 100644 index 00000000..d4ec2a13 --- /dev/null +++ b/Src/Plugins/Library/ml_disc/M3UWriter.cpp @@ -0,0 +1,91 @@ +#include "M3UWriter.h" +#include <shlwapi.h> + +static void MakeRelativePathName( const char *filename, char *outFile, const char *path ) +{ + char outPath[ MAX_PATH ] = { 0 }; + + int common = PathCommonPrefixA( path, filename, outPath ); + if ( common && common == lstrlenA( path ) ) + { + PathAddBackslashA( outPath ); + const char *p = filename + lstrlenA( outPath ); + lstrcpyA( outFile, p ); + } + else if ( !PathIsUNCA( filename ) && PathIsSameRootA( filename, path ) ) + { + lstrcpyA( outFile, filename + 2 ); + } +} + +M3UWriter::M3UWriter() +{ + memset( basePath, 0, sizeof( basePath ) ); +} + +M3UWriter::~M3UWriter() +{ + Close(); +} + +int M3UWriter::Open( char *filename, int extendedMode ) +{ + fp = fopen( filename, "wt" ); + if ( !fp ) + return 0; + + if ( extendedMode ) + fprintf( fp, "#EXTM3U\n" ); + + extended = extendedMode; + + lstrcpynA( basePath, filename, MAX_PATH ); + PathRemoveFileSpecA( basePath ); + + return 1; +} + +int M3UWriter::Open( FILE *_fp, char *filename, int extendedMode ) +{ + fp = _fp; + if ( !fp ) + return 0; + + if ( extendedMode ) + fprintf( fp, "#EXTM3U\n" ); + + extended = extendedMode; + + lstrcpynA( basePath, filename, MAX_PATH ); + PathRemoveFileSpecA( basePath ); + + return 1; +} + +void M3UWriter::SetFilename( char *filename ) +{ + //char temp[ MAX_PATH ] = { 0 }; + //MakeRelativePathName( filename, temp, basePath ); + fprintf( fp, "%s\n", filename ); +} + +void M3UWriter::SetExtended( char *filename, char *title, int length ) +{ + if ( !extended ) + SetFilename( filename ); + else + { + //char temp[ MAX_PATH ] = { 0 }; + //MakeRelativePathName( filename, temp, basePath ); + fprintf( fp, "#EXTINF:%d,%s\n%s\n", length, title, filename ); + } +} + +void M3UWriter::Close() +{ + if ( fp != NULL ) + { + fclose( fp ); + fp = NULL; + } +}
\ No newline at end of file |