util.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "./main.h"
  2. #include <string.h>
  3. #include <shlobj.h>
  4. #include "./config.h"
  5. #include "./resource.h"
  6. #include "../nu/AutoChar.h"
  7. #include "../nu/AutoWide.h"
  8. #include "api__gen_ml.h"
  9. #include <strsafe.h>
  10. #include <api/syscb/callbacks/browsercb.h>
  11. void myOpenURLWithFallback(HWND hwnd, wchar_t *loc, wchar_t *fallbackLoc)
  12. {
  13. bool override=false;
  14. if (loc)
  15. {
  16. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::BROWSER, BrowserCallback::ONOPENURL, reinterpret_cast<intptr_t>(loc), reinterpret_cast<intptr_t>(&override));
  17. }
  18. if (!override && fallbackLoc)
  19. ShellExecuteW(hwnd, L"open", fallbackLoc, NULL, NULL, SW_SHOWNORMAL);
  20. }
  21. void FixAmps(char *str, size_t len)
  22. {
  23. size_t realSize=0;
  24. size_t extra=0;
  25. char *itr = str;
  26. while (itr && *itr)
  27. {
  28. if (*itr == '&')
  29. extra++;
  30. itr++;
  31. realSize++;
  32. }
  33. extra = min(len-(realSize+1), extra);
  34. while (extra)
  35. {
  36. str[extra+realSize]=str[realSize];
  37. if (str[realSize] == '&')
  38. {
  39. extra--;
  40. str[extra+realSize]='&';
  41. }
  42. realSize--;
  43. }
  44. }
  45. LPWSTR FixAmpsW(LPWSTR pszText, INT cchMaxText)
  46. {
  47. INT realSize, extra;
  48. LPWSTR itr;
  49. for (itr = pszText, extra = 0; NULL != *itr; itr++) if (L'&' == *itr) extra++;
  50. realSize = (INT)(itr - pszText);
  51. for (extra = min(cchMaxText - (realSize + 1), extra); extra > 0; realSize--)
  52. {
  53. pszText[extra+realSize] = pszText[realSize];
  54. if (L'&' == pszText[realSize])
  55. {
  56. extra--;
  57. pszText[extra+realSize] = L'&';
  58. }
  59. }
  60. return pszText;
  61. }
  62. bool IsVista()
  63. {
  64. static INT fVista = -1;
  65. if (-1 == fVista)
  66. {
  67. OSVERSIONINFO osver;
  68. osver.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
  69. fVista = ( ::GetVersionEx(&osver) && osver.dwPlatformId == VER_PLATFORM_WIN32_NT && (osver.dwMajorVersion >= 6 )) ? 1 : 0;
  70. }
  71. return (1 == fVista);
  72. }