-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInGameMarketplace.cpp
More file actions
412 lines (354 loc) · 11 KB
/
InGameMarketplace.cpp
File metadata and controls
412 lines (354 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// ======================================================================================
// File : InGameMarketplace.cpp
// Author : Li Chen
// Last Change : 01/17/2011 | 14:40:23 PM | Monday,January
// Description :
// ======================================================================================
#include "stdafx.h"
#include "Master.h"
#include "SignIn.h"
#include "Task.h"
#include "HttpSrv.h"
#include "LogFile.h"
#include "Interface.h"
#if defined(_XBOX)
#include "ContentManager.h"
#include "InGameDownloadManager.h"
#include "InGameOfferManager.h"
#elif defined(_PS3)
#include "InGameBrowsing.h"
#endif
#include "InGameMarketplace.h"
namespace GameService
{
InGameMarketplace::InGameMarketplace(MessageMgr* msgMgr)
: m_iCurrentCategory(GS_EDLCCAT_ALL), m_ContentInstalledCallBack( NULL )
, m_bDownloadImageStarted(FALSE), m_bDownloadImageEnded(FALSE)
, m_bIsCatRequestPending(FALSE), m_bIsProdRequestPending(FALSE)
{
if (msgMgr)
{
msgMgr->Register(EMessage_InternalTaskDone,this);
}
#if defined(_XBOX)
if (msgMgr)
{
msgMgr->Register(EMessage_ContentInstalled,this);
msgMgr->Register(EMessage_SignInChanged,this);
}
m_pContentMgr = GS_NEW ContentManager(msgMgr);
m_pDownloadMgr = GS_NEW DownloadManager();
m_pOfferMgr = GS_NEW OfferManager(msgMgr);
GS_Assert(m_pContentMgr && m_pDownloadMgr && m_pOfferMgr);
#elif defined(_PS3)
m_pInGameBrowsing = GS_NEW InGameBrowsing();
GS_Assert(m_pInGameBrowsing != NULL);
#endif
if (!Initialize())
{
Finalize();
}
}
InGameMarketplace::~InGameMarketplace()
{
#if defined(_XBOX)
if (m_pContentMgr)
{
GS_DELETE m_pContentMgr;
m_pContentMgr = NULL;
}
if (m_pDownloadMgr)
{
GS_DELETE m_pDownloadMgr;
m_pDownloadMgr = NULL;
}
if (m_pOfferMgr)
{
GS_DELETE m_pOfferMgr;
m_pOfferMgr = NULL;
}
#elif defined(_PS3)
if (m_pInGameBrowsing)
{
GS_DELETE m_pInGameBrowsing;
m_pInGameBrowsing = NULL;
}
#endif
}
GS_BOOL InGameMarketplace::Initialize()
{
#if defined(_XBOX)
if (m_pContentMgr)
m_pContentMgr->Initialize();
if (m_pOfferMgr)
m_pOfferMgr->Initialize();
#elif defined(_PS3)
if (m_pInGameBrowsing)
m_pInGameBrowsing->Init();
#endif
m_dwSelectedOffer = ( GS_DWORD )-1;
return TRUE;
}
GS_VOID InGameMarketplace::Finalize()
{
#if defined(_XBOX)
if (m_pContentMgr)
m_pContentMgr->Finalize();
if (m_pOfferMgr)
m_pOfferMgr->Cleanup();
#elif defined(_PS3)
if (m_pInGameBrowsing)
m_pInGameBrowsing->Term();
#endif
}
GS_VOID InGameMarketplace::Update()
{
#if defined(_XBOX)
if (m_pContentMgr)
m_pContentMgr->Update();
if (m_pDownloadMgr)
m_pDownloadMgr->Update();
if (m_pOfferMgr)
m_pOfferMgr->Update();
#elif defined(_PS3)
if (m_pInGameBrowsing)
m_pInGameBrowsing->Update();
#endif
// +LCTEST
static int s_request = 0;
if (s_request)
RequestContentList(GS_EDLCCAT_Song | GS_EDLCCAT_Gear);
// -LCTEST
}
GS_BOOL InGameMarketplace::RequestContentList(GS_INT category)
{
m_iCurrentCategory = category;
m_bIsCatRequestPending = TRUE;
#if defined(_XBOX)
if (m_pOfferMgr)
{
return m_pOfferMgr->EnumerateOffers(category);
}
#elif defined(_PS3)
if (m_pInGameBrowsing)
{
return m_pInGameBrowsing->GetCategory(category);
}
#endif
return FALSE;
}
GS_BOOL InGameMarketplace::RequestProductDetail(GS_INT index)
{
m_dwSelectedOffer = index;
m_bIsProdRequestPending = TRUE;
m_bDownloadImageStarted = m_bDownloadImageEnded = FALSE;
#if defined(_XBOX)
return TRUE;
#elif defined(_PS3)
if (m_pInGameBrowsing)
return m_pInGameBrowsing->GetProductDetail(index, FALSE);
#endif
return FALSE;
}
GS_BOOL InGameMarketplace::RequestDownloadItems( GS_INT index, ContentInstalledCallBack callBack )
{
#if defined(_XBOX)
if ( m_pDownloadMgr )
{
m_ContentInstalledCallBack = callBack;
ULONGLONG offerID;
if ( !m_pOfferMgr->GetOfferIDByIndex( index, offerID ) )
{
return FALSE;
}
DownloadRequest downloadRequest( 1 );
downloadRequest.AddOffer( offerID );
m_pDownloadMgr->DownloadItems( &downloadRequest );
return TRUE;
}
#elif defined(_PS3)
if (m_pInGameBrowsing)
{
m_ContentInstalledCallBack = callBack;
return m_pInGameBrowsing->BuyProduct( index, callBack );
}
#endif
return FALSE;
}
GS_BOOL InGameMarketplace::CheckContentListFinished(TArray<CMarketplaceItem>& productList)
{
if (!m_bIsCatRequestPending)
return FALSE;
productList.Empty();
#if defined(_XBOX)
if (m_pOfferMgr && m_pOfferMgr->IsOfferEnumerationFinished())
{
m_pOfferMgr->GetContentList(productList);
m_bIsCatRequestPending = FALSE;
return TRUE;
}
#elif defined(_PS3)
if (m_pInGameBrowsing)
{
if (m_pInGameBrowsing->IsGetCategoryFinished(productList))
{
m_bIsCatRequestPending = FALSE;
return TRUE;
}
}
#endif
return FALSE;
}
GS_BOOL InGameMarketplace::CheckProductDetailFinished(CMarketplaceDetail& detail)
{
if (!m_bIsProdRequestPending)
return FALSE;
#if defined(_XBOX)
if (m_pOfferMgr && m_pOfferMgr->IsOfferEnumerationFinished())
{
if (!m_bDownloadImageStarted)
{
m_bDownloadImageStarted = TRUE;
m_pOfferMgr->GetProductDetail(m_dwSelectedOffer, detail);
DWORD dwErr;
XSTORAGE_DOWNLOAD_TO_MEMORY_RESULTS pResults = {0};
static char s_FileReadBuffer[500*1024];
ZeroMemory( s_FileReadBuffer, sizeof( s_FileReadBuffer ) );
WCHAR tmp_imageURL[XMARKETPLACE_IMAGE_URL_MINIMUM_WCHARCOUNT*2];
size_t ret_value = 0;
mbstowcs_s(&ret_value, tmp_imageURL, XMARKETPLACE_IMAGE_URL_MINIMUM_WCHARCOUNT*2, detail.m_strImagePath, XMARKETPLACE_IMAGE_URL_MINIMUM_WCHARCOUNT*2);
dwErr = XStorageDownloadToMemory( SignIn::GetActiveUserIndex(), tmp_imageURL,
sizeof( s_FileReadBuffer ), ( const BYTE* )s_FileReadBuffer,
sizeof( XSTORAGE_DOWNLOAD_TO_MEMORY_RESULTS ), &pResults, NULL );
if( dwErr != ERROR_SUCCESS )
{
Master::G()->Log( "Error: File was not read." );
}
// else if( g_dwStorageFacilities[m_dwStorageIndex] != XSTORAGE_FACILITY_PER_TITLE )
// {
// if( pResults.dwBytesTotal == sizeof( m_dwFileBuffer ) &&
// memcmp( ( void* )m_dwFileBuffer, m_dwFileReadBuffer, pResults.dwBytesTotal ) == 0 )
// Master::G()->Log( "File was successfully read and verified." );
// else
// Master::G()->Log( L"File did not pass verification." );
// }
else
{
Master::G()->Log( "File was successfully read." );
}
if (Master::G()->WriteLocalFile(GS_EFileIndex_TmpImg, (GS_BYTE*)s_FileReadBuffer, pResults.dwBytesTotal))
{
// Flash file system will set to Data/GFxAssets folder which is same as the LogFile class setting
strcpy(detail.m_strImagePath, "GS_TmpDLCImgFile.png");
}
m_bDownloadImageEnded = FALSE;
m_bIsProdRequestPending = FALSE;
return TRUE;
// Master::G()->GetHttpSrv()->QueryURL(detail.m_strImagePath.c_str());
// // let TaskMgr track the QueryURL process
// CTaskID id = 0;
// Master::G()->GetTaskMgr()->AddTask(EGSTaskType_RetrieveImageFromHTTP,this,&id);
// Master::G()->GetTaskMgr()->StartTask(id,ERROR_IO_PENDING);
}
else
{
// in downloading image
if (m_bDownloadImageEnded)
{
m_bDownloadImageEnded = FALSE;
m_bIsProdRequestPending = FALSE;
return TRUE;
}
}
}
#elif defined(_PS3)
if (m_pInGameBrowsing)
{
if (m_pInGameBrowsing->IsGetProductFinished(detail))
{
if (!m_bDownloadImageStarted)
{
m_bDownloadImageStarted = TRUE;
Master::G()->GetHttpSrv()->QueryURL(detail.m_strImagePath);
// let TaskMgr track the QueryURL process
CTaskID id = 0;
Master::G()->GetTaskMgr()->AddTask(EGSTaskType_RetrieveImageFromHTTP,0,this,&id);
Master::G()->GetTaskMgr()->StartTask(id);
}
else
{
// in downloading image
if (m_bDownloadImageEnded)
{
m_bDownloadImageEnded = FALSE;
m_bIsProdRequestPending = FALSE;
strcpy(detail.m_strImagePath, Master::G()->GetLocalFileName(GS_EFileIndex_TmpImg));
return TRUE;
}
}
}
}
#endif
return FALSE;
}
//GS_BOOL InGameMarketplace::Add2WishList(GS_INT index)
//{
// WishlistItem tmp;
// tmp.uId = 0;
// tmp.szName = "";
//#if defined(_XBOX)
// if (m_pOfferMgr && m_pOfferMgr->IsOfferEnumerationFinished())
// {
// tmp.uId = (*m_pOfferMgr)[index].qwOfferID;
// Wishlist::GetSingleton()->AddItem(tmp);
// return TRUE;
// }
//#elif defined(_PS3)
// if (m_pInGameBrowsing)
// {
// GS_CHAR tmp_id[64];
// if (m_pInGameBrowsing->GetProductID(index, tmp_id))
// {
// tmp.szName = tmp_id;
// return TRUE;
// }
// }
//#endif
// return FALSE;
//}
GS_VOID InGameMarketplace::MessageResponse(Message* message)
{
#if defined(_XBOX)
if (EMessage_SignInChanged == message->GetMessageID())
{
GS_INT signed_in = *(GS_INT*)message->ReadPayload(0);
if (signed_in)
{
if (m_pOfferMgr)
m_pOfferMgr->EnumerateOffers(m_iCurrentCategory);
}
}
else if (EMessage_ContentInstalled == message->GetMessageID())
{
if (m_pContentMgr)
m_pContentMgr->OnContentInstalled();
if (m_pOfferMgr)
m_pOfferMgr->EnumerateOffers(m_iCurrentCategory);
if ( m_ContentInstalledCallBack )
m_ContentInstalledCallBack();
}
else
#endif
if (EMessage_InternalTaskDone == message->GetMessageID())
{
CTaskID task_id = *(CTaskID*)message->ReadPayload(0);
GS_TaskType taskType = (GS_TaskType)(*(GS_INT*)message->ReadPayload(1));
GS_DWORD taskResult = *(GS_DWORD*)message->ReadPayload(2);
// finished no matter whether succeed in the process
if (EGSTaskType_RetrieveImageFromHTTP == taskType)
{
m_bDownloadImageEnded = TRUE;
}
}
}
} // namespace