aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_disc/M3UWriter.cpp
blob: d4ec2a13bc13928193e9496590a0a38806af443b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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;
	}
}