1
0

templateAddress.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "./templateAddress.h"
  2. #include "./pageAddress.h"
  3. #include "./common.h"
  4. #include <shlwapi.h>
  5. #include <strsafe.h>
  6. LoginTemplateAddress::LoginTemplateAddress()
  7. : ref(1), title(NULL), message(NULL), address(NULL), addressTitle(NULL),
  8. replaceUsername(FALSE)
  9. {
  10. }
  11. LoginTemplateAddress::~LoginTemplateAddress()
  12. {
  13. LoginBox_FreeString(title);
  14. LoginBox_FreeString(message);
  15. LoginBox_FreeString(address);
  16. LoginBox_FreeString(addressTitle);
  17. }
  18. HRESULT LoginTemplateAddress::CreateInstance(LoginTemplateAddress **instance)
  19. {
  20. if (NULL == instance) return E_POINTER;
  21. *instance = new LoginTemplateAddress();
  22. if (NULL == *instance) return E_OUTOFMEMORY;
  23. return S_OK;
  24. }
  25. ULONG LoginTemplateAddress::AddRef()
  26. {
  27. return InterlockedIncrement((LONG*)&ref);
  28. }
  29. ULONG LoginTemplateAddress::Release()
  30. {
  31. if (0 == ref)
  32. return ref;
  33. LONG r = InterlockedDecrement((LONG*)&ref);
  34. if (0 == r)
  35. delete(this);
  36. return r;
  37. }
  38. HRESULT LoginTemplateAddress::GetType(GUID *templateUid)
  39. {
  40. if (NULL == templateUid) return E_INVALIDARG;
  41. *templateUid = LTUID_ADDRESS;
  42. return S_OK;
  43. }
  44. HRESULT LoginTemplateAddress::SetParameter(LPCWSTR pszKey, LPCWSTR pszValue)
  45. {
  46. if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"title"))
  47. {
  48. LoginBox_FreeString(title);
  49. title = LoginBox_CopyString(pszValue);
  50. }
  51. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"message"))
  52. {
  53. LoginBox_FreeString(message);
  54. message = LoginBox_CopyString(pszValue);
  55. }
  56. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"address"))
  57. {
  58. LoginBox_FreeString(address);
  59. address = LoginBox_CopyString(pszValue);
  60. }
  61. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"addressTitle"))
  62. {
  63. LoginBox_FreeString(addressTitle);
  64. addressTitle = LoginBox_CopyString(pszValue);
  65. }
  66. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"replaceUsername"))
  67. {
  68. if (NULL != pszValue)
  69. {
  70. WORD charType;
  71. LPCWSTR p = pszValue;
  72. while(L'\0' != *p)
  73. {
  74. if (FALSE == GetStringTypeW(CT_CTYPE1, p, 1, &charType) ||
  75. 0 != ((C1_DIGIT | C1_XDIGIT) & charType))
  76. {
  77. break;
  78. }
  79. p = CharNext(p);
  80. }
  81. INT r;
  82. if (FALSE != StrToIntEx(p, STIF_SUPPORT_HEX, &r) && 0 != r)
  83. replaceUsername = TRUE;
  84. }
  85. }
  86. return S_OK;
  87. }
  88. HRESULT LoginTemplateAddress::IsValid()
  89. {
  90. return S_OK;
  91. }
  92. HRESULT LoginTemplateAddress::IsIdentical(LoginTemplate *test)
  93. {
  94. if (NULL == test)
  95. return E_INVALIDARG;
  96. GUID typeId;
  97. if (FAILED(test->GetType(&typeId)) || FALSE == IsEqualGUID(LTUID_ADDRESS, typeId))
  98. return S_FALSE;
  99. LoginTemplateAddress *testAddr = (LoginTemplateAddress*)test;
  100. if(S_OK != LoginBox_IsStrEq(title, testAddr->title) ||
  101. S_OK != LoginBox_IsStrEq(message, testAddr->message) ||
  102. S_OK != LoginBox_IsStrEqInvI(address, testAddr->address) ||
  103. S_OK != LoginBox_IsStrEq(addressTitle, testAddr->addressTitle) ||
  104. replaceUsername != testAddr->replaceUsername)
  105. {
  106. return S_FALSE;
  107. }
  108. return S_OK;
  109. }
  110. HWND LoginTemplateAddress::CreatePage(HWND hLoginbox, HWND hParent)
  111. {
  112. HWND hPage = LoginPageAddress::CreatePage(hLoginbox, hParent);
  113. if (NULL == hPage) return NULL;
  114. if (NULL != title)
  115. LoginPage_SetTitle(hPage, title);
  116. if (NULL != message)
  117. LoginPageAddress_SetMessage(hPage, message);
  118. if (NULL != address)
  119. LoginPageAddress_SetAddress(hPage, address, replaceUsername);
  120. if (NULL != addressTitle)
  121. LoginPageAddress_SetAddressTitle(hPage, addressTitle);
  122. return hPage;
  123. }