Pls.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include <io.h>
  10. #include <sys/stat.h>
  11. #include "api.h"
  12. #include "WinampPlaylist.h"
  13. #include "../nu/AutoChar.h"
  14. #include <strsafe.h>
  15. void saveplsfn(const wchar_t *_fn)
  16. {
  17. int pos = PlayList_getPosition();
  18. PlayList_setposition(0);
  19. FILE *plsFile = _wfopen(_fn, L"wt");
  20. if(plsFile)
  21. {
  22. int x = 0;
  23. fprintf(plsFile, "[playlist]\r\n");
  24. for (;;)
  25. {
  26. int plspos = PlayList_getPosition();
  27. if (!PlayList_gethidden(plspos) && !PlayList_hasanycurtain(plspos))
  28. {
  29. wchar_t fnbuf[FILENAME_SIZE] = {0}, ftbuf[FILETITLE_SIZE] = {0};
  30. PlayList_getitem2W(plspos, fnbuf, ftbuf);
  31. PlayList_makerelative(_fn, fnbuf, 0);
  32. fprintf(plsFile, "File%d=%s\r\n", ++x, (char *)AutoChar(fnbuf));
  33. /*
  34. const char *sBrowser = PlayList_getbrowser(plspos);
  35. if (sBrowser)
  36. fprintf(plsFile, "Browser%d=%s\r\n", x, sBrowser);
  37. */
  38. if (PlayList_getcached(plspos))
  39. {
  40. fprintf(plsFile, "Title%d=%s\r\n", x, (char *)AutoChar(ftbuf));
  41. fprintf(plsFile, "Length%d=%d\r\n", x, PlayList_getcurrentlength());
  42. }
  43. int repeat = PlayList_getrepeatcount(plspos);
  44. if (repeat > 0)
  45. fprintf(plsFile, "Repeat%d=%d\r\n", x, repeat);
  46. }
  47. if (PlayList_advance(1) < 0) break;
  48. }
  49. fprintf(plsFile, "NumberOfEntries=%d\r\n", x);
  50. fprintf(plsFile, "Version=2\r\n");
  51. PlayList_setposition(pos);
  52. fclose(plsFile);
  53. }
  54. return ;
  55. }
  56. int loadpls(HWND hwnd, int whattodo)
  57. {
  58. if (!playlistManager)
  59. {
  60. LPMessageBox(hwnd, IDS_PLAYLIST_SUPPORT_NOT_INSTALLED,IDS_PLAYLIST_LOAD_ERROR, MB_OK);
  61. return 0;
  62. }
  63. wchar_t filter[1024] = {0};
  64. playlistManager->GetFilterList(filter, 1024);
  65. wchar_t temp[FILENAME_SIZE] = {0}, oldCurPath[MAX_PATH] = {0}, titleStr[128] = {0};
  66. GetCurrentDirectoryW(MAX_PATH, oldCurPath);
  67. OPENFILENAMEW l = {sizeof(OPENFILENAMEW),0};
  68. static int q;
  69. int retv = 0;
  70. if (q) return 0;
  71. q = 1;
  72. l.hwndOwner = DIALOG_PARENT(hMainWindow); //hwnd;
  73. l.hInstance = hMainInstance;
  74. l.lpstrFilter = filter;
  75. l.lpstrFile = temp;
  76. temp[0] = 0;
  77. l.nMaxFile = FILENAME_SIZE;
  78. l.lpstrInitialDir = WASABI_API_APP->path_getWorkingPath();
  79. if (whattodo == 0) l.lpstrTitle = getStringW(IDS_OPEN_PLAYLIST,titleStr,128);
  80. else if (whattodo == 1) l.lpstrTitle = getStringW(IDS_ADD_PLAYLIST,titleStr,128);
  81. else l.lpstrTitle = getStringW(IDS_OPEN_PLAYLIST,titleStr,128);
  82. l.lpstrDefExt = L"pls";
  83. l.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
  84. UninitDragDrops();
  85. if (GetOpenFileNameW(&l))
  86. {
  87. wchar_t newCurPath[MAX_PATH] = {0};
  88. GetCurrentDirectoryW(MAX_PATH, newCurPath);
  89. WASABI_API_APP->path_setWorkingPath(newCurPath);
  90. q = 0;
  91. if (LoadPlaylist(temp, whattodo, 0) != 0)
  92. retv = 0;
  93. //else // TODO: this wasn't there in the old code, so we'll leave it out for now
  94. retv = 1;
  95. }
  96. SetCurrentDirectoryW(oldCurPath);
  97. q = 0;
  98. InitDragDrops();
  99. return retv;
  100. }
  101. static void checkplswritable(wchar_t *filename)
  102. {
  103. if (!_waccess(filename, 0))
  104. {
  105. if (_waccess(filename, 2))
  106. {
  107. _wchmod(filename, _S_IREAD | _S_IWRITE);
  108. }
  109. }
  110. }
  111. int savepls(HWND hwnd)
  112. {
  113. wchar_t oldCurPath[MAX_PATH] = {0};
  114. GetCurrentDirectoryW(MAX_PATH, oldCurPath);
  115. static wchar_t temp[MAX_PATH] = {0};
  116. OPENFILENAMEW l = {sizeof(OPENFILENAMEW),0};
  117. static int q;
  118. if (q) return 0;
  119. int ret = 0;
  120. q = 1;
  121. l.hwndOwner = hwnd;
  122. l.hInstance = hMainInstance;
  123. l.lpstrFilter = (LPCWSTR)SendMessageW(hMainWindow, WM_WA_IPC, 3, IPC_GET_PLAYLIST_EXTLISTW);
  124. l.nFilterIndex = _r_i("plsflt", 3);
  125. l.lpstrFile = temp;
  126. l.nMaxFile = MAX_PATH - 1;
  127. l.lpstrTitle = getStringW(IDS_SAVE_PLAYLIST,NULL,0);
  128. l.lpstrDefExt = L"m3u";
  129. l.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_OVERWRITEPROMPT;
  130. if (GetSaveFileNameW(&l))
  131. {
  132. wchar_t newCurPath[MAX_PATH] = {0};
  133. GetCurrentDirectoryW(MAX_PATH, newCurPath);
  134. WASABI_API_APP->path_setWorkingPath(newCurPath);
  135. SetCurrentDirectoryW(oldCurPath);
  136. checkplswritable(temp);
  137. q = 0;
  138. ret = 1;
  139. if (!_wcsicmp(extensionW(temp), L"pls"))
  140. {
  141. DeleteFileW(temp);
  142. saveplsfn(temp);
  143. }
  144. else // if it's not PLS, then it's m3u or m3u8, both of which are handled by the same function
  145. {
  146. savem3ufn(temp, 0, 0);
  147. }
  148. }
  149. _w_i("plsflt", l.nFilterIndex);
  150. SetCurrentDirectoryW(oldCurPath);
  151. q = 0;
  152. return ret;
  153. }