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
|
/** (c) Nullsoft, Inc. C O N F I D E N T I A L
** Filename:
** Project:
** Description:
** Author:
** Created:
**/
#include "Main.h"
#include <io.h>
#include <sys/stat.h>
#include "api.h"
#include "WinampPlaylist.h"
#include "../nu/AutoChar.h"
#include <strsafe.h>
void saveplsfn(const wchar_t *_fn)
{
int pos = PlayList_getPosition();
PlayList_setposition(0);
FILE *plsFile = _wfopen(_fn, L"wt");
if(plsFile)
{
int x = 0;
fprintf(plsFile, "[playlist]\r\n");
for (;;)
{
int plspos = PlayList_getPosition();
if (!PlayList_gethidden(plspos) && !PlayList_hasanycurtain(plspos))
{
wchar_t fnbuf[FILENAME_SIZE] = {0}, ftbuf[FILETITLE_SIZE] = {0};
PlayList_getitem2W(plspos, fnbuf, ftbuf);
PlayList_makerelative(_fn, fnbuf, 0);
fprintf(plsFile, "File%d=%s\r\n", ++x, (char *)AutoChar(fnbuf));
/*
const char *sBrowser = PlayList_getbrowser(plspos);
if (sBrowser)
fprintf(plsFile, "Browser%d=%s\r\n", x, sBrowser);
*/
if (PlayList_getcached(plspos))
{
fprintf(plsFile, "Title%d=%s\r\n", x, (char *)AutoChar(ftbuf));
fprintf(plsFile, "Length%d=%d\r\n", x, PlayList_getcurrentlength());
}
int repeat = PlayList_getrepeatcount(plspos);
if (repeat > 0)
fprintf(plsFile, "Repeat%d=%d\r\n", x, repeat);
}
if (PlayList_advance(1) < 0) break;
}
fprintf(plsFile, "NumberOfEntries=%d\r\n", x);
fprintf(plsFile, "Version=2\r\n");
PlayList_setposition(pos);
fclose(plsFile);
}
return ;
}
int loadpls(HWND hwnd, int whattodo)
{
if (!playlistManager)
{
LPMessageBox(hwnd, IDS_PLAYLIST_SUPPORT_NOT_INSTALLED,IDS_PLAYLIST_LOAD_ERROR, MB_OK);
return 0;
}
wchar_t filter[1024] = {0};
playlistManager->GetFilterList(filter, 1024);
wchar_t temp[FILENAME_SIZE] = {0}, oldCurPath[MAX_PATH] = {0}, titleStr[128] = {0};
GetCurrentDirectoryW(MAX_PATH, oldCurPath);
OPENFILENAMEW l = {sizeof(OPENFILENAMEW),0};
static int q;
int retv = 0;
if (q) return 0;
q = 1;
l.hwndOwner = DIALOG_PARENT(hMainWindow); //hwnd;
l.hInstance = hMainInstance;
l.lpstrFilter = filter;
l.lpstrFile = temp;
temp[0] = 0;
l.nMaxFile = FILENAME_SIZE;
l.lpstrInitialDir = WASABI_API_APP->path_getWorkingPath();
if (whattodo == 0) l.lpstrTitle = getStringW(IDS_OPEN_PLAYLIST,titleStr,128);
else if (whattodo == 1) l.lpstrTitle = getStringW(IDS_ADD_PLAYLIST,titleStr,128);
else l.lpstrTitle = getStringW(IDS_OPEN_PLAYLIST,titleStr,128);
l.lpstrDefExt = L"pls";
l.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
UninitDragDrops();
if (GetOpenFileNameW(&l))
{
wchar_t newCurPath[MAX_PATH] = {0};
GetCurrentDirectoryW(MAX_PATH, newCurPath);
WASABI_API_APP->path_setWorkingPath(newCurPath);
q = 0;
if (LoadPlaylist(temp, whattodo, 0) != 0)
retv = 0;
//else // TODO: this wasn't there in the old code, so we'll leave it out for now
retv = 1;
}
SetCurrentDirectoryW(oldCurPath);
q = 0;
InitDragDrops();
return retv;
}
static void checkplswritable(wchar_t *filename)
{
if (!_waccess(filename, 0))
{
if (_waccess(filename, 2))
{
_wchmod(filename, _S_IREAD | _S_IWRITE);
}
}
}
int savepls(HWND hwnd)
{
wchar_t oldCurPath[MAX_PATH] = {0};
GetCurrentDirectoryW(MAX_PATH, oldCurPath);
static wchar_t temp[MAX_PATH] = {0};
OPENFILENAMEW l = {sizeof(OPENFILENAMEW),0};
static int q;
if (q) return 0;
int ret = 0;
q = 1;
l.hwndOwner = hwnd;
l.hInstance = hMainInstance;
l.lpstrFilter = (LPCWSTR)SendMessageW(hMainWindow, WM_WA_IPC, 3, IPC_GET_PLAYLIST_EXTLISTW);
l.nFilterIndex = _r_i("plsflt", 3);
l.lpstrFile = temp;
l.nMaxFile = MAX_PATH - 1;
l.lpstrTitle = getStringW(IDS_SAVE_PLAYLIST,NULL,0);
l.lpstrDefExt = L"m3u";
l.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_OVERWRITEPROMPT;
if (GetSaveFileNameW(&l))
{
wchar_t newCurPath[MAX_PATH] = {0};
GetCurrentDirectoryW(MAX_PATH, newCurPath);
WASABI_API_APP->path_setWorkingPath(newCurPath);
SetCurrentDirectoryW(oldCurPath);
checkplswritable(temp);
q = 0;
ret = 1;
if (!_wcsicmp(extensionW(temp), L"pls"))
{
DeleteFileW(temp);
saveplsfn(temp);
}
else // if it's not PLS, then it's m3u or m3u8, both of which are handled by the same function
{
savem3ufn(temp, 0, 0);
}
}
_w_i("plsflt", l.nFilterIndex);
SetCurrentDirectoryW(oldCurPath);
q = 0;
return ret;
}
|