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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
#include "main.h"
#include "WinampPlaylist.h"
#include "../nu/AutoChar.h"
#include "../nu/AutoWide.h"
#include "api.h"
WinampDirectoryLoad::WinampDirectoryLoad( bool _forceRecurse, char *_exts ) : forceRecurse( _forceRecurse ), exts( _exts ), needsFree( false ), listStart( 0 )
{
listStart = PlayList_getlength();
if ( !exts )
{
exts = in_getextlist();
needsFree = false;
}
}
WinampDirectoryLoad::~WinampDirectoryLoad()
{
if ( config_rofiob & 1 )
PlayList_sort( 2, listStart );
if ( needsFree )
GlobalFree( (HGLOBAL)exts );
}
WinampPlaylist::WinampPlaylist( const wchar_t *_base, bool _loadDirectories ) : base( _base ), terminateOnEnd( false ), loadDirectories( _loadDirectories )
{}
bool WhitelistOK( wchar_t *url )
{
bool validurl = false;
wchar_t *p = url;
// Whitelist the url...
if ( *p == L'a' ) p++; // get passed the ad-fullscreen blob.
if ( *p )
{
wchar_t *whitelist;
whitelist = wcsstr( p, L"http://www.winamp.com/" );
if ( whitelist && whitelist == p )
{
validurl = true;
}
if ( validurl == false ) // Check for javscript command
{
whitelist = wcsstr( p, L"javascript:onCommand(" );
if ( whitelist && whitelist == p )
{
wchar_t *semi = wcsstr( whitelist, L";" );
if ( semi )
{
semi++;
if ( *semi )
*semi = 0;
}
validurl = true;
}
}
}
return validurl;
}
WinampPlaylist::~WinampPlaylist()
{
//if ( terminateOnEnd )
//{
//}
}
void WinampPlaylist::OnFile(const wchar_t *filename, const wchar_t *title, int lengthInMs, ifc_plentryinfo *info)
{
BOOL hidden = false;
int playcount = 0;
unsigned long starttime = 0, endtime = 0;
wchar_t fcurtain[FILENAME_SIZE] = L"";
wchar_t fileExt[ 10 ] = L"";
//wchar_t fbrowser[FILENAME_SIZE] = L"";
if (LoadPlaylist(filename, 1, 0) == 0) //(playlistManager->Load(filename, this) == PLAYLISTMANAGER_SUCCESS) // if it's another playlist file, load recursively
return ;
// check for trailing backslash
/*
if (filename[lstrlenW(filename)] == '\\')
{
WinampDirectoryLoad dir(true);
playlistManager->LoadDirectory(filename, this, &dir);
return;
}
*/
// see if it's a directory
if ( loadDirectories && !PathIsURLW( filename ) && !PathIsNetworkPathW( filename ) )
{
HANDLE h;
WIN32_FIND_DATAW d;
h = FindFirstFileW( filename, &d );
if ( h != INVALID_HANDLE_VALUE )
{
FindClose( h );
if ( d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
WinampDirectoryLoad dir( true );
playlistManager->LoadDirectory( filename, this, &dir );
return;
}
}
}
if (info)
{
const wchar_t *ext = 0;
ext = info->GetExtendedInfo(L"Repeat");
if (ext) playcount = _wtoi(ext);
ext = info->GetExtendedInfo(L"Start");
if (ext) starttime = _wtoi(ext);
ext = info->GetExtendedInfo(L"End");
if (ext) endtime = _wtoi(ext);
ext = info->GetExtendedInfo(L"Hidden");
if (ext)
hidden = _wtoi(ext);
else
{
ext = info->GetExtendedInfo(L"Context");
if (ext)
{
if (!lstrcmpiW(ext, L"radio"))
{
hidden = true;
terminateOnEnd = true;
}
}
}
ext = info->GetExtendedInfo(L"Curtain");
if (ext)
{
StringCchCopyW(fcurtain, FILENAME_SIZE, ext);
if (!WhitelistOK(fcurtain))
fcurtain[0] = 0;
}
ext = info->GetExtendedInfo( L"ext" );
if ( ext )
{
StringCchCopyW( fileExt, 10, ext );
}
/*
ext = info->GetExtendedInfo(L"Browser");
if (ext)
{
StringCchCopyW(fbrowser, FILENAME_SIZE, ext);
if (!WhitelistOK(fbrowser))
fbrowser[0] = 0;
}
*/
}
if ( lengthInMs != -1 )
lengthInMs /= 1000;
if ( !hidden )
{
PlayList_append_withinfo_curtain( filename, title, lengthInMs, fcurtain[ 0 ] ? AutoChar( fcurtain ) : 0, fileExt, 0 );
}
else
{
PlayList_append_withinfo_hidden( filename, title, lengthInMs, fcurtain[ 0 ] ? AutoChar( fcurtain ) : 0/*, fbrowser[0] ? AutoChar(fbrowser) : 0*/ );
}
PlayList_SetLastItem_RepeatCount(playcount);
PlayList_SetLastItem_Range(starttime, endtime);
}
const wchar_t *WinampPlaylist::GetBasePath()
{
return base;
}
bool WinampDirectoryLoad::ShouldRecurse(const wchar_t *path)
{
if (config_rofiob&1)
PlayList_sort(2, listStart);
listStart = PlayList_getlength();
if (forceRecurse)
return true;
else
return (config_rofiob&2) ? false : true;
}
bool WinampDirectoryLoad::ShouldLoad(const wchar_t *filename)
{
if (!exts)
return true;
const wchar_t *ext = extensionW(filename);
char *a = exts;
while (a && *a)
{
if (!_wcsicmp(AutoWide(a), ext))
return true;
a += lstrlenA(a) + 1;
}
return false;
}
#define CBCLASS WinampPlaylist
START_DISPATCH;
VCB(IFC_PLAYLISTLOADERCALLBACK_ONFILE, OnFile)
CB(IFC_PLAYLISTLOADERCALLBACK_GETBASEPATH, GetBasePath)
END_DISPATCH;
#undef CBCLASS
#define CBCLASS WinampDirectoryLoad
START_DISPATCH;
CB(IFC_PLAYLISTDIRECTORYCALLBACK_SHOULDRECURSE, ShouldRecurse)
CB(IFC_PLAYLISTDIRECTORYCALLBACK_SHOULDLOAD, ShouldLoad)
END_DISPATCH;
#undef CBCLASS
|