CurrentPlaylist.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #include <shlobj.h>
  2. #include <shlwapi.h>
  3. #include <strsafe.h>
  4. #include "main.h"
  5. #include "CurrentPlaylist.h"
  6. #include "Playlist.h"
  7. #include "../winamp/wa_ipc.h"
  8. #include "../nu/AutoWide.h"
  9. #include "PlaylistDirectoryCallback.h"
  10. #include "api__ml_playlists.h"
  11. extern Playlist currentPlaylist;
  12. bool currentPlaylist_ImportFromDisk( HWND hwnd )
  13. {
  14. wchar_t oldCurPath[MAX_PATH] = {0};
  15. GetCurrentDirectoryW(MAX_PATH, oldCurPath);
  16. wchar_t temp[1024] = {0};
  17. wchar_t filter[1024] = {0};
  18. AGAVE_API_PLAYLISTMANAGER->GetFilterList(filter, 1024);
  19. OPENFILENAMEW l = {sizeof(l), };
  20. l.hwndOwner = hwnd;
  21. l.lpstrFilter = filter;
  22. l.lpstrFile = temp;
  23. l.nMaxFile = 1023;
  24. l.lpstrTitle = WASABI_API_LNGSTRINGW(IDS_IMPORT_PLAYLIST);
  25. l.lpstrDefExt = L"m3u";
  26. l.lpstrInitialDir = WASABI_API_APP->path_getWorkingPath();
  27. l.Flags = OFN_HIDEREADONLY | OFN_EXPLORER;
  28. bool ret = false;
  29. if ( GetOpenFileNameW( &l ) )
  30. {
  31. wchar_t newCurPath[ MAX_PATH ] = { 0 };
  32. GetCurrentDirectoryW( MAX_PATH, newCurPath );
  33. WASABI_API_APP->path_setWorkingPath( newCurPath );
  34. wchar_t titleStr[ 32 ] = { 0 };
  35. int w = currentPlaylist.GetNumItems() == 0 ? IDYES :
  36. MessageBox( hwnd, WASABI_API_LNGSTRINGW( IDS_APPEND_IMPORTED_PLAYLIST ),
  37. WASABI_API_LNGSTRINGW_BUF( IDS_LIBRARY_QUESTION, titleStr, 32 ),
  38. MB_YESNOCANCEL | MB_ICONQUESTION );
  39. if ( w != IDCANCEL )
  40. {
  41. if ( w == IDNO )
  42. currentPlaylist.Clear();
  43. AGAVE_API_PLAYLISTMANAGER->Load( temp, &currentPlaylist );
  44. ret = true;
  45. }
  46. }
  47. SetCurrentDirectoryW( oldCurPath );
  48. return ret;
  49. }
  50. bool currentPlaylist_ImportFromWinamp( HWND hwnd )
  51. {
  52. wchar_t titleStr[ 32 ] = { 0 };
  53. int w = currentPlaylist.GetNumItems() == 0 ? IDNO :
  54. MessageBox( hwnd, WASABI_API_LNGSTRINGW( IDS_APPEND_ACTIVE_PLAYLIST ),
  55. WASABI_API_LNGSTRINGW_BUF( IDS_LIBRARY_QUESTION, titleStr, 32 ),
  56. MB_YESNOCANCEL | MB_ICONQUESTION );
  57. if ( w != IDCANCEL )
  58. {
  59. if ( w == IDNO )
  60. currentPlaylist.Clear();
  61. SendMessage( plugin.hwndWinampParent, WM_WA_IPC, 0, IPC_WRITEPLAYLIST );
  62. wchar_t *m3udir = (wchar_t *)SendMessage( plugin.hwndWinampParent, WM_WA_IPC, 0, IPC_GETM3UDIRECTORYW );
  63. wchar_t s[ MAX_PATH ] = { 0 };
  64. PathCombineW( s, m3udir, L"winamp.m3u8" );
  65. AGAVE_API_PLAYLISTMANAGER->Load( s, &currentPlaylist );
  66. return true;
  67. }
  68. return false;
  69. }
  70. bool CurrentPlaylist_DeleteMissing()
  71. {
  72. bool ret = false;
  73. size_t x = currentPlaylist.GetNumItems();
  74. while ( x-- )
  75. {
  76. wchar_t fn[ 1024 ] = { 0 };
  77. currentPlaylist.GetItem( x, fn, 1024 );
  78. if ( !wcsstr( fn, L"://" ) && !wcsstr( fn, L":\\\\" ) && !( PathFileExistsW( fn ) ) )
  79. {
  80. currentPlaylist.Remove( x );
  81. ret = true;
  82. }
  83. }
  84. return ret;
  85. }
  86. void CurrentPlaylist_Export(HWND dlgparent)
  87. {
  88. wchar_t oldCurPath[MAX_PATH] = {0};
  89. GetCurrentDirectoryW(MAX_PATH, oldCurPath);
  90. wchar_t temp[MAX_PATH] = {0};
  91. OPENFILENAMEW l = {sizeof(OPENFILENAMEW), 0};
  92. lstrcpynW(temp, (wchar_t*)GetPropW(dlgparent, L"TITLE"), MAX_PATH);
  93. Playlists_ReplaceBadPathChars(temp);
  94. l.hwndOwner = dlgparent;
  95. l.hInstance = plugin.hDllInstance;
  96. l.nFilterIndex = g_config->ReadInt(L"filter", 3);
  97. l.lpstrFilter = (LPCWSTR)SendMessage(plugin.hwndWinampParent, WM_WA_IPC, 3, IPC_GET_PLAYLIST_EXTLISTW);
  98. l.lpstrFile = temp;
  99. l.nMaxFile = MAX_PATH;
  100. l.lpstrTitle = WASABI_API_LNGSTRINGW(IDS_EXPORT_PLAYLIST);
  101. l.lpstrDefExt = L"m3u";
  102. l.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_OVERWRITEPROMPT;
  103. if ( GetSaveFileNameW( &l ) )
  104. {
  105. wchar_t newCurPath[ MAX_PATH ] = { 0 };
  106. GetCurrentDirectoryW( MAX_PATH, newCurPath );
  107. WASABI_API_APP->path_setWorkingPath( newCurPath );
  108. AGAVE_API_PLAYLISTMANAGER->Save( temp, &currentPlaylist );
  109. }
  110. g_config->WriteInt( L"filter", l.nFilterIndex );
  111. SetCurrentDirectoryW( oldCurPath );
  112. }
  113. bool CurrentPlaylist_AddLocation( HWND hwndDlg )
  114. {
  115. bool ret = false;
  116. char *p = (char *)SendMessage( plugin.hwndWinampParent, WM_WA_IPC, (WPARAM)hwndDlg, IPC_OPENURLBOX );
  117. if ( p )
  118. {
  119. //size_t s = currentPlaylist.GetNumItems();
  120. AutoWide wideFn( p );
  121. if ( AGAVE_API_PLAYLISTMANAGER->Load( wideFn, &currentPlaylist ) != PLAYLISTMANAGER_SUCCESS )
  122. {
  123. wchar_t title[ FILETITLE_SIZE ] = { 0 };
  124. int length = -1;
  125. mediaLibrary.GetFileInfo( wideFn, title, FILETITLE_SIZE, &length );
  126. currentPlaylist.AppendWithInfo( wideFn, title, length * 1000 );
  127. }
  128. ret = true;
  129. // TODO: if (GetPrivateProfileInt("winamp", "rofiob", 1, WINAMP_INI)&1) PlayList_sort(2, s);
  130. GlobalFree( (HGLOBAL)p );
  131. }
  132. return ret;
  133. }
  134. static INT_PTR CALLBACK browseCheckBoxProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  135. {
  136. if ( uMsg == WM_INITDIALOG )
  137. {
  138. int rofiob = GetPrivateProfileIntA( "winamp", "rofiob", 1, mediaLibrary.GetWinampIni() );
  139. if ( !( rofiob & 2 ) )
  140. CheckDlgButton( hwndDlg, IDC_CHECK1, BST_CHECKED );
  141. }
  142. if ( uMsg == WM_COMMAND )
  143. {
  144. if ( LOWORD( wParam ) == IDC_CHECK1 )
  145. {
  146. int rofiob = GetPrivateProfileIntA( "winamp", "rofiob", 1, mediaLibrary.GetWinampIni() );
  147. if ( IsDlgButtonChecked( hwndDlg, IDC_CHECK1 ) )
  148. rofiob &= ~2;
  149. else
  150. rofiob |= 2;
  151. char blah[ 32 ] = { 0 };
  152. StringCchPrintfA( blah, 32, "%d", rofiob );
  153. WritePrivateProfileStringA( "winamp", "rofiob", blah, mediaLibrary.GetWinampIni() );
  154. }
  155. }
  156. return 0;
  157. }
  158. static int CALLBACK WINAPI BrowseCallbackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
  159. {
  160. switch ( uMsg )
  161. {
  162. case BFFM_INITIALIZED:
  163. {
  164. SetWindowTextW( hwnd, WASABI_API_LNGSTRINGW( IDS_ADD_DIR_TO_PLAYLIST ) );
  165. SendMessageW( hwnd, BFFM_SETSELECTIONW, 1, (LPARAM)WASABI_API_APP->path_getWorkingPath() );
  166. HWND h2 = FindWindowEx( hwnd, NULL, NULL, L"__foo2" );
  167. if ( h2 )
  168. ShowWindow( h2, SW_HIDE );
  169. HWND h = WASABI_API_CREATEDIALOGW( IDD_BROWSE_PLFLD, hwnd, browseCheckBoxProc );
  170. SetWindowPos( h, 0, 4, 4, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
  171. ShowWindow( h, SW_SHOWNA );
  172. // this is not nice but it fixes the selection not working correctly on all OSes
  173. EnumChildWindows( hwnd, browseEnumProc, 0 );
  174. }
  175. }
  176. return 0;
  177. }
  178. bool CurrentPlaylist_AddDirectory( HWND hwndDlg )
  179. {
  180. BROWSEINFOW bi = { 0 };
  181. wchar_t name[ MAX_PATH ] = { 0 };
  182. bi.hwndOwner = hwndDlg;
  183. bi.pidlRoot = 0;
  184. bi.pszDisplayName = name;
  185. bi.lpszTitle = L"__foo2";
  186. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  187. bi.lpfn = BrowseCallbackProc;
  188. bi.lParam = 0;
  189. ITEMIDLIST *idlist = SHBrowseForFolderW( &bi );
  190. if ( idlist )
  191. {
  192. //size_t s = currentPlaylist.GetNumItems();
  193. wchar_t path[ MAX_PATH ] = { 0 };
  194. SHGetPathFromIDListW( idlist, path );
  195. WASABI_API_APP->path_setWorkingPath( path );
  196. extern void Shell_Free( void *p );
  197. Shell_Free( idlist );
  198. WASABI_API_APP->path_setWorkingPath( path );
  199. PlaylistDirectoryCallback dirCallback( mediaLibrary.GetExtensionList(), mediaLibrary.GetWinampIni() );
  200. AGAVE_API_PLAYLISTMANAGER->LoadDirectory( path, &currentPlaylist, &dirCallback );
  201. //int rofiob = GetPrivateProfileInt("winamp", "rofiob", 1, WINAMP_INI);
  202. // TODO: if (rofiob&1) PlayList_sort(2, s);
  203. return true;
  204. }
  205. return false;
  206. }
  207. bool CurrentPlaylist_AddFiles( HWND hwndDlg )
  208. {
  209. wchar_t oldCurPath[ MAX_PATH ] = { 0 };
  210. GetCurrentDirectoryW( MAX_PATH, oldCurPath );
  211. const int len = 256 * 1024 - 128;
  212. wchar_t *temp;
  213. OPENFILENAMEW l = { sizeof( l ), };
  214. static int q;
  215. if ( q )
  216. return false;
  217. q = 1;
  218. temp = (wchar_t *)GlobalAlloc( GPTR, sizeof( wchar_t ) * len );
  219. l.hwndOwner = hwndDlg;
  220. wchar_t *fsb = (wchar_t *)SendMessage( plugin.hwndWinampParent, WM_WA_IPC, 1, IPC_GET_EXTLISTW );
  221. l.lpstrFilter = fsb;
  222. l.lpstrFile = temp;
  223. l.nMaxFile = len - 1;
  224. l.lpstrTitle = WASABI_API_LNGSTRINGW( IDS_ADD_FILES_TO_PLAYLIST );
  225. l.lpstrDefExt = L"";
  226. l.lpstrInitialDir = WASABI_API_APP->path_getWorkingPath();
  227. l.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
  228. bool ret = false;
  229. if ( GetOpenFileNameW( &l ) )
  230. {
  231. wchar_t newCurPath[ MAX_PATH ] = { 0 };
  232. GetCurrentDirectoryW( MAX_PATH, newCurPath );
  233. WASABI_API_APP->path_setWorkingPath( newCurPath );
  234. if ( temp[ wcslen( temp ) + 1 ] )
  235. {
  236. AGAVE_API_PLAYLISTMANAGER->LoadFromDialog( temp, &currentPlaylist );
  237. ret = true;
  238. // TODO: if (GetPrivateProfileInt("winamp", "rofiob", 1, WINAMP_INI)&1) PlayList_sort(2, sp);
  239. }
  240. else
  241. {
  242. if ( AGAVE_API_PLAYLISTMANAGER->Load( temp, &currentPlaylist ) != PLAYLISTMANAGER_SUCCESS )
  243. {
  244. wchar_t title[ FILETITLE_SIZE ] = { 0 };
  245. int length;
  246. mediaLibrary.GetFileInfo( temp, title, FILETITLE_SIZE, &length );
  247. currentPlaylist.AppendWithInfo( temp, title, length * 1000 );
  248. ret = true;
  249. }
  250. }
  251. }
  252. SetCurrentDirectoryW( oldCurPath );
  253. GlobalFree( fsb );
  254. GlobalFree( temp );
  255. q = 0;
  256. return ret;
  257. }