miniiapsymbianclient.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "miniiapsymbianclient.h"
  2. #include <iapsymbianclientapi.h>
  3. #include <e32debug.h>
  4. #include <aknappui.h>
  5. //#include "drmfile.h"
  6. //#include <mw/vwsdef.h>
  7. #include <e32def.h>
  8. #include <f32file.h>
  9. #include "Symbian/symbianclientapihelper.h"
  10. MiniIAPSymbianClient::MiniIAPSymbianClient() :
  11. MiniIAPClientApi(),
  12. drmFileHelper()
  13. {
  14. m_IAPHelper = 0;
  15. RDebug::Printf("MiniIAPSymbianClient::MiniIAPSymbianClient");
  16. }
  17. MiniIAPSymbianClient::~MiniIAPSymbianClient()
  18. {
  19. if (m_IAPHelper) delete m_IAPHelper;
  20. m_IAPHelper = 0;
  21. }
  22. bool MiniIAPSymbianClient::isProductPurchased(const char *productId, const char *fileName)
  23. {
  24. TBuf<KMaxFileName> processname =
  25. RProcess().FileName();
  26. processname.Delete(processname.Length()-4,4);
  27. // from "C:\sys\bin\EPong_0xE003AF4F.exe"
  28. // to "C:\sys\bin\EPong_0xE003AF4F"
  29. // ultimately to "C:\private\E003AF4F\drm\data\resourceid_642613\2player.dat"
  30. TText8 *productIdAsText = (TText8 *)productId;
  31. TPtrC8 productIdPtr(productIdAsText);
  32. TText8 *fileNameAsText = (TText8 *)fileName;
  33. TPtrC8 fileNamePtr(fileNameAsText);
  34. TPtrC16 drive = processname.Left(1);
  35. TPtrC16 uid = processname.Right(8);
  36. TBuf<KMaxProductIdLength> tempBuf;
  37. TBuf<KMaxFileName> path;
  38. path.Append(drive);
  39. _LIT(KPrivate,":\\private\\");
  40. path.Append(KPrivate);
  41. path.Append(uid);
  42. _LIT(KDRMDir,"\\drm\\data\\resourceid_");
  43. path.Append(KDRMDir);
  44. tempBuf.Zero(); tempBuf.Copy(productIdPtr);
  45. path.Append(tempBuf);
  46. _LIT(KSeparator,"\\");
  47. path.Append(KSeparator);
  48. tempBuf.Zero(); tempBuf.Copy(fileNamePtr);
  49. path.Append(tempBuf);
  50. RDebug::Printf("isProductPurchased ??");
  51. RDebug::RawPrint(path);
  52. int error = drmFileHelper.open(path);
  53. bool result = true;
  54. if (error && drmFileHelper.isDRMError(error)) {
  55. RDebug::Printf("IS NOT PURCHASED");
  56. result = false;
  57. }
  58. else {
  59. RDebug::Printf("IS PURCHASED");
  60. }
  61. return result;
  62. }
  63. bool MiniIAPSymbianClient::purchaseProduct(const char *productId)
  64. {
  65. RDebug::Printf("MiniIAPSymbianClient::purchaseProduct started");
  66. prepare();
  67. if (!m_miniIAPReceiver) {
  68. RDebug::Printf("MiniIAPSymbianClient::purchaseProduct, but NO m_miniIAPReceiver");
  69. }
  70. return m_IAPHelper->purchaseProduct(productId);
  71. }
  72. void MiniIAPSymbianClient::PurchaseCompleted(const char *productId, const char *status)
  73. {
  74. RDebug::Printf("MiniIAPSymbianClient::PurchaseCompleted %d", m_miniIAPReceiver);
  75. if (m_miniIAPReceiver == NULL) return;
  76. RDebug::Printf("MiniIAPSymbianClient::PurchaseCompleted");
  77. m_miniIAPReceiver->purchaseCompleted(productId, status);
  78. }
  79. void MiniIAPSymbianClient::PurchaseFlowFinished(const char *productId)
  80. {
  81. RDebug::Printf("MiniIAPSymbianClient::PurchaseFlowFinished %d", m_miniIAPReceiver);
  82. if (m_miniIAPReceiver == NULL) return;
  83. m_miniIAPReceiver->purchaseFlowFinished(productId);
  84. }
  85. void MiniIAPSymbianClient::prepare()
  86. {
  87. RDebug::Printf("MiniIAPSymbianClient::prepare");
  88. if (!m_miniIAPReceiver) {
  89. RDebug::Printf("MiniIAPSymbianClient::prepare, #6, but NO m_miniIAPReceiver");
  90. }
  91. if (!m_IAPHelper) {
  92. m_IAPHelper = new SymbianClientApiHelper();
  93. if (!m_miniIAPReceiver) {
  94. RDebug::Printf("MiniIAPSymbianClient::prepare, #8, but NO m_miniIAPReceiver");
  95. }
  96. m_IAPHelper->prepare(this);
  97. }
  98. if (!m_miniIAPReceiver) {
  99. RDebug::Printf("MiniIAPSymbianClient::prepare, #7, but NO m_miniIAPReceiver");
  100. }
  101. }