📄 plxbrowpush.c
字号:
(pFileUnit->class == PUSH_TEXT && pFileUnit->lItemSize < sizeof(FILEUNIT) + sizeof(TXTFILEITEM)))
{
FS_Close(fileHandle);
#ifdef __PLXBROW_DEBUG_
PlxTrace ("[%d] WBPushGetHeader -----> pFileUnit->lItemSize < 0!", __LINE__);
#endif
return -4;
}
#ifdef __PLXBROW_DEBUG_
PlxTrace ("[%d] WBPushGetHeader -----> nRead = %d", __LINE__, nRead);
#endif
FS_Close(fileHandle);
return 0;
}
/****************************************************************************
* Function WBPushReadItem
* Purpose read a push item from file
* Params
* Return
* Remarks
\****************************************************************************/
int WBPushReadItem(U16 *fileName, void *pItemData, unsigned long bufLen){
FILEUNIT fileUnit;
S32 fileHandle;
UINT nRead;
#ifdef __PLXBROW_DEBUG_
PSIFILEITEM pSiItem;
#endif
fileHandle = FS_Open(fileName, FS_READ_ONLY);
if (fileHandle < 0) {
#ifdef __PLXBROW_DEBUG_
PlxTrace ("[%d] WBPushReadItem -----> FS_Open[%d]", __LINE__, fileHandle);
#endif
return -1;
}
FS_Seek(fileHandle, 0, SEEK_SET);
FS_Read(fileHandle, &fileUnit, sizeof(FILEUNIT), &nRead);
#ifdef __PLXBROW_DEBUG_
PlxTrace ("[%d] WBPushReadItem -----> fileUnit[%d]", __LINE__, nRead);
#endif
if (fileUnit.lItemSize - (sizeof(FILEUNIT)) > bufLen) {
FS_Close(fileHandle);
return -4; //not enough buffer
}
FS_Read(fileHandle, pItemData, fileUnit.lItemSize - (sizeof(FILEUNIT)), &nRead);
#ifdef __PLXBROW_DEBUG_
PlxTrace ("[%d] WBPushReadItem -----> pItemData[%d]", __LINE__, nRead);
if(fileUnit.class == PUSH_SI)
{
pSiItem = (PSIFILEITEM )(pItemData);
PlxTrace ("[%d] WBPushReadItem -----> SI: nRead=%d CreatTime=%s exTime=%s", __LINE__,pSiItem->nRead, pSiItem->szCreateTime,pSiItem->szExTime);
PlxTrace ("[%d] WBPushReadItem -----> SI: nActiveType=%d CreatTime=%d exTime=%d", __LINE__,pSiItem->nActionType, pSiItem->szTitle, pSiItem->szUrl);
}
#endif
FS_Close(fileHandle);
return 0;
}
/****************************************************************************
* Function WBPushParseSIItem
* Purpose parse a si item
* Params
* Return
* Remarks
\****************************************************************************/
/*
void WBPushParseSIItem(void *pSiData, PSIINFO pSiInfo){
PSIFILEITEM pSiItem;
pSiItem = (PSIFILEITEM)pSiData;
pSiInfo->nActionType = pSiItem->nActionType;
pSiInfo->nRead = pSiItem->nRead;
PlxAppMemcpy(pSiInfo->szCreateTime, pSiItem->szCreateTime, DATETIEMLEN);
PlxAppMemcpy(pSiInfo->szExTime, pSiItem->szExTime, DATETIEMLEN);
pSiInfo->pszTitle = (char *)pSiData + sizeof(SIFILEITEM);
pSiInfo->pszUri = (char *)pSiData + sizeof(SIFILEITEM) + pSiItem->szTitle;
#ifdef __PLXBROW_DEBUG_
PlxTrace("[%d] WBPushParseSiltem -----> PUSH_SI :: push title: %s, pus url: %s, ",__LINE__, pSiInfo->pszTitle, pSiInfo->pszUri);
#endif
}
*/
/****************************************************************************
* Function WBPushSetReadState
* Purpose set a push item's read state
* Params
* Return
* Remarks
\****************************************************************************/
static int WBPushSetReadState(PPUSH pPush, unsigned int bRead){
S32 fileHandle;
UINT nRead;
char* currPath;
int flag = 0;
PSIFILEITEM pSI;
PTXTFILEITEM pTxt;
int nNameLen;
char strNewName[PLXBROW_PUSH_FILENAME_MAX_LEN];
char szTemp[2];
if(NULL == pPush)
return -1;
pfnUnicodeStrcpy((S8*)strNewName, (const S8*)pPush->fileName);
nNameLen = pfnUnicodeStrlen((const S8*)pPush->fileName);
if(nNameLen < 5)
return -1;
if((PUSH_SI == pPush->fileUnit.class && 1 == ((PSIFILEITEM)(pPush->pData))->nRead) ||
(PUSH_TEXT == pPush->fileUnit.class && 1 == ((PTXTFILEITEM)(pPush->pData))->bRead))
{
// if('1' == *((char*)pPush->fileName + (nNameLen - 5 ) * 2))
AnsiiToUnicodeString((S8 *)szTemp, (S8 *)"1");
if(0 == pfnUnicodeStrncmp((const S8*)(pPush->fileName + (nNameLen - 5) * 2),(const S8*)szTemp, 1))
return 0;
else
flag = 1; //read but not rename the file
}
if(NULL == (currPath = PlxAppMalloc(PLXBROW_MAX_PATH * 2)))
return -1;
FS_GetCurrentDir((WCHAR *)currPath,PLXBROW_MAX_PATH -1);
if(0 > SetPushDir())
{
PlxAppFree(currPath);
return -1;
}
if(flag == 0) //no need to write read flag in file, just only need to rename the file
{
switch(pPush->fileUnit.class)
{
case PUSH_SI:
pSI = (PSIFILEITEM)(pPush->pData);
pSI->nRead = bRead;
break;
case PUSH_TEXT:
pTxt = (PTXTFILEITEM)(pPush->pData);
pTxt->bRead = bRead;
break;
default:
break;
}
fileHandle = FS_Open((const WCHAR*)pPush->fileName, FS_READ_WRITE);
if (fileHandle < 0)
{
FS_SetCurrentDir((const WCHAR *) currPath);
PlxAppFree(currPath);
return -1;
}
FS_Seek(fileHandle, sizeof(FILEUNIT), SEEK_SET);
FS_Write(fileHandle, &bRead, sizeof(unsigned int), &nRead);
FS_Close(fileHandle);
}
// *(strNewName + (nNameLen - 5) * 2) = '1';
AnsiiNToUnicodeString((S8 *)(strNewName + (nNameLen - 5) * 2), (S8 * )"1", 1);
if(FS_FILE_EXISTS == FS_Rename((const WCHAR * )pPush->fileName, (const WCHAR *)strNewName))
{
#ifdef __PLXBROW_DEBUG_
WAP_DataOut((const unsigned char*)strNewName,(unsigned short)PLXBROW_PUSH_FILENAME_MAX_LEN,(const unsigned char*)"WBSetReadState ------> strNewName");
DumpPush(pPush);
#endif
FS_Delete((const WCHAR*)strNewName);
FS_Rename((const WCHAR * )pPush->fileName, (const WCHAR *)strNewName);
}
// *((char*)pPush->fileName + (nNameLen - 5 ) * 2) = '1';
AnsiiNToUnicodeString((S8 *)((char*)pPush->fileName + (nNameLen - 5 ) * 2), (S8 *)"1", 1);
FS_SetCurrentDir((const WCHAR *) currPath);
PlxAppFree(currPath);
return 0;
}
/****************************************************************************
* Function WBPushDeleteItem
* Purpose delete a push item
* Params
* Return
* Remarks
\****************************************************************************/
/*
int WBPushDeleteItem(U16 *fileName){
return FS_Delete(fileName);
}
*/
/****************************************************************************
* Function SetPushDir
* Purpose
* Params
* Return
* Remarks
\****************************************************************************/
static int SetPushDir (void)
{
int nUtf8PathLen;
char *szWidePath;
nUtf8PathLen = strlen(GetPBUIPushBoxDirectory());
if(NULL == (szWidePath = PlxAppMalloc(nUtf8PathLen *2 +2)))
{
return -1;
}
AnsiiToUnicodeString((S8 *)szWidePath, (S8 *)GetPBUIPushBoxDirectory());
if(FS_NO_ERROR != FS_SetCurrentDir ((WCHAR *)szWidePath))
{
PlxBrowInitCreateSysDir();
// FS_CreateDir ((WCHAR*)szWidePath);
if(FS_NO_ERROR != FS_SetCurrentDir((WCHAR*)szWidePath))
{
PlxAppFree(szWidePath);
return -2;
}
}
PlxAppFree(szWidePath);
return 0;
}
/****************************************************************************
* Function GeneratePushMainName
* Purpose
* Params
* Return
* Remarks
\****************************************************************************/
static void GeneratePushMainName(char* szBuffer, int nBuffLen)
{
MYTIME myTime;
char szTemp1[6];
char szTemp2 [4];
char szInfo[20];
if(NULL == szBuffer || nBuffLen < PUSHITEM_MAIN_NAME_LEN * 2 + 2)
return;
AnsiiToUnicodeString((S8*)szTemp1,(S8*)"00");
AnsiiToUnicodeString((S8*)szTemp2,(S8*)"0");
GetDateTime(&myTime);
if(myTime.nYear <= 100)
{
pfnUnicodeStrcpy((S8*)szBuffer,(const S8*)szTemp1);
pixtel_UI_itoa((s32)myTime.nYear, (UI_string_type)szInfo, 10);
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szInfo);
}
else
{
pixtel_UI_itoa((s32)myTime.nYear, (UI_string_type)szInfo, 10);
pfnUnicodeStrcpy((S8*)szBuffer,(const S8*)szInfo);
}
if(myTime.nMonth < 10)
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szTemp2);
pixtel_UI_itoa((s32)myTime.nMonth, (UI_string_type)szInfo, 10);
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szInfo);
if(myTime.nDay < 10)
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szTemp2);
pixtel_UI_itoa((s32)myTime.nDay, (UI_string_type)szInfo, 10);
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szInfo);
if(myTime.nHour < 10)
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szTemp2);
pixtel_UI_itoa((s32)myTime.nHour, (UI_string_type)szInfo, 10);
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szInfo);
if(myTime.nMin < 10)
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szTemp2);
pixtel_UI_itoa((s32)myTime.nMin , (UI_string_type)szInfo, 10);
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szInfo);
if(myTime.nSec< 10)
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szTemp2);
pixtel_UI_itoa((s32)myTime.nSec, (UI_string_type)szInfo, 10);
pfnUnicodeStrcat((S8*)szBuffer,(const S8*)szInfo);
return ;
}
/****************************************************************************
* Function NewAndOpenFile
* Purpose create a push item file
* Params
* Return the file handler
* Remarks
\****************************************************************************/
static long NewAndOpenFile(char *RetFileName){
// unsigned long tickTime;
FS_DOSDirEntry FileInfo;
int findHandle = -1;
S32 fileHandle;
char strFind[PLXBROW_PUSH_FILENAME_MAX_LEN];
char *szCurrPath;
char szTemp[64];
int nSecond = 100;
int nMainNameLen;
int nSubNameLen;
if(NULL == (szCurrPath = PlxAppMalloc(FS_MAX_PATH)))
return -2;
FS_GetCurrentDir((WCHAR *) szCurrPath,FS_MAX_PATH/2);
if(0 > SetPushDir())
{
#ifdef __PLXBROW_DEBUG_
PlxTrace ("[%d] NewAndOpenFile -----> SetPushDir error",__LINE__);
#endif
PlxAppFree(szCurrPath);
return -1;
}
/*
tickTime = PwbGetTickCount();
for (;;)
{
pixtel_UI_itoa(tickTime,(UI_string_type)strFind,10);
pfnUnicodeStrcat((S8*)strFind,(const S8*)".\x00p\x00s\x00h\x00\x00\x00");
#ifdef __PLXBROW_DEBUG_
PlxTrace ("%s : %d, strFind=%s", __FILE__, __LINE__,strFind);
#endif
findHandle = FS_FindFirst((const WCHAR*)strFind, 0, 0, &FileInfo, (WCHAR *)szTemp, 100);
#ifdef __PLXBROW_DEBUG_
PlxTrace("%s : %d, strFind = %s FindFirst findHandle =%d", __FILE__, __LINE__, strFind,findHandle);
#endif
if (0 > findHandle) {
break;
}
FS_FindClose(findHandle);
++ tickTime;
}
*/
GeneratePushMainName((char*)strFind, PLXBROW_PUSH_FILENAME_MAX_LEN);
// AnsiiToUnicodeString((S8 *)szTemp, (S8 *)"-");
// pfnUnicodeStrcat((S8*)strFind,(const S8*)szTemp);
nMainNameLen = pfnUnicodeStrlen((const S8*)strFind);
for(;;)
{
pixtel_UI_itoa((s32)nSecond, (UI_string_type)szTemp, 10);
nSubNameLen = pfnUnicodeStrlen((const S8*)szTemp);
pfnUnicodeStrcpy((S8 *)strFind + nMainNameLen * 2 , (S8 *)szTemp);
AnsiiToUnicodeString((S8 *)strFind + nMainNameLen *2 + (nSubNameLen - 1) * 2, (S8 *) "?");
pfnUnicodeStrcat((S8*)strFind,(const S8*)".\x00p\x00s\x00h\x00\x00\x00");
findHandle = FS_FindFirst((const WCHAR*)strFind, 0, 0, &FileInfo, (WCHAR *)szTemp, 62);
#ifdef __PLXBROW_DEBUG_
PlxTrace("[%d] NewAndOpenFile -----> strFind = %s FindFirst findHandle =%d", __LINE__, strFind,findHandle);
WAP_DataOut((const unsigned char * )strFind, (unsigned short)PLXBROW_PUSH_FILENAME_MAX_LEN, (const unsigned char *)"strFind");
#endif
if (0 > findHandle)
break;
FS_FindClose(findHandle);
/* findHandle = FS_Open((U16 *)strFind, FS_READ_ONLY);
if (findHandle < 0)
{
#ifdef __PLXBROW_DEBUG_
PlxTrace("[%d] NewAndOpenFile -----> findHandle =%d", __LINE__, findHandle);
WAP_DataOut((const unsigned char * )strFind, (unsigned short)PLXBROW_PUSH_FILENAME_MAX_LEN, (const unsigned char *)"strFind");
#endif
break;
}
FS_Close(findHandle);*/
nSecond += 10;
}
AnsiiNToUnicodeString((S8 *)strFind + nMainNameLen *2 + (nSubNameLen - 1) * 2, (S8 *) "0", 1);
fileHandle = FS_Open((U16*)strFind, FS_CREATE|FS_READ_WRITE);
pfnUnicodeStrcpy((S8*)RetFileName,(const S8*)strFind);
FS_SetCurrentDir((const WCHAR *)szCurrPath);
PlxAppFree(szCurrPath);
return fileHandle;
}
/****************************************************************************
* Function PwbGetTickCount
* Purpose get tick count
* Params
* Return
* Remarks
\****************************************************************************/
/*
#ifdef MMI_ON_HARDWARE_P
typedef unsigned int kal_uint32;
void kal_get_time ( kal_uint32* ticks_ptr);
#endif
static unsigned long PwbGetTickCount(void)
{
unsigned long last_time;
#ifdef MMI_ON_HARDWARE_P
unsigned int last_ticks;
kal_get_time ( &last_ticks );
last_time = kal_ticks_to_milli_secs ( last_ticks );
return last_time;
#else
__declspec(dllimport) unsigned long _stdcall GetTickCount(void);
last_time = GetTickCount();
return last_time;
#endif
}
*/
/****************************************************************************
* Function DeInitPlxBrowPush
* Purpose
* Params
* Return
* Remarks
\****************************************************************************/
void DeInitPlxBrowPush(void)
{
#if 0
int i;
if (0 != listItems) {
for (i = 0; i < bakItemsNum; ++ i) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -