1
0

util.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <shlobj.h>
  2. #include <strsafe.h>
  3. #include "main.h"
  4. #include "api__playlist.h"
  5. #include "../nu/ns_wc.h"
  6. HRESULT ResolveShortCut(HWND hwnd, LPCWSTR pszShortcutFile, LPWSTR pszPath)
  7. {
  8. IShellLinkW *psl = 0;
  9. WIN32_FIND_DATAW wfd = {0};
  10. *pszPath = 0; // assume failure
  11. HRESULT hres = CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **)&psl );
  12. if ( SUCCEEDED( hres ) )
  13. {
  14. IPersistFile *ppf = 0;
  15. hres = psl->QueryInterface( &ppf ); // OLE 2! Yay! --YO
  16. if ( SUCCEEDED( hres ) )
  17. {
  18. hres = ppf->Load( pszShortcutFile, STGM_READ );
  19. if ( SUCCEEDED( hres ) )
  20. {
  21. hres = psl->Resolve( hwnd, SLR_ANY_MATCH );
  22. if ( SUCCEEDED( hres ) )
  23. {
  24. wchar_t szGotPath[ MAX_PATH ] = { 0 };
  25. StringCchCopyW( szGotPath, MAX_PATH, pszShortcutFile );
  26. hres = psl->GetPath( szGotPath, MAX_PATH, &wfd, SLGP_SHORTPATH );
  27. StringCchCopyW( pszPath, MAX_PATH, szGotPath );
  28. }
  29. }
  30. ppf->Release();
  31. }
  32. psl->Release();
  33. }
  34. return SUCCEEDED(hres);
  35. }
  36. bool IsUrl(const wchar_t *url)
  37. {
  38. return !!wcsstr(url, L"://");
  39. }
  40. void SetUserAgent(api_httpreceiver *http)
  41. {
  42. char agent[256] = {0};
  43. StringCchPrintfA(agent, 256, "User-Agent: %S/%S", WASABI_API_APP->main_getAppName(), WASABI_API_APP->main_getVersionNumString());
  44. http->addheader(agent);
  45. }
  46. const char *GetProxy()
  47. {
  48. static char proxy[ 256 ] = "";
  49. // {C0A565DC-0CFE-405a-A27C-468B0C8A3A5C}
  50. const GUID internetConfigGroupGUID =
  51. { 0xc0a565dc, 0xcfe, 0x405a, { 0xa2, 0x7c, 0x46, 0x8b, 0xc, 0x8a, 0x3a, 0x5c } };
  52. ifc_configgroup *group = AGAVE_API_CONFIG->GetGroup( internetConfigGroupGUID );
  53. if ( group )
  54. {
  55. ifc_configitem *item = group->GetItem( L"Proxy" );
  56. if ( item )
  57. {
  58. const wchar_t *wideProxy = item->GetString();
  59. if ( wideProxy )
  60. {
  61. WideCharToMultiByteSZ( CP_ACP, 0, wideProxy, -1, proxy, 256, 0, 0 );
  62. }
  63. }
  64. }
  65. return proxy;
  66. }