1
0

registry.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 "../nu/AutoWide.h"
  11. #include "main.hpp"
  12. #include "api.h"
  13. /* register winamp as a media player (in "set defaults")*/
  14. BOOL config_registermediaplayer(DWORD accessEnabled)
  15. {
  16. if (config_no_registry)
  17. return TRUE;
  18. IFileTypeRegistrar *registrar=0;
  19. if (GetRegistrar(&registrar, (accessEnabled != 2)) == 0 && registrar)
  20. {
  21. wchar_t programname[MAX_PATH] = {0};
  22. GetModuleFileNameW(hMainInstance,programname,MAX_PATH);
  23. registrar->RegisterMediaPlayer(!!accessEnabled, programname, AutoWide(app_name), config_whichicon);
  24. LPCWSTR szProtocols[] = { L"mms", L"mmsu", L"mmst", L"uvox", L"icy", L"sc", L"shout", L"unsv", };
  25. for (int i = 0; i < sizeof(szProtocols)/sizeof(*szProtocols); i++)
  26. {
  27. wchar_t szBuffer[64] = {0};
  28. StringCbPrintfW(szBuffer, sizeof(szBuffer), L"%s://", szProtocols[i]);
  29. int offset=0;
  30. if (NULL != in_setmod_noplay(szBuffer, &offset))
  31. registrar->RegisterMediaPlayerProtocol(szProtocols[i], AutoWide(app_name));
  32. else
  33. registrar->UnregisterMediaPlayerProtocol(szProtocols[i], AutoWide(app_name));
  34. }
  35. registrar->Release();
  36. return TRUE;
  37. }
  38. return FALSE;
  39. }
  40. BOOL config_adddircontext(BOOL use_fallback)
  41. {
  42. if (config_no_registry)
  43. return TRUE;
  44. wchar_t programname[MAX_PATH] = {0};
  45. if (!GetModuleFileNameW(hMainInstance,programname,MAX_PATH)) return FALSE;
  46. IFileTypeRegistrar *registrar=0;
  47. if (GetRegistrar(&registrar, !use_fallback) == 0 && registrar)
  48. {
  49. wchar_t str[MAX_PATH+128] = {0}, langbuf[1024] = {0};
  50. StringCchPrintfW(str,MAX_PATH+128,L"\"%s\" \"%%1\"",programname);
  51. registrar->AddDirectoryContext(str, WINAMP_PLAYW, getStringW(IDS_CONFIG_PLAYSTR,langbuf,1024));
  52. StringCchPrintfW(str,MAX_PATH+128,L"\"%s\" /ADD \"%%1\"",programname);
  53. registrar->AddDirectoryContext(str, WINAMP_ENQUEUEW, getStringW(IDS_CONFIG_ENQUEUESTR,langbuf,1024));
  54. StringCchPrintfW(str,MAX_PATH+128,L"\"%s\" /BOOKMARK \"%%1\"",programname);
  55. registrar->AddDirectoryContext(str, WINAMP_BOOKMARKW, getStringW(IDS_CONFIG_BOOKMARKSTR,langbuf,1024));
  56. registrar->Release();
  57. return TRUE;
  58. }
  59. return FALSE;
  60. }
  61. int config_isdircontext(void)
  62. {
  63. if (config_no_registry)
  64. return 0;
  65. HKEY mp3Key;
  66. if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\Classes\\Directory\\shell\\" WINAMP_PLAY,&mp3Key) != ERROR_SUCCESS) return 0;
  67. RegCloseKey(mp3Key);
  68. return 1;
  69. }
  70. BOOL config_setup_filetype(const wchar_t *winamp_file, const wchar_t *name, BOOL use_fallback)
  71. {
  72. wchar_t programname[MAX_PATH] = {0};
  73. if (!GetModuleFileNameW(hMainInstance,programname,MAX_PATH)) return FALSE;
  74. IFileTypeRegistrar *registrar=0;
  75. if (GetRegistrar(&registrar, use_fallback) == 0 && registrar)
  76. {
  77. wchar_t str[MAX_PATH+32] = {0}, langbuf[1024] = {0};
  78. registrar->SetupFileType(programname, winamp_file, name, config_whichicon, config_addtolist?L"Enqueue":L"Play", L"");
  79. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" \"%%1\"",programname);
  80. registrar->SetupShell(str, winamp_file, getStringW(IDS_CONFIG_PLAYSTR,langbuf,1024), L"Play", L"{46986115-84D6-459c-8F95-52DD653E532E}");
  81. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" \"%%1\"",programname);
  82. registrar->SetupShell(str, winamp_file, L"", L"open", L"{46986115-84D6-459c-8F95-52DD653E532E}");
  83. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" /ADD \"%%1\"",programname);
  84. registrar->SetupShell(str, winamp_file, getStringW(IDS_CONFIG_ENQUEUESTR,langbuf,1024), L"Enqueue", L"{77A366BA-2BE4-4a1e-9263-7734AA3E99A2}");
  85. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" /BOOKMARK \"%%1\"",programname);
  86. registrar->SetupShell(str, winamp_file, getStringW(IDS_CONFIG_BOOKMARKSTR,langbuf,1024), L"ListBookmark", L"");
  87. registrar->Release();
  88. return TRUE;
  89. }
  90. return FALSE;
  91. }
  92. BOOL config_setup_filetypes(int mode)
  93. {
  94. if (config_no_registry)
  95. return TRUE;
  96. wchar_t programname[MAX_PATH] = {0};
  97. if (!GetModuleFileNameW(hMainInstance,programname,MAX_PATH)) return FALSE;
  98. if (!config_setup_filetype(WINAMP_FILEW, getStringW(IDS_WINAMP_MEDIA_FILE,NULL,0), !mode))
  99. return FALSE;
  100. IFileTypeRegistrar *registrar=0;
  101. if (GetRegistrar(&registrar, !mode) == 0 && registrar)
  102. {
  103. wchar_t str[MAX_PATH+32] = {0}, langbuf[1024] = {0};
  104. // droptarget stuff for windows XP
  105. // clsid for open
  106. registrar->RegisterGUID(programname, L"{46986115-84D6-459c-8F95-52DD653E532E}");
  107. // clsid for enqueue
  108. registrar->RegisterGUID(programname, L"{77A366BA-2BE4-4a1e-9263-7734AA3E99A2}");
  109. /* Register playlist shell type */
  110. registrar->RegisterTypeShell(programname, WINAMP_PLAYLISTW, getStringW(IDS_WINAMP_PLAYLIST_FILE,NULL,0), config_whichicon2, config_addtolist?L"Enqueue":L"Play");
  111. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" \"%%1\"",programname);
  112. registrar->SetupShell(str, WINAMP_PLAYLISTW, getStringW(IDS_CONFIG_PLAYSTR,langbuf,1024), L"Play", L"");
  113. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" \"%%1\"",programname);
  114. registrar->SetupShell(str, WINAMP_PLAYLISTW, L"", L"open", L"");
  115. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" /ADD \"%%1\"",programname);
  116. registrar->SetupShell(str, WINAMP_PLAYLISTW, getStringW(IDS_CONFIG_ENQUEUESTR,langbuf,1024), L"Enqueue", L"");
  117. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" /BOOKMARK \"%%1\"",programname);
  118. registrar->SetupShell(str, WINAMP_PLAYLISTW, getStringW(IDS_CONFIG_BOOKMARKSTR,langbuf,1024), L"ListBookmark", L"");
  119. /* Register skin shell type */
  120. registrar->RegisterTypeShell(programname, WINAMP_SKINZIPW, getStringW(IDS_WINAMP_EXTENSION_INSTALLATION_FILE,NULL,0), config_whichicon, L"Install");
  121. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" \"%%1\"",programname);
  122. registrar->SetupShell(str, WINAMP_SKINZIPW, getStringW(IDS_WINAMP_FILE_INSTALL,langbuf,1024), L"Install", L"");
  123. /* Register language file type */
  124. registrar->RegisterTypeShell(programname, WINAMP_LANGZIPW, getStringW(IDS_WINAMP_LANGUAGE_INSTALLATION_FILE,NULL,0), config_whichicon, L"Install");
  125. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" \"%%1\"",programname);
  126. registrar->SetupShell(str, WINAMP_LANGZIPW, getStringW(IDS_WINAMP_FILE_INSTALL,langbuf,1024), L"Install", L"");
  127. regmimetype(L"interface/x-winamp-skin", programname, L".wsz", 0);
  128. regmimetype(L"interface/x-winamp-lang", programname, L".wlz", 0);
  129. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" /HANDLE \"%%1\"",programname);
  130. wchar_t icon[MAX_PATH+32] = {0};
  131. StringCchPrintfW(icon,MAX_PATH+32,L"\"%s\",%d",programname, config_whichicon);
  132. //registrar->RegisterProtocol(L"winamp", str, icon);
  133. // regmimetype(L"application/x-winamp-plugin", programname,L"wpz",0);
  134. registrar->Release();
  135. return TRUE;
  136. }
  137. return FALSE;
  138. }
  139. // mar-17-2005-benski
  140. void config_regdvdplayer(void)
  141. {
  142. wchar_t winampPath[MAX_PATH] = {0};
  143. // get the full path exe
  144. if (!GetModuleFileNameW(hMainInstance,winampPath, MAX_PATH))
  145. return;
  146. IFileTypeRegistrar *registrar=0;
  147. if (GetRegistrar(&registrar, true) == 0 && registrar)
  148. {
  149. registrar->RegisterDVDPlayer(winampPath, config_whichicon, L"Winamp.DVD", L"Winamp", L"Nullsoft Winamp", L"Play in Winamp");
  150. registrar->Release();
  151. }
  152. }
  153. static void _reg_associated_filetypes(int force)
  154. {
  155. wchar_t ext_list[16384] = {0}, *p = ext_list;
  156. wchar_t *c_list = in_getextlistW();
  157. void _r_sW(const char *name, wchar_t *data, int mlen);
  158. _r_sW("config_extlist", ext_list, ARRAYSIZE(ext_list));
  159. int something_regged=0;
  160. while (p && *p)
  161. {
  162. wchar_t *p2 = p;
  163. while (p2 && *p2 && *p2 != L':') p2++;
  164. if (p2 && *p2 == L':') *p2++ = 0;
  165. if (!config_isregistered(p))
  166. {
  167. // dropped register on startup for Win8 as we cannot
  168. // re-associate due to changes in the OSes behaviour
  169. if (force || (!IsWin8() && config_check_ft_startup))
  170. {
  171. config_register(p, 1);
  172. something_regged=1;
  173. }
  174. }
  175. else
  176. {
  177. int a = 0;
  178. wchar_t *w = c_list;
  179. if (IsPlaylistExtension(p))
  180. a = 1;
  181. else while (w && *w && !a)
  182. {
  183. if (!_wcsicmp(w, p)) a = 1;
  184. w += lstrlenW(w) + 1;
  185. }
  186. if (!a)
  187. {
  188. config_register(p, 0);
  189. something_regged=1;
  190. }
  191. }
  192. p = p2;
  193. }
  194. GlobalFree((HGLOBAL)c_list);
  195. if (something_regged)
  196. SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL);
  197. }
  198. static int RegisterThread(HANDLE handle, void *user_data, intptr_t id)
  199. {
  200. CoInitializeEx(0,COINIT_MULTITHREADED);
  201. _reg_associated_filetypes((int)id);
  202. CoUninitialize();
  203. return 0;
  204. }
  205. void reg_associated_filetypes(int force)
  206. {
  207. WASABI_API_THREADPOOL->RunFunction(0, RegisterThread, 0, force, api_threadpool::FLAG_LONG_EXECUTION|api_threadpool::FLAG_REQUIRE_COM_MT);
  208. }