⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brew_lib.txt

📁 自己开发的brew 程序库
💻 TXT
📖 第 1 页 / 共 3 页
字号:

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : File I/O
* RETURN        : 
*******************************************************************************************************************************************/
boolean CApp::dataSave( void* pData, int nsz, char* pszFile )
{
 IFileMgr* pFMgr = NULL;
 IFile*  pFile = NULL;
 boolean  bResult = FALSE;

 // File Mgr create
 if(ISHELL_CreateInstance( m_pIShell, AEECLSID_FILEMGR, (void**)&pFMgr ) == SUCCESS )
 {
  // if szFile exist
  if(IFILEMGR_Test(pFMgr,pszFile) == SUCCESS)
  {
   // DELETE
   if(IFILEMGR_Remove(pFMgr,pszFile) == EFAILED)
   {
    IFILEMGR_Release(pFMgr);
    return FALSE;
   }
  }

  //////////////////////////////////
  // check EFS space
  // TODO...
  //////////////////////////////////

  // CREATE
  pFile = IFILEMGR_OpenFile(pFMgr,pszFile,_OFM_CREATE);

  if(pFile != NULL)
  {
   // WRITE
   if(IFILE_Write(pFile, pData, nsz))
   {
    bResult = TRUE;
   }
   IFILE_Release(pFile);
  }
  IFILEMGR_Release(pFMgr);
 }

 return bResult;
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
boolean CApp::dataLoad( void* pData, int nsz, char* pszFile )
{
 IFileMgr* pFMgr = NULL;
 IFile*   pFile = NULL;
 boolean   bResult = FALSE;

 // File Mgr create.
 if(ISHELL_CreateInstance( m_pIShell, AEECLSID_FILEMGR, (void**)&pFMgr ) == SUCCESS)
 {
  // if szFile exist
  if(IFILEMGR_Test(pFMgr, pszFile) == SUCCESS)
  {
   // OPEN
   pFile = IFILEMGR_OpenFile(pFMgr, pszFile, _OFM_READ);
   if(pFile != NULL)
   {
    // READ
    if(IFILE_Read(pFile, pData, nsz))
    {
     bResult = TRUE;
    }
    IFILE_Release(pFile);
   }
  }
  IFILEMGR_Release(pFMgr);
 }

 return bResult;
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
int CApp::dataLoad( char* pszFile, uint8** ppData )
{
 int ret = 0;
 IFileMgr* pFMgr = NULL;
 IFile*   pFile = NULL;

 // File Mgr create.
 if(ISHELL_CreateInstance( m_pIShell, AEECLSID_FILEMGR, (void**)&pFMgr ) == SUCCESS)
 {
  // if szFile exist
  if(IFILEMGR_Test(pFMgr, pszFile) == SUCCESS)
  {
   // OPEN
   pFile = IFILEMGR_OpenFile(pFMgr, pszFile, _OFM_READ);
   if(pFile != NULL)
   {
    // GET FILE INFO
    AEEFileInfo fi;
    if( IFILE_GetInfo( pFile, &fi ) == SUCCESS && fi.dwSize > 0 )
    {
     // create buffer
     *ppData = (uint8*)MALLOC( fi.dwSize );
     // READ
     ret = IFILE_Read( pFile, *ppData, fi.dwSize );
    }
    
    IFILE_Release(pFile);
   }
  }
  IFILEMGR_Release(pFMgr);
 }

 return ret;
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
boolean CApp::fileExists( char* pszFile )
{
 boolean ret = FALSE;
 IFileMgr* pFMgr = NULL;
 IFile*   pFile = NULL;

 // File Mgr create.
 if(ISHELL_CreateInstance( m_pIShell, AEECLSID_FILEMGR, (void**)&pFMgr ) == SUCCESS)
 {
  // if szFile exist
  if(IFILEMGR_Test(pFMgr, pszFile) == SUCCESS)
  {
   ret = TRUE;
  }
  IFILEMGR_Release(pFMgr);
 }

 return ret;
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
boolean CApp::dataReplace( int nStart, int nsz, void* pData, char* pszFile )
{
 IFileMgr* pFMgr = NULL;
 IFile*   pFile = NULL;
 boolean   bResult = FALSE;

 // File Mgr create.
 if(ISHELL_CreateInstance(m_pIShell,AEECLSID_FILEMGR,(void**)&pFMgr) == SUCCESS)
 {
  //////////////////////////////////
  // check EFS space
  // TODO...
  //////////////////////////////////

  // if szFile exist
  if(IFILEMGR_Test(pFMgr,pszFile) == SUCCESS)
  {
   // OPEN
   pFile = IFILEMGR_OpenFile(pFMgr,pszFile,_OFM_READWRITE);
  }
  else
  {
   // CREATE
   pFile = IFILEMGR_OpenFile( pFMgr, pszFile, _OFM_CREATE );
  }
   
  if(pFile != NULL)
  {
   // MODIFY
   if( IFILE_Seek( pFile, _SEEK_START, nStart ) == SUCCESS )
   {
    if ( IFILE_Write( pFile, pData, nsz ) > 0 )
    {
     bResult = TRUE;
    }
   }
   IFILE_Release(pFile);
  }
  
  IFILEMGR_Release(pFMgr);
 }

 return bResult;
}

 

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : String
* RETURN        : 
*******************************************************************************************************************************************/
AECHAR* CApp::SubString( AECHAR* psz, int bi, int ei )
{
 AECHAR* ret = NULL;

 int len = ei - bi;
 if ( ( len > 0 ) && ( bi <= WSTRLEN(psz) ) )
 {
  ret = new AECHAR[len];
  MEMCPY( (void*)ret, (void*)(psz + bi), len * sizeof(AECHAR) );
 }

 return ret;
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
AECHAR* CApp::SubString( AECHAR* psz, int bi )
{
 return SubString( psz, bi, WSTRLEN(psz) );
}
/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : -1,if not found target
*******************************************************************************************************************************************/
int CApp::IndexOf( AECHAR* source, AECHAR* target )
{
 int sourceCount=WSTRLEN(source);
 int targetCount=WSTRLEN(target);
 if (sourceCount<=0) {
  return -1;
 }
 if (targetCount == 0) {
  return -1;
 }

 AECHAR first  = target[0];
 int i = 0;
 int max = (sourceCount - targetCount);

startSearchForFirstChar:
 while (true) {
  /* Look for first character. */
  while (i <= max && source[i] != first) {
   i++;
  }
  if (i > max) {
   return -1;
  }

  /* Found first character, now look at the rest of v2 */
  int j = i + 1;
  int end = j + targetCount - 1;
  int k = 1;
  while (j < end) {
   if (source[j++] != target[k++]) {
    i++;
    /* Look for str's first char again. */
    goto startSearchForFirstChar;
   }
  }
  return i ; /* Found whole string. */
 }
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
int CApp::IndexOf( AECHAR* source, AECHAR target )
{
 int sourceCount=WSTRLEN(source);
 int i;
 for ( i=0; i<sourceCount; i++ )
 {
  if ( source[i] == target )
  {
   return i;
  }
 }
 return -1;
}


/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
AECHAR* CApp::Trim( AECHAR* psz )
{
 int count = WSTRLEN(psz);
 int len = count;
 int st = 0;

 while ((st < len) && (psz[st] <= ' ')) {
     st++;
 }
 while ((st < len) && (psz[len - 1] <= ' ')) {
     len--;
 }

 AECHAR* ret = NULL;
 if ( (st > 0) || (len < count) )
 {
  ret = SubString( psz, st, len );
  delete[] psz;
  psz = NULL;
 }
 else
 {
  ret = psz;
 }
 return ret;
}

/*******************************************************************************************************************************************
* FUNCTION      : 
* DESCRIPTION   : 
* RETURN        : 
*******************************************************************************************************************************************/
int CApp::ParseInt( AECHAR* psz )
{
 char numBuf[12];
 WSTRTOSTR( psz, (char*)numBuf, 12 );

 int len = STRLEN( numBuf );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -