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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
#include "main.h"
#include "api__ml_iso.h"
#include <api/service/waservicefactory.h>
#include "../burner/obj_isocreator.h"
#include "../playlist/ifc_playlistloadercallback.h"
#include <shlwapi.h>
#include <strsafe.h>
/**
** Playlist Loader callback class
** Used when this plugin loads a playlist file
** the playlist loader will call the OnFile() function
** for each playlist item
*/
class ISOPlaylistLoader : public ifc_playlistloadercallback
{
public:
ISOPlaylistLoader(obj_isocreator *_creator);
protected:
RECVS_DISPATCH;
private:
void OnFile(const wchar_t *filename, const wchar_t *title, int lengthInMS, ifc_plentryinfo *info);
obj_isocreator *creator;
};
/**
** helper function
** for getting a filename location
** of where to save the ISO file
**/
static bool PromptForFilename(wchar_t *filename, size_t filenameCch)
{
wchar_t oldCurPath[MAX_PATH], newCurPath[MAX_PATH];
OPENFILENAMEW openfilename;
// null terminate the string or else we'll get a garbage filename as the 'default' filename
filename[0]=0;
// GetSaveFileName changes Window's working directory
// which locks that folder from being deleted until Winamp closes
// so we save the old working directory name
// and restore it on complete
// Winamp maintains its own concept of a working directory
// to help us avoid this problem
GetCurrentDirectoryW(MAX_PATH, oldCurPath);
// initialize the open file name struct
openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = plugin.hwndLibraryParent;
openfilename.hInstance = plugin.hDllInstance;
openfilename.lpstrFilter = L"ISO Files\0*.iso\0";
openfilename.lpstrCustomFilter = 0;
openfilename.nMaxCustFilter = 0;
openfilename.nFilterIndex = 0;
openfilename.lpstrFile = filename;
openfilename.nMaxFile = filenameCch;
openfilename.lpstrFileTitle = 0;
openfilename.nMaxFileTitle = 0;
// we set the initial directory based on winamp's working path
openfilename.lpstrInitialDir = WASABI_API_APP->path_getWorkingPath();
openfilename.lpstrTitle = 0;
// despite the big note about working directory
// we don't want to use OFN_NOCHANGEDIR
// because we're going to manually sync Winamp's working path
openfilename.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_LONGNAMES;
openfilename.nFileOffset = 0;
openfilename.nFileExtension = 0;
openfilename.lpstrDefExt = L".iso";
openfilename.lCustData = 0;
openfilename.lpfnHook = 0;
openfilename.lpTemplateName = 0;
if (GetSaveFileNameW(&openfilename))
{
// let's re-synch Winamp's working directory
GetCurrentDirectoryW(MAX_PATH, newCurPath);
WASABI_API_APP->path_setWorkingPath(newCurPath);
// set the old path back
SetCurrentDirectoryW(oldCurPath);
return true; // success!
}
else
{
// set the old path back
SetCurrentDirectoryW(oldCurPath);
return false; // user hit cancel or something else happened
}
}
/**
** helper functions
** for creating and deleting
** an iso creator object
** through the wasabi service manager
**/
static obj_isocreator *CreateISOCreator()
{
waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(obj_isocreatorGUID);
if (factory)
return (obj_isocreator *)factory->getInterface();
else
return 0;
}
static void ReleaseISOCreator(obj_isocreator *creator)
{
if (creator)
{
waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(obj_isocreatorGUID);
if (factory)
factory->releaseInterface(creator);
}
}
void ConvertItemRecordListToISO(const itemRecordList *list)
{
obj_isocreator *isocreator = CreateISOCreator();
if (isocreator)
{
wchar_t destination[MAX_PATH];
if (PromptForFilename(destination, MAX_PATH))
{
// these values are hardcoded for this example.
isocreator->Open(L"WinampISO", obj_isocreator::FORMAT_JOLIET, obj_isocreator::MEDIA_CD);
char destinationPath[MAX_PATH];
// loop through the files and add them
for (int i=0;i<list->Size;i++)
{
itemRecord &item = list->Items[i];
// since we have metadata, we're going to auto-generate folders based on the album name
const char *album = item.album;
if (!album || !*album)
album = "Unknown Album";
// isocreator requires a preceding backslash
StringCbPrintfA(destinationPath, sizeof(destinationPath), "\\%s\\%s", album, PathFindFileNameA(item.filename));
// convert to unicode since that's what obj_isocreator requires
wchar_t unicodeSource[MAX_PATH];
wchar_t unicodeDest[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, item.filename, -1, unicodeSource, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, destinationPath, -1, unicodeDest, MAX_PATH);
isocreator->AddFile(unicodeSource, unicodeDest);
}
isocreator->Write(destination, 0);
}
ReleaseISOCreator(isocreator);
}
}
void ConvertFilenamesToISO(const char *filenames)
{
obj_isocreator *isocreator = CreateISOCreator();
if (isocreator)
{
wchar_t destination[MAX_PATH];
if (PromptForFilename(destination, MAX_PATH))
{
// these values are hardcoded for this example.
isocreator->Open(L"WinampISO", obj_isocreator::FORMAT_JOLIET, obj_isocreator::MEDIA_CD);
wchar_t destinationPath[MAX_PATH];
// loop through the files and add them
while (*filenames)
{
/**
** both playlist loader and iso creator want unicode filenames
** so we'll convert it first
*/
wchar_t unicodeFilename[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, filenames, -1, unicodeFilename, MAX_PATH);
/**
** see if this file is a playlist file
** we'll do that by trying to load it
** the Load() function will fail gracefully if it's not a playlist file
** if it succeeds, it will call loader.OnFile() which adds it to the iso file
**/
ISOPlaylistLoader loader(isocreator); // make a callback object for playlist loading
if (AGAVE_API_PLAYLISTMANAGER->Load(unicodeFilename, &loader) == PLAYLISTMANAGER_LOAD_NO_LOADER)
{
// not a playlist file, so load it normally
// isocreator requires a preceding backslash
StringCbPrintfW(destinationPath, sizeof(destinationPath), L"\\%s", PathFindFileNameW(unicodeFilename));
isocreator->AddFile(unicodeFilename, destinationPath);
}
filenames+=strlen(filenames)+1;
}
isocreator->Write(destination, 0);
}
ReleaseISOCreator(isocreator);
}
}
/**
** Load Playlist and write it to the ISO file
** this function is a bit complex, since we have to load the playlist
** through api_playlistmanager. This involves creating an playlist loader callback
** (ifc_playlistloadercallback) which gets called for each playlist item
**/
void ConvertPlaylistToISO(const mlPlaylist *playlist)
{
obj_isocreator *isocreator = CreateISOCreator();
if (isocreator)
{
wchar_t destination[MAX_PATH];
if (PromptForFilename(destination, MAX_PATH))
{
// these values are hardcoded for this example.
const wchar_t *title=L"WinampISO";
if (playlist->title) // if there's a playlist title, use it as the volume name
title = playlist->title;
isocreator->Open(title, obj_isocreator::FORMAT_JOLIET, obj_isocreator::MEDIA_CD);
ISOPlaylistLoader loader(isocreator); // make a callback object for playlist loading
AGAVE_API_PLAYLISTMANAGER->Load(playlist->filename, &loader);
isocreator->Write(destination, 0);
}
ReleaseISOCreator(isocreator);
}
}
/** Load all playlists and write them to the ISO file
** this function is a bit complex, since we have to load the playlist
** through api_playlistmanager. This involves creating an playlist loader callback
** (ifc_playlistloadercallback) which gets called for each playlist item
**/
void ConvertPlaylistsToISO(const mlPlaylist **playlists)
{
obj_isocreator *isocreator = CreateISOCreator();
if (isocreator)
{
wchar_t destination[MAX_PATH];
if (PromptForFilename(destination, MAX_PATH))
{
// these values are hardcoded for this example.
isocreator->Open(L"WinampISO", obj_isocreator::FORMAT_JOLIET, obj_isocreator::MEDIA_CD);
while (*playlists)
{
const mlPlaylist *playlist = *playlists;
ISOPlaylistLoader loader(isocreator); // make a callback object for playlist loading
AGAVE_API_PLAYLISTMANAGER->Load(playlist->filename, &loader);
playlists++;
}
isocreator->Write(destination, 0);
}
ReleaseISOCreator(isocreator);
}
}
void ConvertUnicodeItemRecordListToISO(const itemRecordListW *list)
{
obj_isocreator *isocreator = CreateISOCreator();
if (isocreator)
{
wchar_t destination[MAX_PATH];
if (PromptForFilename(destination, MAX_PATH))
{
// these values are hardcoded for this example.
isocreator->Open(L"WinampISO", obj_isocreator::FORMAT_JOLIET, obj_isocreator::MEDIA_CD);
wchar_t destinationPath[MAX_PATH];
// loop through the files and add them
for (int i=0;i<list->Size;i++)
{
itemRecordW &item = list->Items[i];
// since we have metadata, we're going to auto-generate folders based on the album name
const wchar_t *album = item.album;
if (!album || !*album)
album = L"Unknown Album";
// isocreator requires a preceding backslash
StringCbPrintfW(destinationPath, sizeof(destinationPath), L"\\%s\\%s", album, PathFindFileNameW(item.filename));
isocreator->AddFile(item.filename, destinationPath);
}
isocreator->Write(destination, 0);
}
ReleaseISOCreator(isocreator);
}
}
void ConvertUnicodeFilenamesToISO(const wchar_t *filenames)
{
obj_isocreator *isocreator = CreateISOCreator();
if (isocreator)
{
wchar_t destination[MAX_PATH];
if (PromptForFilename(destination, MAX_PATH))
{
// these values are hardcoded for this example.
isocreator->Open(L"WinampISO", obj_isocreator::FORMAT_JOLIET, obj_isocreator::MEDIA_CD);
wchar_t destinationPath[MAX_PATH];
// loop through the files and add them
while (*filenames)
{
/**
** see if this file is a playlist file
** we'll do that by trying to load it
** the Load() function will fail gracefully if it's not a playlist file
** if it succeeds, it will call loader.OnFile() which adds it to the iso file
**/
ISOPlaylistLoader loader(isocreator); // make a callback object for playlist loading
if (AGAVE_API_PLAYLISTMANAGER->Load(filenames, &loader) == PLAYLISTMANAGER_LOAD_NO_LOADER)
{
// not a playlist file, so load it normally
// isocreator requires a preceding backslash
StringCbPrintfW(destinationPath, sizeof(destinationPath), L"\\%s", PathFindFileNameW(filenames));
isocreator->AddFile(filenames, destinationPath);
}
filenames+=wcslen(filenames)+1;
}
isocreator->Write(destination, 0);
}
ReleaseISOCreator(isocreator);
}
}
/* --- Playlist Loader definition --- */
ISOPlaylistLoader::ISOPlaylistLoader(obj_isocreator *_creator)
{
creator=_creator;
}
void ISOPlaylistLoader::OnFile(const wchar_t *filename, const wchar_t *title, int lengthInMS, ifc_plentryinfo *info)
{
// isocreator requires a preceding backslash
wchar_t destinationPath[MAX_PATH];
StringCbPrintfW(destinationPath, sizeof(destinationPath), L"\\%s", PathFindFileNameW(filename));
// add file to .iso image
creator->AddFile(filename, destinationPath);
}
#define CBCLASS ISOPlaylistLoader
START_DISPATCH;
VCB(IFC_PLAYLISTLOADERCALLBACK_ONFILE, OnFile)
//VCB(IFC_PLAYLISTLOADERCALLBACK_ONPLAYLISTINFO, OnPlaylistInfo)
END_DISPATCH;
|