options_bookmarks.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. #if 0 // no more minibrowser
  10. static int listDragging=0,listSel=-1;
  11. static WNDPROC OldBookListProc;
  12. static BOOL CALLBACK BookListProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  13. {
  14. switch (uMsg)
  15. {
  16. case WM_LBUTTONDOWN:
  17. if (!listDragging)
  18. {
  19. POINT p;
  20. RECT r;
  21. GetCursorPos(&p);
  22. GetWindowRect(hwndDlg,&r);
  23. if (p.x >= r.left && p.x < r.right && p.y >= r.top && p.y < r.bottom)
  24. {
  25. int x=SendMessageW(hwndDlg,LB_ITEMFROMPOINT,0,MAKELPARAM(p.x-r.left,p.y-r.top-2));
  26. if (!HIWORD(x))
  27. {
  28. listDragging=1;
  29. listSel=x;
  30. }
  31. }
  32. }
  33. break;
  34. // case WM_KILLFOCUS:
  35. case WM_LBUTTONUP:
  36. listDragging=0;
  37. listSel=-1;
  38. break;
  39. }
  40. return CallWindowProc(OldBookListProc,hwndDlg,uMsg,wParam,lParam);
  41. }
  42. static char *g_bmedit_fn, *g_bmedit_ft;
  43. static BOOL CALLBACK BookMarkEditProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  44. {
  45. switch (uMsg)
  46. {
  47. case WM_INITDIALOG:
  48. SetDlgItemText(hwndDlg,IDC_TITLE,g_bmedit_ft);
  49. SetDlgItemText(hwndDlg,IDC_FILE,g_bmedit_fn);
  50. return 0;
  51. case WM_COMMAND:
  52. switch (LOWORD(wParam))
  53. {
  54. case IDOK:
  55. GetDlgItemText(hwndDlg,IDC_TITLE,g_bmedit_ft,4095);
  56. GetDlgItemText(hwndDlg,IDC_FILE,g_bmedit_fn,MAX_PATH);
  57. case IDCANCEL:
  58. EndDialog(hwndDlg,0);
  59. return 0;
  60. }
  61. return 0;
  62. }
  63. return 0;
  64. }
  65. static BOOL CALLBACK BookProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  66. {
  67. // hi helpinfo[]={
  68. // };
  69. // DO_HELP();
  70. switch (uMsg)
  71. {
  72. case WM_CTLCOLORLISTBOX:
  73. if(listDragging)
  74. {
  75. POINT p;
  76. RECT r;
  77. int thisp;
  78. GetCursorPos(&p);
  79. GetWindowRect(GetDlgItem(hwndDlg,IDC_SELBOX),&r);
  80. thisp=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_ITEMFROMPOINT,0,MAKELPARAM(p.x-r.left,p.y-r.top-2));
  81. if(HIWORD(thisp))
  82. {
  83. // mouse pointer outside client area
  84. thisp=LOWORD(thisp);
  85. }
  86. if (listSel != -1 && listSel != thisp)
  87. {
  88. int len=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCOUNT,0,0);
  89. // move listSel to thisp.
  90. if (thisp >= 0 && listSel >= 0 && thisp < len && listSel < len) {
  91. char fn[MAX_PATH] = {0};
  92. char file1[MAX_PATH] = {0}, title1[4096] = {0};
  93. FILE *fp,*fpo;
  94. Bookmark_getfn(fn);
  95. fp=fopen(fn,"rt");
  96. fpo=fopen(TEMP_FILE,"wt");
  97. if (fp&&fpo)
  98. {
  99. char ft[4096] = {0};
  100. int x=0;
  101. while (1)
  102. {
  103. if (x == listSel)
  104. {
  105. fgets(file1,MAX_PATH,fp);
  106. fgets(title1,4096,fp);
  107. }
  108. else
  109. {
  110. fgets(fn,MAX_PATH,fp);
  111. fgets(ft,4096,fp);
  112. }
  113. if (feof(fp)) break;
  114. x++;
  115. }
  116. fseek(fp,0,SEEK_SET);
  117. x=0;
  118. while (1)
  119. {
  120. fgets(fn,MAX_PATH,fp);
  121. fgets(ft,4096,fp);
  122. if (feof(fp)) break;
  123. if (listSel < thisp)
  124. {
  125. if (x != listSel) fprintf(fpo,"%s%s",fn,ft);
  126. if (x == thisp) fprintf(fpo,"%s%s",file1,title1);
  127. }
  128. else
  129. {
  130. if (x == thisp) fprintf(fpo,"%s%s",file1,title1);
  131. if (x != listSel) fprintf(fpo,"%s%s",fn,ft);
  132. }
  133. x++;
  134. }
  135. }
  136. if (fp) fclose(fp);
  137. if (fpo) fclose(fpo);
  138. if (fp && fpo)
  139. {
  140. Bookmark_getfn(fn);
  141. DeleteFile(fn);
  142. MoveFile(TEMP_FILE,fn);
  143. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETTEXT,(WPARAM)listSel,(LPARAM)title1);
  144. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,(WPARAM)listSel,0);
  145. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_INSERTSTRING,(WPARAM)thisp,(LPARAM)title1);
  146. listSel=thisp;
  147. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,thisp,0);
  148. }
  149. }
  150. }
  151. }
  152. return 0;
  153. case WM_USER+32:
  154. if (wParam == 1024 && lParam == 3213)
  155. {
  156. char fn[MAX_PATH] = {0};
  157. FILE *fp;
  158. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_RESETCONTENT,0,0);
  159. Bookmark_getfn(fn);
  160. fp=fopen(fn,"rt");
  161. if (fp)
  162. {
  163. while (1)
  164. {
  165. char ft[4096] = {0};
  166. fgets(fn,MAX_PATH,fp);
  167. if (feof(fp)) break;
  168. fgets(ft,4096,fp);
  169. if (feof(fp)) break;
  170. if (ft[0] && fn[0])
  171. {
  172. if (fn[lstrlen(fn)-1]=='\n') fn[lstrlen(fn)-1]=0;
  173. if (ft[lstrlen(ft)-1]=='\n') ft[lstrlen(ft)-1]=0;
  174. if (ft[0] && fn[0])
  175. {
  176. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_ADDSTRING,0,(LPARAM)ft);
  177. }
  178. }
  179. }
  180. fclose(fp);
  181. }
  182. }
  183. return 0;
  184. case WM_INITDIALOG:
  185. {
  186. char fn[MAX_PATH] = {0};
  187. FILE *fp;
  188. OldBookListProc=(WNDPROC)SetWindowLong(GetDlgItem(hwndDlg,IDC_SELBOX), GWLP_WNDPROC,(LONG)BookListProc);
  189. listDragging=0;
  190. listSel=-1;
  191. Bookmark_getfn(fn);
  192. fp=fopen(fn,"rt");
  193. if (fp)
  194. {
  195. while (1)
  196. {
  197. char ft[4096] = {0};
  198. fgets(fn,MAX_PATH,fp);
  199. if (feof(fp)) break;
  200. fgets(ft,4096,fp);
  201. if (feof(fp)) break;
  202. if (ft[0] && fn[0])
  203. {
  204. if (fn[lstrlen(fn)-1]=='\n') fn[lstrlen(fn)-1]=0;
  205. if (ft[lstrlen(ft)-1]=='\n') ft[lstrlen(ft)-1]=0;
  206. if (ft[0] && fn[0])
  207. {
  208. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_ADDSTRING,0,(LPARAM)ft);
  209. }
  210. }
  211. }
  212. fclose(fp);
  213. }
  214. }
  215. return TRUE;
  216. case WM_COMMAND:
  217. switch (LOWORD(wParam))
  218. {
  219. case IDC_BUTTON5:
  220. case IDC_SELBOX:
  221. case IDC_BUTTON4: // open
  222. if (LOWORD(wParam) != IDC_SELBOX || HIWORD(wParam) == LBN_DBLCLK)
  223. {
  224. int x,len,openDir=0;
  225. char fn[MAX_PATH] = {0};
  226. FILE *fp;
  227. Bookmark_getfn(fn);
  228. fp=fopen(fn,"rt");
  229. if (fp)
  230. {
  231. len=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCOUNT,0,0);
  232. for (x = 0; x < len; x ++)
  233. {
  234. char ft[4096] = {0};
  235. fgets(fn,MAX_PATH,fp);
  236. fgets(ft,4096,fp);
  237. if (feof(fp)) break;
  238. if (SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETSEL,x,0))
  239. {
  240. if (ft[0] && fn[0])
  241. {
  242. if (fn[lstrlen(fn)-1]=='\n') fn[lstrlen(fn)-1]=0;
  243. if (ft[lstrlen(ft)-1]=='\n') ft[lstrlen(ft)-1]=0;
  244. if (ft[0] && fn[0])
  245. {
  246. if (!strstr(fn,"http://"))
  247. {
  248. int ga=GetFileAttributes(fn);
  249. if ((ga!=0xffffffff) && (ga & FILE_ATTRIBUTE_DIRECTORY))
  250. {
  251. getNewFile((LOWORD(wParam) != IDC_BUTTON5),hwndDlg,fn);
  252. openDir=1;
  253. }
  254. }
  255. if(!openDir)
  256. {
  257. if (LOWORD(wParam) != IDC_BUTTON5) PlayList_delete();
  258. PlayList_appendthing(fn);
  259. }
  260. }
  261. }
  262. }
  263. }
  264. if (LOWORD(wParam) != IDC_BUTTON5 && !openDir)
  265. {
  266. if (config_shuffle) PlayList_randpos(-BIGINT);
  267. else PlayList_setposition(0);
  268. PlayList_getcurrent(FileName,FileTitle,FileTitleNum);
  269. plEditRefresh();
  270. StartPlaying();
  271. }
  272. else
  273. plEditRefresh();
  274. fclose(fp);
  275. }
  276. }
  277. return 0;
  278. case IDC_EDITBOOK:
  279. {
  280. int sel=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  281. if (sel != LB_ERR)
  282. {
  283. int x;
  284. char fn[MAX_PATH] = {0};
  285. FILE *fp,*fpo;
  286. Bookmark_getfn(fn);
  287. fp=fopen(fn,"rt");
  288. fpo=fopen(TEMP_FILE,"wt");
  289. if (fp&&fpo)
  290. {
  291. x=0;
  292. while (1)
  293. {
  294. char ft[4096] = {0};
  295. fgets(fn,MAX_PATH,fp);
  296. fgets(ft,4096,fp);
  297. if (feof(fp)) break;
  298. if (fn[lstrlen(fn)-1]=='\n') fn[lstrlen(fn)-1]=0;
  299. if (ft[lstrlen(ft)-1]=='\n') ft[lstrlen(ft)-1]=0;
  300. if (x==sel)
  301. {
  302. g_bmedit_fn=fn;
  303. g_bmedit_ft=ft;
  304. LPDialogBox(IDD_EDITBOOKMARK,hwndDlg,BookMarkEditProc);
  305. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,x,0);
  306. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_INSERTSTRING,x,(LPARAM)ft);
  307. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,x,0);
  308. }
  309. fprintf(fpo,"%s\n%s\n",fn,ft);
  310. x++;
  311. }
  312. }
  313. if (fp) fclose(fp);
  314. if (fpo) fclose(fpo);
  315. if (fp && fpo)
  316. {
  317. Bookmark_getfn(fn);
  318. DeleteFile(fn);
  319. MoveFile(TEMP_FILE,fn);
  320. }
  321. }
  322. }
  323. return 0;
  324. case IDC_BUTTON1: // remove
  325. {
  326. int sel=SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_GETCURSEL,0,0);
  327. if (sel != LB_ERR) {
  328. char fn[MAX_PATH] = {0};
  329. FILE *fp,*fpo;
  330. Bookmark_getfn(fn);
  331. fp=fopen(fn,"rt");
  332. fpo=fopen(TEMP_FILE,"wt");
  333. if (fp&&fpo)
  334. {
  335. int l=0;
  336. int x=0;
  337. while (1)
  338. {
  339. char ft[4096] = {0};
  340. fgets(fn,MAX_PATH,fp);
  341. fgets(ft,4096,fp);
  342. if (feof(fp)) break;
  343. if (x == sel)
  344. {
  345. l=x-1;
  346. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_DELETESTRING,x,0);
  347. }
  348. else
  349. {
  350. fprintf(fpo,"%s%s",fn,ft);
  351. }
  352. x++;
  353. }
  354. SendDlgItemMessage(hwndDlg,IDC_SELBOX,LB_SETCURSEL,l,0);
  355. }
  356. if (fp) fclose(fp);
  357. if (fpo) fclose(fpo);
  358. if (fp && fpo)
  359. {
  360. Bookmark_getfn(fn);
  361. DeleteFile(fn);
  362. MoveFile(TEMP_FILE,fn);
  363. }
  364. }
  365. }
  366. break;
  367. }
  368. return FALSE;
  369. }
  370. return 0;
  371. }
  372. #endif