Esempio n. 1
0
CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle)
{
    // BREW does not have a system-wide temporary directory,
    // use "fs:/~/tmp" as our temporary directory.
    String tempPath("fs:/~/tmp");

    PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR);

    // Create the temporary directory if it does not exist.
    IFILEMGR_MkDir(fileMgr.get(), tempPath.utf8().data());

    // Loop until we find a temporary filename that does not exist.
    int number = static_cast<int>(randomNumber() * 10000);
    CString filename;
    do {
        StringBuilder builder;
        builder.append(tempPath);
        builder.append('/');
        builder.append(prefix);
        builder.append(String::number(number));
        filename = builder.toString().utf8();
        number++;
    } while (IFILEMGR_Test(fileMgr.get(), filename.data()) == SUCCESS);

    IFile* tempFile = IFILEMGR_OpenFile(fileMgr.get(), filename.data(), _OFM_CREATE);
    if (tempFile) {
        handle = tempFile;
        return filename;
    }

    return CString();
}
Esempio n. 2
0
/**
 * 打开文件
 * @param file 打开文件名
 * @param flag 打开方式
 * @return 0:成功 -1:失败
 enum {
 _OFM_READ      = 0x0001,
 _OFM_READWRITE = 0x0002,
 _OFM_CREATE    = 0x0004,
 _OFM_APPEND    = 0x0008
 };
 */
int File::open(const char* file,
            int flag)
{
    if (_FileMgr == 0)
        return -1;

    _flag = flag;
	  if (SUCCESS != IFILEMGR_Test(_FileMgr, file))
	  {
      _flag |= _OFM_CREATE;
	  }
	  else
	  {
      _flag |= _OFM_APPEND;
	  }
    _File = IFILEMGR_OpenFile(_FileMgr, file, _flag);

    if (!_File)
    {
        _FileMgr = 0;
        return -1;
    }
    if (_flag|_OFM_APPEND)
    {
        IFILE_Seek(_File,_SEEK_END,0);
    }

    return 0;
}
Esempio n. 3
0
/*======================================================================= 
Function: Loc_InitGPSSettings()

Description: 
   Initializes the GPS configuration to the default values.
=======================================================================*/
uint32 Loc_InitGPSSettings(IShell *pIShell, AEEGPSConfig *gpsConfig)
{
   IFileMgr   *pIFileMgr = NULL;
   IFile      *pIConfigFile = NULL;
   uint32      nResult = 0;
   
   if (pIShell == NULL || gpsConfig == NULL)
      return EFAILED;

   // Create the instance of IFileMgr
   nResult = ISHELL_CreateInstance( pIShell, AEECLSID_FILEMGR, (void**)&pIFileMgr );
   if ( SUCCESS != nResult ) {
      return nResult;
   }

   // If the config file exists, open it and read the settings.  Otherwise, we need to
   // create a new config file.
   nResult = IFILEMGR_Test( pIFileMgr, LOC_CONFIG_FILE );
   if ( SUCCESS == nResult ) {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, LOC_CONFIG_FILE, _OFM_READ );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = Loc_ReadGPSSettings( pIConfigFile, gpsConfig );
      }
   }
   else {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, LOC_CONFIG_FILE, _OFM_CREATE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         // Setup the default GPS settings
         gpsConfig->optim  = AEEGPS_OPT_DEFAULT;
         gpsConfig->qos    = LOC_QOS_DEFAULT;
         gpsConfig->server.svrType = AEEGPS_SERVER_DEFAULT;
         nResult = Loc_WriteGPSSettings( pIConfigFile , gpsConfig);
      }
   }

   // Free the IFileMgr and IFile instances
   IFILE_Release( pIConfigFile );
   IFILEMGR_Release( pIFileMgr );

   return nResult;
}
Esempio n. 4
0
/*======================================================================= 
Function: SamplePosDet_InitGPSSettings()

Description: 
   Initializes the GPS configuration to the default values.

Prototype:

   uint32 SamplePosDet_InitGPSSettings( CSamplePosDet *pMe );

Parameters:
   pMe: [in]. CSamplePosDet instance.

Return Value:

   SUCCESS - If the settings were initialized successfully.
   Returns error code otherwise.
 
Comments:  
   None

Side Effects: 
   None

See Also:
   None
=======================================================================*/
uint32 SamplePosDet_InitGPSSettings(CSamplePosDet *pMe)
{
   IFileMgr   *pIFileMgr = NULL;
   IFile      *pIConfigFile = NULL;
   uint32      nResult = 0;

   // Create the instance of IFileMgr
   nResult = ISHELL_CreateInstance( pMe->theApp.m_pIShell, AEECLSID_FILEMGR, (void**)&pIFileMgr );
   if ( SUCCESS != nResult ) {
      return nResult;
   }

   // If the config file exists, open it and read the settings.  Otherwise, we need to
   // create a new config file.
   nResult = IFILEMGR_Test( pIFileMgr, SPD_CONFIG_FILE );
   if ( SUCCESS == nResult ) {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_READ );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = SamplePosDet_ReadGPSSettings( pMe, pIConfigFile );
      }
   }
   else {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_CREATE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         // Setup the default GPS settings
         pMe->gpsSettings.optim  = AEEGPS_OPT_DEFAULT;
         pMe->gpsSettings.qos    = SPD_QOS_DEFAULT;
         pMe->gpsSettings.server.svrType = AEEGPS_SERVER_DEFAULT;
         nResult = SamplePosDet_WriteGPSSettings( pMe, pIConfigFile );
      }
   }

   // Free the IFileMgr and IFile instances
   IFILE_Release( pIConfigFile );
   IFILEMGR_Release( pIFileMgr );

   return nResult;
}
Esempio n. 5
0
/*======================================================================= 
Function: SamplePosDet_SaveGPSSettings()

Description: 
   Opens the configuration file and saves the settings.

Prototype:

   uint32 SamplePosDet_SaveGPSSettings(CSamplePosDet *pMe);

Parameters:
   pMe: [in]. CSamplePosDet instance.

Return Value:

  SUCCESS - If the settings were written successfully.
  Error code otherwise.
 
Comments:  
   None

Side Effects: 
   None

See Also:
   None
=======================================================================*/
uint32 SamplePosDet_SaveGPSSettings( CSamplePosDet *pMe )
{
   IFileMgr   *pIFileMgr = NULL;
   IFile      *pIConfigFile = NULL;
   uint32      nResult = 0;

   // Create the instance of IFileMgr
   nResult = ISHELL_CreateInstance( pMe->theApp.m_pIShell, AEECLSID_FILEMGR, (void**)&pIFileMgr );
   if ( SUCCESS != nResult ) {
      return nResult;
   }

   // If the config file exists, open it and read the settings.  Otherwise, we need to
   // create a new config file.
   nResult = IFILEMGR_Test( pIFileMgr, SPD_CONFIG_FILE );
   if ( SUCCESS == nResult ) {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_READWRITE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = SamplePosDet_WriteGPSSettings( pMe, pIConfigFile );
      }
   }
   else {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_CREATE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = SamplePosDet_WriteGPSSettings( pMe, pIConfigFile );
      }
   }

   // Free the IFileMgr and IFile instances
   IFILE_Release( pIConfigFile );
   IFILEMGR_Release( pIFileMgr );

   return nResult;
}
Esempio n. 6
0
bool fileExists(const String& path)
{
    PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR);

    return (IFILEMGR_Test(fileMgr.get(), path.utf8().data()) == SUCCESS);
}