cmdline.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  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 "resource.h"
  10. #include "strutil.h"
  11. #include "../nu/AutoChar.h"
  12. #include "../nu/AutoWide.h"
  13. #include "../nu/ns_wc.h"
  14. #include "api.h"
  15. #include "main.hpp"
  16. #include "MergePlaylist.h"
  17. static HWND find_otherwinamp_fast()
  18. {
  19. wchar_t buf[MAX_PATH] = {0};
  20. StringCchPrintfW(buf, MAX_PATH, L"%s_%x_CLASS", szAppName, APP_VERSION_NUM);
  21. HANDLE waitEvent = OpenEventW(EVENT_ALL_ACCESS, FALSE, buf);
  22. if (waitEvent)
  23. {
  24. HWND lhwnd = 0;
  25. CloseHandle(waitEvent);
  26. while (NULL != (lhwnd = FindWindowExW(NULL, lhwnd, szAppName, NULL)))
  27. {
  28. if (lhwnd != hMainWindow)
  29. return lhwnd;
  30. }
  31. }
  32. return NULL;
  33. }
  34. wchar_t *EatSpaces(wchar_t *cmdLine)
  35. {
  36. while (cmdLine && *cmdLine && *cmdLine == L' ')
  37. cmdLine = CharNextW(cmdLine);
  38. return cmdLine;
  39. }
  40. static const wchar_t *EatSpaces(const wchar_t *cmdLine)
  41. {
  42. while (cmdLine && *cmdLine && *cmdLine == L' ')
  43. cmdLine = CharNextW(cmdLine);
  44. return cmdLine;
  45. }
  46. wchar_t *FindNextCommand(wchar_t *cmdLine)
  47. {
  48. int inQuotes = 0;
  49. while (cmdLine && *cmdLine)
  50. {
  51. if (*cmdLine == L' ' && !inQuotes) // if we see a space (and we're not in quotes) then we're done
  52. {
  53. // we purposefully don't eat any extra space characters here
  54. // that way we can null terminate the results of this function and get a clean string
  55. break;
  56. }
  57. else if (*cmdLine == L'\"') // check for quotes
  58. {
  59. inQuotes = !inQuotes; // toggles quotes mode
  60. }
  61. cmdLine = CharNextW(cmdLine); // iterate the string
  62. }
  63. return cmdLine;
  64. }
  65. void GetParameter(const wchar_t *commandLine, wchar_t *yourBuffer, size_t yourBufferSize)
  66. {
  67. int inQuotes = 0;
  68. commandLine = EatSpaces(commandLine);
  69. for(;;)
  70. {
  71. if (yourBufferSize == 1 // buffer is out
  72. || *commandLine == 0 // out of stuff to copy
  73. || (*commandLine == L' ' && !inQuotes)) // or we found a space
  74. {
  75. *yourBuffer = 0;
  76. break;
  77. }
  78. else if (*commandLine == L'\"') // don't copy quotes
  79. {
  80. inQuotes = !inQuotes; // but do toggle the quote flag (so we can ignore spaces)
  81. }
  82. else // safe character to copy
  83. {
  84. *yourBuffer++ = *commandLine;
  85. yourBufferSize--;
  86. }
  87. commandLine++;
  88. }
  89. }
  90. bool IsCommand(const wchar_t *cmdline, const wchar_t *str, size_t size)
  91. {
  92. if (!_wcsnicmp(cmdline, str, size) && (!cmdline[size] || cmdline[size] == L' '))
  93. return true;
  94. else
  95. return false;
  96. }
  97. static void createPlayListDBFileName(wchar_t *filename)
  98. {
  99. int x = 32;
  100. for (;;)
  101. {
  102. GetTempFileNameW(M3UDIR, L"plf", GetTickCount() + x*5000, filename);
  103. if (lstrlenW(filename) > 4)
  104. {
  105. PathRemoveExtensionW(filename);
  106. PathAddExtensionW(filename, L".m3u8");
  107. }
  108. HANDLE h = CreateFileW(filename, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, 0, 0);
  109. if (h != INVALID_HANDLE_VALUE)
  110. {
  111. CloseHandle(h);
  112. break;
  113. }
  114. if (++x > 4096)
  115. {
  116. break;
  117. }
  118. }
  119. }
  120. #if 0
  121. #ifdef BETA
  122. void ParseParametersExpired(wchar_t *lpszCmdParam)
  123. {
  124. lpszCmdParam = EatSpaces(lpszCmdParam);
  125. if (IsCommand(lpszCmdParam, L"/UNREG", 6))
  126. {
  127. char ext_list[8192] = {0};
  128. char *a = ext_list;
  129. void _r_s(char *name, char *data, int mlen);
  130. CoInitialize(0);
  131. setup_config();
  132. Wasabi_Load();
  133. w5s_init();
  134. ext_list[0] = 0;
  135. _r_s("config_extlist", ext_list, sizeof(ext_list));
  136. while (a && *a)
  137. {
  138. char *p = strstr(a, ":");
  139. if (p) *p++ = 0;
  140. config_register(a, 0);
  141. a = p;
  142. }
  143. wchar_t playlistExtensions[1024] = {0};
  144. playlistManager->GetExtensionList(playlistExtensions, 1024);
  145. wchar_t *p = playlistExtensions;
  146. while (p && *p)
  147. {
  148. config_register(AutoChar(p), 0);
  149. p += lstrlenW(p) + 1;
  150. }
  151. a = "wsz\0wpz\0wal\0wlz\0";
  152. while (a && *a)
  153. {
  154. config_register(a, 0);
  155. a += lstrlen(a) + 1;
  156. }
  157. config_regcdplayer(0);
  158. if (config_isdircontext()) config_removedircontext();
  159. config_registermediaplayer(0);
  160. w5s_deinit(NULL);
  161. Wasabi_Unload();
  162. SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL);
  163. RemoveRegistrar();
  164. ExitProcess(0);
  165. }
  166. }
  167. #endif
  168. #endif
  169. void* LoadResource(HINSTANCE hinst, HINSTANCE owner, LPCTSTR lpType, LPCTSTR lpName, DWORD* size)
  170. {
  171. HINSTANCE hmod = hinst;
  172. HRSRC rsrc = FindResource(hmod, lpName, lpType);
  173. if(!rsrc)
  174. {
  175. hmod = owner;
  176. rsrc = FindResource(hmod, lpName, lpType);
  177. }
  178. if(rsrc)
  179. {
  180. HGLOBAL resourceHandle = LoadResource(hmod, rsrc);
  181. if(size){*size = SizeofResource(hmod, rsrc);}
  182. return LockResource(resourceHandle);
  183. }
  184. return 0;
  185. }
  186. static LRESULT WINAPI cmdLineProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  187. {
  188. switch (uMsg)
  189. {
  190. case WM_INITDIALOG:
  191. {
  192. HICON hIcon = LoadIconW(hMainInstance, MAKEINTRESOURCE(ICON_XP));
  193. SetClassLongPtrW(hwndDlg, GCLP_HICON, (LONG_PTR)hIcon);
  194. char *b = NULL, *p = 0, *op = 0;
  195. DWORD size = 0;
  196. HGLOBAL hResource = LoadResource(hMainInstance, hMainInstance, TEXT("TEXT"), TEXT("CMDLINE"), &size);
  197. p = (char*)hResource;
  198. if (p && (op = strstr(p, "!!End"))) // if there's "!!End" in the resource, than copy everything before it
  199. {
  200. b = (char*)GlobalAlloc(GPTR, op-p+1);
  201. memcpy(b, p, op-p);
  202. b[op-p] = 0;
  203. } else {
  204. b = (char*)GlobalAlloc(GPTR, size+1);
  205. if (b && p)
  206. {
  207. memcpy(b, p, size);
  208. b[size] = 0;
  209. }
  210. }
  211. SetDlgItemTextA(hwndDlg, IDC_CMDLINE, (b ? b : p)); // send it to the text control to display
  212. if (b) GlobalFree(b);
  213. SetFocus(GetDlgItem(hwndDlg, IDC_CMDLINE));
  214. }
  215. return FALSE;
  216. case WM_COMMAND:
  217. {
  218. switch (LOWORD(wParam))
  219. {
  220. case IDCANCEL:
  221. case IDOK:
  222. DestroyWindow(hwndDlg);
  223. return FALSE;
  224. }
  225. }
  226. break;
  227. }
  228. return 0;
  229. }
  230. wchar_t *ParseParameters(wchar_t *lpszCmdParam, int *bAdd, int *bBookmark, int *bHandle, int *nCmdShow, int *bCommand, int *bCmdParam, int *bAllowCompat)
  231. {
  232. for (;;)
  233. {
  234. lpszCmdParam = EatSpaces(lpszCmdParam);
  235. if (IsCommand(lpszCmdParam, L"-embedding", 10))
  236. {
  237. lpszCmdParam = SkipXW(lpszCmdParam, 10);
  238. }
  239. else if (IsCommand(lpszCmdParam, L"/ALLOW_COMPAT_MODE", 18))
  240. {
  241. lpszCmdParam = SkipXW(lpszCmdParam, 18);
  242. *bAllowCompat = 1;
  243. }
  244. else if (!_wcsnicmp(lpszCmdParam, L"/SAFE=", 6))
  245. {
  246. wchar_t p[1024] = {0};
  247. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  248. GetParameter(lpszCmdParam, p, 1024);
  249. int mode = _wtoi(p);
  250. g_safeMode = (1 + (mode == 2));
  251. }
  252. else if (!_wcsnicmp(lpszCmdParam, L"/SAFEALWAYS", 11))
  253. {
  254. lpszCmdParam = SkipXW(lpszCmdParam, 11);
  255. g_safeMode = 3;
  256. }
  257. else if (IsCommand(lpszCmdParam, L"/?", 2))
  258. {
  259. DialogBoxW(hMainInstance, MAKEINTRESOURCEW(IDD_CMDLINE), 0, (DLGPROC)cmdLineProc);
  260. ExitProcess(0);
  261. }
  262. else if (IsCommand(lpszCmdParam, L"/NEW", 4))
  263. {
  264. lpszCmdParam = SkipXW(lpszCmdParam, 4);
  265. bNoHwndOther = 1;
  266. }
  267. else if (IsCommand(lpszCmdParam, L"/HANDLE", 7))
  268. {
  269. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  270. *bHandle = 1;
  271. }
  272. else if (!_wcsnicmp(lpszCmdParam, L"/REG=", 5))
  273. {
  274. wchar_t p[1024] = {0};
  275. wchar_t *pItr = p;
  276. lpszCmdParam = SkipXW(lpszCmdParam, 5);
  277. GetParameter(lpszCmdParam, p, 1024);
  278. is_install = 1;
  279. while (pItr && *pItr)
  280. {
  281. // changed 5.64 - cope with upper + lowercase
  282. // if the commands are done that way as well
  283. switch (*pItr)
  284. {
  285. case L'A': case L'a': is_install |= 2; break; //2=audiotype
  286. case L'V': case L'v': is_install |= 4; break; //4=videotype
  287. case L'C': case L'c': is_install |= 8; break; //8=cd
  288. case L'N': case L'n': is_install |= 16; break; //16=set needreg=1
  289. case L'D': case L'd': is_install |= 32; break; //32=dircontextmenus
  290. case L'L': case L'l': is_install |= 64; break; //64=playlisttype
  291. case L'S': case L's': is_install |= 128; break; //128=setupwizard
  292. }
  293. pItr = CharNextW(pItr);
  294. }
  295. }
  296. else if (IsCommand(lpszCmdParam, L"/NOREG", 6))
  297. {
  298. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  299. g_noreg = 1;
  300. }
  301. else if (IsCommand(lpszCmdParam, L"/UNREG", 6))
  302. {
  303. wchar_t ext_list[16384] = {0};
  304. wchar_t *a = ext_list;
  305. void _r_sW(const char *name, wchar_t *data, int mlen);
  306. CoInitialize(0);
  307. setup_config();
  308. Wasabi_Load();
  309. w5s_init();
  310. _r_sW("config_extlist", ext_list, ARRAYSIZE(ext_list));
  311. while (a && *a)
  312. {
  313. wchar_t *p = wcsstr(a, L":");
  314. if (p) *p++ = 0;
  315. config_register(a, 0);
  316. a = p;
  317. }
  318. wchar_t playlistExtensions[1024] = {0};
  319. playlistManager->GetExtensionList(playlistExtensions, 1024);
  320. wchar_t *p = playlistExtensions;
  321. while (p && *p)
  322. {
  323. config_register(p, 0);
  324. p += lstrlenW(p) + 1;
  325. }
  326. a = L"wsz\0wpz\0wal\0wlz\0";
  327. while (a && *a)
  328. {
  329. config_register(a, 0);
  330. a += lstrlenW(a) + 1;
  331. }
  332. config_regcdplayer(0, 0);
  333. if (config_isdircontext()) config_removedircontext(0);
  334. config_registermediaplayer(0);
  335. w5s_deinit();
  336. Wasabi_Unload();
  337. SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL);
  338. RemoveRegistrar();
  339. ExitProcess(0);
  340. }
  341. else if (!_wcsnicmp(lpszCmdParam, L"/ADD", 4) && (!lpszCmdParam[4] || lpszCmdParam[4] == L' '))
  342. {
  343. lpszCmdParam = SkipXW(lpszCmdParam, 4);
  344. *bAdd = 1;
  345. }
  346. else if (!_wcsnicmp(lpszCmdParam, L"/ADDPLAYLIST", 12) && (!lpszCmdParam[12] || lpszCmdParam[12] == L' '))
  347. {
  348. // winamp.exe /ADDPLAYLIST playlist.m3u "Playlist Name" {GUID}
  349. lpszCmdParam = SkipXW(lpszCmdParam, 12);
  350. setup_config();
  351. Wasabi_Load();
  352. w5s_init();
  353. if (AGAVE_API_PLAYLISTS)
  354. {
  355. config_read(1);
  356. wchar_t playlist_filename[MAX_PATH] = {0};
  357. wchar_t playlist_guid_str[256] = {0};
  358. GUID playlist_guid = INVALID_GUID;
  359. GetParameter(lpszCmdParam, playlist_filename, MAX_PATH);
  360. if (playlist_filename[0])
  361. {
  362. wchar_t playlist_name[256] = {0};
  363. lpszCmdParam = EatSpaces(lpszCmdParam);
  364. lpszCmdParam = FindNextCommand(lpszCmdParam);
  365. GetParameter(lpszCmdParam, playlist_name, 256);
  366. lpszCmdParam = EatSpaces(lpszCmdParam);
  367. lpszCmdParam = FindNextCommand(lpszCmdParam);
  368. GetParameter(lpszCmdParam, playlist_guid_str, 256);
  369. if (playlist_name[0] == 0)
  370. StringCchCopyW(playlist_name, 256, PathFindFileNameW(playlist_filename));
  371. if (playlist_guid_str[0] != 0)
  372. {
  373. int skip = playlist_guid_str[0] == L'{';
  374. playlist_guid_str[37]=0;
  375. UuidFromStringW((RPC_WSTR)(&playlist_guid_str[skip]), (UUID *)&playlist_guid);
  376. }
  377. AGAVE_API_PLAYLISTS->AddPlaylist(playlist_filename, playlist_name, playlist_guid);
  378. AGAVE_API_PLAYLISTS->Flush();
  379. w5s_deinit();
  380. Wasabi_Unload();
  381. ExitProcess(0);
  382. }
  383. }
  384. w5s_deinit();
  385. Wasabi_Unload();
  386. ExitProcess(1);
  387. }
  388. else if (!_wcsnicmp(lpszCmdParam, L"/CREATEPLAYLIST", 15) && (!lpszCmdParam[15] || lpszCmdParam[15] == L' '))
  389. {
  390. // winamp.exe /CREATEPLAYLIST "Playlist Name" {GUID}
  391. lpszCmdParam = SkipXW(lpszCmdParam, 15);
  392. setup_config();
  393. Wasabi_Load();
  394. w5s_init();
  395. if (AGAVE_API_PLAYLISTS)
  396. {
  397. config_read(1);
  398. wchar_t playlist_name[256] = {0};
  399. wchar_t playlist_guid_str[256] = {0};
  400. GUID playlist_guid = INVALID_GUID;
  401. GetParameter(lpszCmdParam, playlist_name, 256);
  402. if (playlist_name[0])
  403. {
  404. lpszCmdParam = EatSpaces(lpszCmdParam);
  405. lpszCmdParam = FindNextCommand(lpszCmdParam);
  406. GetParameter(lpszCmdParam, playlist_guid_str, 256);
  407. if (playlist_guid_str[0] != 0)
  408. {
  409. int skip = playlist_guid_str[0] == L'{';
  410. playlist_guid_str[37]=0;
  411. UuidFromStringW((RPC_WSTR)(&playlist_guid_str[skip]), (UUID *)&playlist_guid);
  412. }
  413. if (playlist_guid != INVALID_GUID)
  414. {
  415. size_t existing_playlist_index;
  416. // check for duplicate GUID
  417. if (AGAVE_API_PLAYLISTS->GetPosition(playlist_guid, &existing_playlist_index) != API_PLAYLISTS_SUCCESS)
  418. {
  419. wchar_t playlist_filename[MAX_PATH] = {0};
  420. createPlayListDBFileName(playlist_filename); // generate filename
  421. AGAVE_API_PLAYLISTS->AddPlaylist(playlist_filename, playlist_name, playlist_guid);
  422. AGAVE_API_PLAYLISTS->Flush();
  423. }
  424. }
  425. w5s_deinit();
  426. Wasabi_Unload();
  427. ExitProcess(0);
  428. }
  429. }
  430. w5s_deinit();
  431. Wasabi_Unload();
  432. ExitProcess(1);
  433. }
  434. else if (!_wcsnicmp(lpszCmdParam, L"/APPENDPLAYLIST", 15) && (!lpszCmdParam[15] || lpszCmdParam[15] == L' '))
  435. {
  436. // winamp.exe /APPENDPLAYLIST {GUID} filename.mp3
  437. lpszCmdParam = SkipXW(lpszCmdParam, 15);
  438. setup_config();
  439. Wasabi_Load();
  440. w5s_init();
  441. if (AGAVE_API_PLAYLISTS && AGAVE_API_PLAYLISTMANAGER)
  442. {
  443. config_read(1);
  444. wchar_t playlist_guid_str[256] = {0};
  445. GUID playlist_guid = INVALID_GUID;
  446. GetParameter(lpszCmdParam, playlist_guid_str, 256);
  447. if (playlist_guid_str[0])
  448. {
  449. wchar_t filename[MAX_PATH] = {0};
  450. const wchar_t *playlist_filename;
  451. lpszCmdParam = EatSpaces(lpszCmdParam);
  452. lpszCmdParam = FindNextCommand(lpszCmdParam);
  453. GetParameter(lpszCmdParam, filename, MAX_PATH);
  454. int skip = playlist_guid_str[0] == L'{';
  455. playlist_guid_str[37]=0;
  456. UuidFromStringW((RPC_WSTR)(&playlist_guid_str[skip]), (UUID *)&playlist_guid);
  457. MergePlaylist merged_playlist;
  458. size_t playlist_index;
  459. // get playlist filename from AGAVE_API_PLAYLISTS
  460. if (AGAVE_API_PLAYLISTS->GetPosition(playlist_guid, &playlist_index) == API_PLAYLISTS_SUCCESS
  461. && (NULL != (playlist_filename = AGAVE_API_PLAYLISTS->GetFilename(playlist_index))))
  462. {
  463. // load playlist into merge_playlist
  464. if (AGAVE_API_PLAYLISTMANAGER->Load(playlist_filename, &merged_playlist) == PLAYLISTMANAGER_SUCCESS)
  465. {
  466. MergePlaylist appended_playlist;
  467. // if filename is a playlist, load it
  468. if (AGAVE_API_PLAYLISTMANAGER->Load(filename, &appended_playlist) == PLAYLISTMANAGER_SUCCESS)
  469. {
  470. merged_playlist.AppendPlaylist(appended_playlist);
  471. }
  472. else if (PathIsDirectoryW(filename))
  473. { // if it's a directory
  474. AGAVE_API_PLAYLISTMANAGER->LoadDirectory(filename, &appended_playlist, 0);
  475. merged_playlist.AppendPlaylist(appended_playlist);
  476. }
  477. else
  478. {
  479. // TODO: get metadata, but we don't have any plugins loaded
  480. if (!merged_playlist.HasFilename(filename))
  481. merged_playlist.AppendWithInfo(filename, 0, -1);
  482. }
  483. if (AGAVE_API_PLAYLISTMANAGER->Save(playlist_filename, &merged_playlist) == PLAYLISTMANAGER_SUCCESS)
  484. {
  485. size_t num_items = merged_playlist.GetNumItems();
  486. AGAVE_API_PLAYLISTS->SetInfo(playlist_index, api_playlists_itemCount, &num_items, sizeof(num_items));
  487. uint64_t total_time = merged_playlist.total_time/1000ULL;
  488. AGAVE_API_PLAYLISTS->SetInfo(playlist_index, api_playlists_totalTime, &total_time, sizeof(total_time));
  489. AGAVE_API_PLAYLISTS->Flush();
  490. }
  491. }
  492. }
  493. w5s_deinit();
  494. Wasabi_Unload();
  495. ExitProcess(0);
  496. }
  497. }
  498. w5s_deinit();
  499. Wasabi_Unload();
  500. ExitProcess(1);
  501. }
  502. else if (!_wcsnicmp(lpszCmdParam, L"/ENUMPLAYLISTS", 14))
  503. {
  504. setup_config();
  505. Wasabi_Load();
  506. w5s_init();
  507. if (AGAVE_API_PLAYLISTS)
  508. {
  509. size_t count = AGAVE_API_PLAYLISTS->GetCount();
  510. if (count > 0)
  511. {
  512. for (size_t index = 0; index < count; index++)
  513. {
  514. GUID guid = AGAVE_API_PLAYLISTS->GetGUID(index);
  515. fprintf(stdout, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X},%s,%s\n",
  516. (int)guid.Data1, (int)guid.Data2, (int)guid.Data3,
  517. (int)guid.Data4[0], (int)guid.Data4[1], (int)guid.Data4[2],
  518. (int)guid.Data4[3], (int)guid.Data4[4], (int)guid.Data4[5],
  519. (int)guid.Data4[6], (int)guid.Data4[7],
  520. (char*)(AutoChar(AGAVE_API_PLAYLISTS->GetFilename(index), CP_UTF8)),
  521. (char*)(AutoChar(AGAVE_API_PLAYLISTS->GetName(index), CP_UTF8)));
  522. }
  523. fflush(stdout);
  524. }
  525. w5s_deinit();
  526. Wasabi_Unload();
  527. ExitProcess(0);
  528. }
  529. w5s_deinit();
  530. Wasabi_Unload();
  531. ExitProcess(1);
  532. }
  533. else if (!_wcsnicmp(lpszCmdParam, L"/BOOKMARK", 9) && (!lpszCmdParam[9] || lpszCmdParam[9] == L' '))
  534. {
  535. lpszCmdParam = SkipXW(lpszCmdParam, 9);
  536. *bBookmark = 1;
  537. }
  538. else if (!_wcsnicmp(lpszCmdParam, L"/CONFIG=", 8))
  539. {
  540. wchar_t p[1024] = {0};
  541. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  542. GetParameter(lpszCmdParam, p, 1024);
  543. config_setinifile(p);
  544. }
  545. else if (!_wcsnicmp(lpszCmdParam, L"/INIDIR=", 8))
  546. {
  547. wchar_t p[1024] = {0};
  548. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  549. GetParameter(lpszCmdParam, p, 1024);
  550. config_setinidir(p);
  551. }
  552. else if (!_wcsnicmp(lpszCmdParam, L"/M3UDIR=", 8))
  553. {
  554. wchar_t p[1024] = {0};
  555. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  556. GetParameter(lpszCmdParam, p, 1024);
  557. config_setm3udir(p);
  558. }
  559. else if (!_wcsnicmp(lpszCmdParam, L"/CLASS=", 7))
  560. {
  561. wchar_t p[1024] = {0};
  562. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  563. GetParameter(lpszCmdParam, p, 1024);
  564. StringCchCopyW(szAppName, 64, p);
  565. }
  566. else if (IsCommand(lpszCmdParam, L"/DELM3U", 7))
  567. {
  568. setup_config();
  569. DeleteFileW(M3U_FILE);
  570. DeleteFileW(OLD_M3U_FILE);
  571. RemoveRegistrar();
  572. ExitProcess(0);
  573. }
  574. else if (IsCommand(lpszCmdParam, L"/QUIT", 5) ||
  575. IsCommand(lpszCmdParam, L"/EXIT", 5) ||
  576. IsCommand(lpszCmdParam, L"/CLOSE", 6))
  577. {
  578. lpszCmdParam = SkipXW(lpszCmdParam, 5 + IsCommand(lpszCmdParam, L"/CLOSE", 6));
  579. HWND hwnd_other_winamp = find_otherwinamp_fast();
  580. if (IsWindow(hwnd_other_winamp))
  581. PostMessageW(hwnd_other_winamp, WM_CLOSE, 0, 0);
  582. ExitProcess(0);
  583. }
  584. else if (IsCommand(lpszCmdParam, L"/KILL", 5))
  585. {
  586. HWND hwnd_other_winamp;
  587. DWORD other_winamp_procId = 0;
  588. lpszCmdParam = SkipXW(lpszCmdParam, 5);
  589. hwnd_other_winamp = find_otherwinamp_fast();
  590. if (hwnd_other_winamp)
  591. {
  592. PostMessageW(hwnd_other_winamp, WM_CLOSE, 0, 0);
  593. GetWindowThreadProcessId(hwnd_other_winamp, &other_winamp_procId); // get the process ID
  594. if (other_winamp_procId) // if we didn't get one, it probably already handled the WM_CLOSE message ...
  595. {
  596. HANDLE other_winamp_process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE | SYNCHRONIZE, FALSE, other_winamp_procId);
  597. if (other_winamp_process) // if we got a process handle (it might have quit already in the meantime ...)
  598. {
  599. if (WaitForSingleObject(other_winamp_process, 3000) == WAIT_TIMEOUT) // wait 5 seconds for it to close
  600. {
  601. DWORD exitCode = 0;
  602. TerminateProcess(other_winamp_process, exitCode); // terminate if we timed out
  603. WaitForSingleObject(other_winamp_process, 1000); // wait some more because TerminateProcess() returns immediately
  604. }
  605. CloseHandle(other_winamp_process); // release our reference to the handle
  606. }
  607. }
  608. }
  609. RemoveRegistrar();
  610. ExitProcess(0);
  611. }
  612. /*else if (!_wcsnicmp(lpszCmdParam, L"/RETURN=", 8))
  613. {
  614. wchar_t p[40] = {0};
  615. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  616. GetParameter(lpszCmdParam, p, 40);
  617. ExitProcess(_wtoi(p));
  618. }*/
  619. #ifndef _WIN64
  620. #ifdef BURN_SUPPORT
  621. else if (!_wcsnicmp(lpszCmdParam, L"/BURN=", 6))
  622. {
  623. wchar_t p[1024] = {0};
  624. unsigned int retCode;
  625. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  626. GetParameter(lpszCmdParam, p, 1024);
  627. CoInitialize(0);
  628. setup_config();
  629. Wasabi_Load();
  630. SpectralAnalyzer_Create();
  631. w5s_init(NULL);
  632. in_init(NULL);
  633. config_read(1);
  634. retCode = burn_doBurn(AutoChar(p), hMainWindow, hMainInstance);
  635. in_deinit(NULL);
  636. w5s_deinit(NULL);
  637. Wasabi_Unload();
  638. SpectralAnalyzer_Destroy();
  639. RemoveRegistrar();
  640. ExitProcess(retCode);
  641. }
  642. #endif
  643. #endif
  644. /*else if (!_wcsnicmp(lpszCmdParam, L"/WATCHER", 8))
  645. {
  646. wchar_t p[2048] = {0};
  647. lpszCmdParam = SkipXW(lpszCmdParam, 9);
  648. GetParameter(lpszCmdParam, p, 2048);
  649. // eat parameter for now...
  650. RemoveRegistrar();
  651. ExitProcess(0); // and do not do anything...
  652. }*/
  653. else if (IsCommand(lpszCmdParam, L"/STARTMIN", 9))
  654. {
  655. lpszCmdParam = SkipXW(lpszCmdParam, 10);
  656. *nCmdShow = SW_MINIMIZE;
  657. }
  658. else if (IsCommand(lpszCmdParam, L"/STARTMAX", 9))
  659. {
  660. lpszCmdParam = SkipXW(lpszCmdParam, 10);
  661. *nCmdShow = SW_RESTORE;
  662. }
  663. else if (IsCommand(lpszCmdParam, L"/PREV", 5))
  664. {
  665. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  666. *bCommand = MAKEWPARAM(WINAMP_BUTTON1, 0);
  667. }
  668. else if (IsCommand(lpszCmdParam, L"/PLAY", 5))
  669. {
  670. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  671. *bCommand = MAKEWPARAM(WINAMP_BUTTON2, 0);
  672. }
  673. else if (IsCommand(lpszCmdParam, L"/PAUSE", 6))
  674. {
  675. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  676. *bCommand = MAKEWPARAM(WINAMP_BUTTON3, 0);
  677. }
  678. else if (IsCommand(lpszCmdParam, L"/STOP", 5))
  679. {
  680. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  681. *bCommand = MAKEWPARAM(WINAMP_BUTTON4, 0);
  682. }
  683. else if (IsCommand(lpszCmdParam, L"/STOPFADE", 9))
  684. {
  685. lpszCmdParam = SkipXW(lpszCmdParam, 10);
  686. *bCommand = MAKEWPARAM(WINAMP_BUTTON4_SHIFT, 0);
  687. }
  688. else if (IsCommand(lpszCmdParam, L"/STOPAFTER", 10))
  689. {
  690. lpszCmdParam = SkipXW(lpszCmdParam, 11);
  691. *bCommand = MAKEWPARAM(WINAMP_BUTTON4_CTRL, 0);
  692. }
  693. else if (IsCommand(lpszCmdParam, L"/NEXT", 5))
  694. {
  695. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  696. *bCommand = MAKEWPARAM(WINAMP_BUTTON5, 0);
  697. }
  698. else if (IsCommand(lpszCmdParam, L"/PLAYPAUSE", 10))
  699. {
  700. lpszCmdParam = SkipXW(lpszCmdParam, 10);
  701. *bCommand = MAKEWPARAM(IPC_ISPLAYING, 2);
  702. }
  703. else if (IsCommand(lpszCmdParam, L"/FWD", 4))
  704. {
  705. lpszCmdParam = SkipXW(lpszCmdParam, 4);
  706. *bCommand = MAKEWPARAM(WINAMP_BUTTON5_SHIFT, 0);
  707. }
  708. else if (IsCommand(lpszCmdParam, L"/REV", 4))
  709. {
  710. lpszCmdParam = SkipXW(lpszCmdParam, 4);
  711. *bCommand = MAKEWPARAM(WINAMP_BUTTON1_SHIFT, 0);
  712. }
  713. else if (!_wcsnicmp(lpszCmdParam, L"/CD", 3)) // CD<[0]-3>
  714. {
  715. wchar_t p[3] = {0};
  716. lpszCmdParam = SkipXW(lpszCmdParam, 3);
  717. GetParameter(lpszCmdParam, p, 3);
  718. // only allow 4 drives so we limit to g_audiocdletters
  719. int id = _wtoi(p);
  720. if (id >= 0 && id < 4)
  721. {
  722. *bCommand = MAKEWPARAM(ID_MAIN_PLAY_AUDIOCD + id, 0);
  723. }
  724. else
  725. ExitProcess(0);
  726. }
  727. else if (!_wcsnicmp(lpszCmdParam, L"/RANDOM=", 8))
  728. {
  729. wchar_t p[2] = {0};
  730. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  731. GetParameter(lpszCmdParam, p, 2);
  732. if (p[0] == '0') *bCmdParam = 0;
  733. else if (p[0] == '1') *bCmdParam = 1;
  734. *bCommand = MAKEWPARAM(IPC_SET_SHUFFLE, 1);
  735. }
  736. else if (IsCommand(lpszCmdParam, L"/RANDOM", 7))
  737. {
  738. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  739. *bCommand = MAKEWPARAM(WINAMP_FILE_SHUFFLE, 0);
  740. }
  741. else if (!_wcsnicmp(lpszCmdParam, L"/SHUFFLE=", 9))
  742. {
  743. wchar_t p[2] = {0};
  744. lpszCmdParam = SkipXW(lpszCmdParam, 9);
  745. GetParameter(lpszCmdParam, p, 2);
  746. if (p[0] == '0') *bCmdParam = 0;
  747. else if (p[0] == '1') *bCmdParam = 1;
  748. else break;
  749. *bCommand = MAKEWPARAM(IPC_SET_SHUFFLE, 1);
  750. }
  751. else if (IsCommand(lpszCmdParam, L"/SHUFFLE", 8))
  752. {
  753. lpszCmdParam = SkipXW(lpszCmdParam, 9);
  754. *bCommand = MAKEWPARAM(WINAMP_FILE_SHUFFLE, 0);
  755. }
  756. else if (!_wcsnicmp(lpszCmdParam, L"/REPEAT=", 8))
  757. {
  758. wchar_t p[2] = {0};
  759. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  760. GetParameter(lpszCmdParam, p, 2);
  761. if (p[0] == '0') *bCmdParam = 0;
  762. else if (p[0] == '1') *bCmdParam = 1;
  763. else break;
  764. *bCommand = MAKEWPARAM(IPC_SET_REPEAT, 1);
  765. }
  766. else if (IsCommand(lpszCmdParam, L"/REPEAT", 7))
  767. {
  768. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  769. *bCommand = MAKEWPARAM(WINAMP_FILE_REPEAT, 0);
  770. }
  771. else if (IsCommand(lpszCmdParam, L"/PANLEFT", 8))
  772. {
  773. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  774. *bCommand = MAKEWPARAM(EQ_PANLEFT, 2);
  775. }
  776. else if (IsCommand(lpszCmdParam, L"/PANRIGHT", 9))
  777. {
  778. lpszCmdParam = SkipXW(lpszCmdParam, 9);
  779. *bCommand = MAKEWPARAM(EQ_PANRIGHT, 2);
  780. }
  781. else if (!_wcsnicmp(lpszCmdParam, L"/PAN=", 5))
  782. {
  783. wchar_t p[5] = {0};
  784. lpszCmdParam = SkipXW(lpszCmdParam, 5);
  785. GetParameter(lpszCmdParam, p, 5);
  786. if (p[0])
  787. {
  788. *bCmdParam = _wtoi(p);
  789. *bCommand = MAKEWPARAM(IPC_SETPANNING, 2);
  790. }
  791. else
  792. ExitProcess(0);
  793. }
  794. else if (IsCommand(lpszCmdParam, L"/VOLUP", 6))
  795. {
  796. lpszCmdParam = SkipXW(lpszCmdParam, 6);
  797. *bCommand = MAKEWPARAM(WINAMP_VOLUMEUP, 0);
  798. }
  799. else if (IsCommand(lpszCmdParam, L"/VOLDOWN", 8))
  800. {
  801. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  802. *bCommand = MAKEWPARAM(WINAMP_VOLUMEDOWN, 0);
  803. }
  804. else if (!_wcsnicmp(lpszCmdParam, L"/VOL=", 5))
  805. {
  806. wchar_t p[4] = {0};
  807. lpszCmdParam = SkipXW(lpszCmdParam, 5);
  808. GetParameter(lpszCmdParam, p, 4);
  809. if (p[0])
  810. {
  811. int vol = _wtoi(p);
  812. if (vol < 0) vol = 0;
  813. if (vol > 100) vol = 100;
  814. *bCmdParam = ceil(vol * 2.55);
  815. *bCommand = MAKEWPARAM(IPC_SETVOLUME, 1);
  816. }
  817. else
  818. ExitProcess(0);
  819. }
  820. else if (IsCommand(lpszCmdParam, L"/JUMPTO", 7))
  821. {
  822. lpszCmdParam = SkipXW(lpszCmdParam, 8);
  823. *bCommand = MAKEWPARAM(WINAMP_JUMPFILE, 0);
  824. }
  825. else if (IsCommand(lpszCmdParam, L"/CLEAR", 6))
  826. {
  827. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  828. *bCommand = MAKEWPARAM(IPC_DELETE, 1);
  829. }
  830. else if (!_wcsnicmp(lpszCmdParam, L"/COMMAND=", 9))
  831. {
  832. wchar_t p[16] = {0};
  833. lpszCmdParam = SkipXW(lpszCmdParam, 9);
  834. GetParameter(lpszCmdParam, p, 16);
  835. int id = _wtoi(p);
  836. if (id > 0 && id < 65536)
  837. {
  838. *bCommand = MAKEWPARAM(id, 0);
  839. }
  840. else
  841. ExitProcess(0);
  842. }
  843. else if (!_wcsnicmp(lpszCmdParam, L"/WA_IPC", 7) && (!lpszCmdParam[7] || lpszCmdParam[7] == L' '))
  844. {
  845. wchar_t p[16] = {0};
  846. lpszCmdParam = SkipXW(lpszCmdParam, 7);
  847. GetParameter(lpszCmdParam, p, 16);
  848. int id = _wtoi(p);
  849. if (id > 0 && id <= 65536)
  850. {
  851. *bCommand = MAKEWPARAM(id, 1);
  852. if (lpszCmdParam && *lpszCmdParam)
  853. lpszCmdParam = CharNextW(lpszCmdParam);
  854. while (lpszCmdParam && *lpszCmdParam)
  855. {
  856. if (*lpszCmdParam == L' ') break;
  857. lpszCmdParam = CharNextW(lpszCmdParam);
  858. }
  859. wchar_t p2[16] = {0};
  860. GetParameter(lpszCmdParam, p2, 16);
  861. id = _wtoi(p2);
  862. if (id >= 0 && id <= 65536)
  863. {
  864. *bCmdParam = id;
  865. if (lpszCmdParam && *lpszCmdParam)
  866. lpszCmdParam = CharNextW(lpszCmdParam);
  867. while (lpszCmdParam && *lpszCmdParam)
  868. {
  869. if (*lpszCmdParam == L' ') break;
  870. lpszCmdParam = CharNextW(lpszCmdParam);
  871. }
  872. }
  873. else
  874. ExitProcess(0);
  875. }
  876. else
  877. ExitProcess(0);
  878. }
  879. else if (*lpszCmdParam == L'/') // ignore /options :)
  880. {
  881. lpszCmdParam = SkipXW(lpszCmdParam, 1);
  882. }
  883. else
  884. break;
  885. lpszCmdParam = FindNextCommand(lpszCmdParam);
  886. }
  887. return lpszCmdParam;
  888. }
  889. void parseCmdLine(wchar_t *cmdline, HWND hwnd)
  890. {
  891. wchar_t buf[MAX_PATH*4] = {0};
  892. wchar_t tmp[MAX_PATH] = {0};
  893. wchar_t *p;
  894. if (wcsstr(cmdline, L"/BOOKMARK") == cmdline)
  895. {
  896. wchar_t bookmark[1024] = {0};
  897. cmdline = SkipXW(cmdline, 9);
  898. GetParameter(cmdline, bookmark, 1024);
  899. COPYDATASTRUCT cds;
  900. cds.dwData = IPC_ADDBOOKMARKW;
  901. cds.lpData = (void *) bookmark;
  902. cds.cbData = sizeof(wchar_t)*(lstrlenW((wchar_t*) cds.lpData) + 1);
  903. SendMessageW(hwnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
  904. return ;
  905. }
  906. else if (wcsstr(cmdline, L"/HANDLE") == cmdline)
  907. {
  908. wchar_t uri[1024] = {0};
  909. cmdline = SkipXW(cmdline, 7);
  910. GetParameter(cmdline, uri, 1024);
  911. COPYDATASTRUCT cds;
  912. cds.dwData = IPC_HANDLE_URI;
  913. cds.lpData = (void *) uri;
  914. cds.cbData = sizeof(wchar_t)*(lstrlenW((wchar_t*) cds.lpData) + 1);
  915. SendMessageW(hwnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
  916. return ;
  917. }
  918. lstrcpynW(buf, cmdline, MAX_PATH*4);
  919. p = buf;
  920. wchar_t param[1024] = {0};
  921. while (p && *p)
  922. {
  923. p = EatSpaces(p);
  924. GetParameter(p, param, 1024);
  925. if (!hwnd)
  926. {
  927. PlayList_appendthing(param, 0, 0);
  928. }
  929. else
  930. {
  931. COPYDATASTRUCT cds;
  932. wchar_t *p2 = 0;
  933. if (!PathIsURLW(param) && GetFullPathNameW(param, MAX_PATH, tmp, &p2) && tmp[0])
  934. {
  935. cds.dwData = IPC_PLAYFILEW;
  936. cds.lpData = (void *) tmp;
  937. cds.cbData = sizeof(wchar_t)*(lstrlenW((wchar_t *) cds.lpData) + 1);
  938. SendMessageW(hwnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
  939. }
  940. else
  941. {
  942. cds.dwData = IPC_PLAYFILEW;
  943. cds.lpData = (void *) param;
  944. cds.cbData = sizeof(wchar_t) * (lstrlenW((wchar_t *) cds.lpData) + 1);
  945. SendMessageW(hwnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
  946. }
  947. }
  948. p = FindNextCommand(p);
  949. }
  950. } // parseCmdLine()
  951. wchar_t *CheckFileBase(wchar_t *lpszCmdParam, HWND hwnd_other, int *exit, int mode)
  952. {
  953. wchar_t buf[32] = {0};
  954. *exit=0;
  955. lstrcpynW(buf, extensionW(lpszCmdParam), 32);
  956. if (wcsstr(buf, L"\"")) wcsstr(buf, L"\"")[0] = 0;
  957. // process .wsz/.wal file or .wlz (depending on the mode enabled)
  958. if ((!mode && (!_wcsicmp(buf, L"wsz") || !_wcsicmp(buf, L"wal"))) || (mode && !_wcsicmp(buf, L"wlz")))
  959. {
  960. wchar_t *p = lpszCmdParam, buf[MAX_PATH] = {0}, buf2[MAX_PATH] = {0},
  961. outname[MAX_PATH] = {0}, current[MAX_PATH] = {0};
  962. while (p &&*p == L' ') p++;
  963. if (p && *p == L'\"') { p++; if (wcsstr(p, L"\"")) wcsstr(p, L"\"")[0] = 0; }
  964. // this is roughly equivalent to PathUndecorate, which we can't use because it requires IE 5.0+
  965. StringCchCopyW(outname, MAX_PATH, PathFindFileNameW(p));
  966. StringCchCopyW(buf, MAX_PATH, (!mode ? SKINDIR : LANGDIR));
  967. PathCombineW(buf2, buf, outname);
  968. void _r_sW(const char *name, wchar_t *data, int mlen);
  969. _r_sW((!mode ? "skin" : "langpack"), current, MAX_PATH);
  970. bool name_match = !_wcsicmp(outname, current);
  971. bool file_match = !_wcsicmp(p, buf2);
  972. //if (_wcsicmp(outname, current))
  973. if (!name_match || name_match && !file_match)
  974. {
  975. // prompt if the user is ok to install (subject to user preferences)
  976. int ret = IDYES;
  977. if (!mode ? config_skin_prompt : config_wlz_prompt)
  978. {
  979. ret = LPMessageBox(NULL, (!mode ? IDS_SKINS_INSTALL_PROMPT : IDS_LANG_INSTALL_PROMPT),
  980. (!mode ? IDS_SKINS_INSTALL_HEADER :IDS_LANG_INSTALL_HEADER),
  981. MB_YESNO | MB_ICONQUESTION);
  982. }
  983. if (ret != IDYES)
  984. {
  985. *exit = 1;
  986. return lpszCmdParam;
  987. }
  988. else
  989. {
  990. if(*exit == -2)
  991. {
  992. *exit = -1;
  993. }
  994. }
  995. {
  996. wchar_t *tmp;
  997. tmp = outname + lstrlenW(outname);
  998. size_t tmpsize = MAX_PATH - (tmp - outname);
  999. while (tmp >= outname && *tmp != L'[') tmp--;
  1000. if(!mode)
  1001. {
  1002. if (tmp >= outname && tmp[1] && !_wcsicmp(tmp + 2, L"].wsz"))
  1003. StringCchCopyW(tmp, tmpsize, L".wsz");
  1004. if (tmp >= outname && tmp[1] && !_wcsicmp(tmp + 2, L"].wal"))
  1005. StringCchCopyW(tmp, tmpsize, L".wal");
  1006. }
  1007. else
  1008. {
  1009. if (tmp >= outname && tmp[1] && !_wcsicmp(tmp + 2, L"].wlz"))
  1010. StringCchCopyW(tmp, tmpsize, L".wlz");
  1011. }
  1012. }
  1013. IFileTypeRegistrar *registrar=0;
  1014. if (GetRegistrar(&registrar, true) == 0 && registrar)
  1015. {
  1016. if (FAILED(registrar->InstallItem(p, buf, outname)))
  1017. {
  1018. wchar_t buffer[MAX_PATH*3] = {0};
  1019. StringCchPrintfW(buffer,sizeof(buffer),getStringW((!mode?IDS_SKINS_INSTALL_ERROR:IDS_LANG_INSTALL_ERROR),NULL,0),outname,p,buf);
  1020. MessageBoxW(NULL, buffer, getStringW(!mode?IDS_SKINS_INSTALL_HEADER:IDS_LANG_INSTALL_HEADER,NULL,0), MB_OK | MB_ICONEXCLAMATION);
  1021. }
  1022. registrar->Release();
  1023. }
  1024. }
  1025. if (hwnd_other)
  1026. {
  1027. if(!mode)
  1028. {
  1029. _w_sW("skin", outname);
  1030. COPYDATASTRUCT cds;
  1031. cds.dwData = IPC_SETSKINW;
  1032. cds.lpData = (void *) outname;
  1033. cds.cbData = sizeof(wchar_t)*(lstrlenW(outname) + 1);
  1034. SendMessageW(hwnd_other, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
  1035. ShowWindow(hwnd_other, SW_RESTORE);
  1036. SetForegroundWindow(hwnd_other);
  1037. }
  1038. else
  1039. {
  1040. // since we can't reliably unload resources on the fly, force a restart
  1041. _w_sW("langpack", outname);
  1042. PostMessageW(hwnd_other,WM_USER,0,IPC_RESTARTWINAMP);
  1043. }
  1044. *exit=1;
  1045. }
  1046. else
  1047. {
  1048. if(!mode)
  1049. {
  1050. g_skinloadedmanually = 1;
  1051. _w_sW("skin", outname);
  1052. }
  1053. else
  1054. {
  1055. _w_sW("langpack", outname);
  1056. }
  1057. }
  1058. lpszCmdParam = L"";
  1059. }
  1060. return lpszCmdParam;
  1061. }