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

📄 myfile.final

📁 BREW程序:在BREW手机上的文件操作程序
💻 FINAL
📖 第 1 页 / 共 2 页
字号:
    {
        IMENUCTL_Release(pMe->pMenu);
        pMe->pMenu = NULL;
    }
    if(pMe->pMyFileMgr)
    {
        IFILEMGR_Release(pMe->pMyFileMgr);
        pMe->pMyFileMgr = NULL;
    }
}

static void BuildMainMenu(myfile *pMe)
{
    if(!pMe->pMenu)
    {
        if(ISHELL_CreateInstance(pMe->pIShell,AEECLSID_MENUCTL,(void**)&pMe->pMenu) != SUCCESS)
            return ;
    }

    IMENUCTL_SetTitle(pMe->pMenu,MYFILE_RES_FILE,IDS_TITLE,NULL);

    IMENUCTL_AddItem(pMe->pMenu,MYFILE_RES_FILE,IDS_CREATE_FILE, ID_CREATE_FILE,NULL,0);
    IMENUCTL_AddItem(pMe->pMenu,MYFILE_RES_FILE,IDS_READ_FILE,    ID_READ_FILE,       NULL,0);
    IMENUCTL_AddItem(pMe->pMenu,MYFILE_RES_FILE,IDS_FS_PREFIX,    ID_FS_PREFIX,       NULL,0);

    IMENUCTL_SetActive(pMe->pMenu,TRUE);
    pMe->status = STATUS_MENU;
}

static void CreateFile(myfile *pMe)
{
    IFile   *pMyFile;
    AECHAR  w_str[100];
    char    str[100];
    /*
    AECHAR  str_open_fail[] = {'O','p','e','n',' ','f','i','l','e',' ','f','a','i','l','\0'};
    AECHAR  str_success[] = {'W','r','i','t','e',' ','S','u','c','c','e','s','s','\0'};
    AECHAR  str_fail[] = {'W','r','i','t','e',' ','F','a','i','l','\0'};
    */
    AECHAR  str_open_fail[] = L"Open File Fail";
    AECHAR  str_success[] = L"Write Success";
    AECHAR  str_fail[] = L"Write Fail";
    
    if(ISHELL_CreateInstance(pMe->pIShell, AEECLSID_FILEMGR,(void **)&pMe->pMyFileMgr))
        return;

    IMENUCTL_SetActive(pMe->pMenu,FALSE);
    pMyFile = IFILEMGR_OpenFile(pMe->pMyFileMgr,"mydir/myfile.txt",_OFM_CREATE);
    if(pMyFile == NULL)
    {
         IDISPLAY_ClearScreen(pMe->pIDisplay);
         IDISPLAY_DrawText(pMe->pIDisplay,    // Display instance
                           AEE_FONT_BOLD,       // Use BOLD font
                           str_open_fail,        // Text - Normally comes from resource
                           -1,                  // -1 = Use full string length
                           0,                   // Ignored - IDF_ALIGN_CENTER
                           0,                   // Ignored - IDF_ALIGN_MIDDLE
                           NULL,                // No clipping
                           IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
         IDISPLAY_Update(pMe->pIDisplay);
         pMe->status = STATUS_CREATE;
         return;
    }
    
    ISHELL_LoadResString(pMe->pIShell,MYFILE_RES_FILE,IDS_FILE_DATA,w_str,sizeof(w_str));
    WSTRTOSTR(w_str,str,sizeof(str));
    if(IFILE_Write(pMyFile,str,STRLEN(str)) == 0)
    {
        IDISPLAY_ClearScreen(pMe->pIDisplay);
         IDISPLAY_DrawText(pMe->pIDisplay,    // Display instance
                           AEE_FONT_BOLD,       // Use BOLD font
                           str_fail,        // Text - Normally comes from resource
                           -1,                  // -1 = Use full string length
                           0,                   // Ignored - IDF_ALIGN_CENTER
                           0,                   // Ignored - IDF_ALIGN_MIDDLE
                           NULL,                // No clipping
                           IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    }
    else
    {
         IDISPLAY_ClearScreen(pMe->pIDisplay);
         IDISPLAY_DrawText(pMe->pIDisplay,    // Display instance
                           AEE_FONT_BOLD,       // Use BOLD font
                           str_success,        // Text - Normally comes from resource
                           -1,                  // -1 = Use full string length
                           0,                   // Ignored - IDF_ALIGN_CENTER
                           0,                   // Ignored - IDF_ALIGN_MIDDLE
                           NULL,                // No clipping
                           IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    }
    IDISPLAY_Update(pMe->pIDisplay);
    IFILE_Release(pMyFile);
    pMe->status = STATUS_CREATE;
}

static void ReadFile(myfile  *pMe)
{
    IFile   *pMyFile;
    //AECHAR   str_open_fail[] = {'N','o',' ','S','u','c','h',' ','f','i','l','e','\0'};
    AECHAR   str_open_fail[] = L"No Such File";
    char     buf[100];
    char     *pDest;
    AECHAR  w_buf[100];

    if(ISHELL_CreateInstance(pMe->pIShell, AEECLSID_FILEMGR,(void **)&pMe->pMyFileMgr))
        return;

    IMENUCTL_SetActive(pMe->pMenu,FALSE);
    pMyFile = IFILEMGR_OpenFile(pMe->pMyFileMgr,"mydir/myfile.txt",_OFM_READ);
    if(pMyFile == NULL)
    {
         IDISPLAY_ClearScreen(pMe->pIDisplay);
         IDISPLAY_DrawText(pMe->pIDisplay,    // Display instance
                           AEE_FONT_BOLD,       // Use BOLD font
                           str_open_fail,        // Text - Normally comes from resource
                           -1,                  // -1 = Use full string length
                           0,                   // Ignored - IDF_ALIGN_CENTER
                           0,                   // Ignored - IDF_ALIGN_MIDDLE
                           NULL,                // No clipping
                           IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
         IDISPLAY_Update(pMe->pIDisplay);
         pMe->status = STATUS_READ;
         return;
    }
    
    IFILE_Read(pMyFile,buf,sizeof(buf));
    pDest = STRCHR(buf,'.');
    pDest ++;
    *pDest = 0;
    STRTOWSTR(buf,w_buf,sizeof(w_buf));
    IDISPLAY_ClearScreen(pMe->pIDisplay);
    IDISPLAY_DrawText(pMe->pIDisplay,    // Display instance
                       AEE_FONT_BOLD,       // Use BOLD font
                       w_buf,        // Text - Normally comes from resource
                       -1,                  // -1 = Use full string length
                       0,                   // Ignored - IDF_ALIGN_CENTER
                       0,                   // Ignored - IDF_ALIGN_MIDDLE
                       NULL,                // No clipping
                       IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    IDISPLAY_Update(pMe->pIDisplay);
    IFILE_Release(pMyFile);
    pMe->status = STATUS_READ;
}

static void WriteLine(myfile * pMe, char *pszStr)
{

   int charHeight = 0;      // Stores the char height in pixels for given font
   int pnAscent = 0;        // Stores the ascent in number of pixels
   int pnDescent = 0;       // Stores the descent in number of pixels
   AECHAR * szBuf;     // a buffer that supports 200 char string

   // Make sure the pointers we'll be using are valid
   if (pMe==NULL || pMe->pIDisplay == NULL || pszStr == NULL)
       return;

   if ((szBuf = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
     return;

   // Get the font metrics info
   charHeight = IDISPLAY_GetFontMetrics (pMe->pIDisplay, AEE_FONT_BOLD, &pnAscent, &pnDescent);

   // Convert to wide string (unicode)
   STR_TO_WSTR ((char *)pszStr, szBuf, TEXT_BUFFER_SIZE);

   IDISPLAY_DrawText(pMe->pIDisplay,    // Display instance
                       AEE_FONT_BOLD,       // Use BOLD font
                       szBuf,        // Text - Normally comes from resource
                       -1,                  // -1 = Use full string length
                       0,                   // Ignored - IDF_ALIGN_CENTER
                       charHeight*pMe->m_cLineNum,                   // Ignored - IDF_ALIGN_MIDDLE
                       NULL,                // No clipping
                       0);

  pMe->m_cLineNum ++;
  FREE(szBuf);
  return;

} // End of WriteLine 

static void FsPrefixTest(myfile  *pMe)
{
    // 1. Usage: Basic File Usage

    // This example illustrates several of the functions in the IFileMgr
    // and IFile interfaces.  We first create a directory and two files within
    // the directory, using IFileMgr's EnumInit and EnumNext functions to verify
    // that the creates succeeded.  We then open one of the files for reading and
    // writing, and write three sentences to it with IFile's Write function.  We then
    // use IFile's Seek and Read functions to read back the second sentence we wrote
    // to the file and echo it to the screen.  We then clean up by deleting the directory
    // and files we created, using IFileMgr's Test function to verify that they no longer
    // exist.

    FileInfo fi;
    IFile * pIFile1, * pIFile2;
    char szFirstStr[]  = "First Sentence";
    char szSecondStr[] = "Second Sentence";
    char szThirdStr[]  = "Third Sentence";
    char szBuffer[30];

    // prepare screen for out text
    IMENUCTL_SetActive(pMe->pMenu,FALSE);
    IDISPLAY_ClearScreen(pMe->pIDisplay);
    pMe->m_cLineNum = 0;

    if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->pMyFileMgr))
        return;

    // Create a new directory.  It will be created as a sub-directory of
    // the directory that contains this app's files.
    if (IFILEMGR_MkDir(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir") != SUCCESS)
    { 
      return;
    }

    // Create two new files in this directory, specifying the directory
    // and file names
    if ((pIFile1 = IFILEMGR_OpenFile(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir/xx1.fil", _OFM_CREATE)) == NULL)
    { 
      return;
    }

    if ((pIFile2 = IFILEMGR_OpenFile(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir/xx2.fil", _OFM_CREATE)) == NULL)
    { 
      IFILE_Release(pIFile1);
      return;
    }

    // To verify that the directory was created, list it
    // (TRUE parm means list directories only)
    IFILEMGR_EnumInit(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir", TRUE);
    while (IFILEMGR_EnumNext(pMe->pMyFileMgr, &fi))
        WriteLine(pMe, fi.szName);

    // To verify that the files were created, list them
    // (FALSE parm means list files only)
    IFILEMGR_EnumInit(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir", FALSE);
    while (IFILEMGR_EnumNext(pMe->pMyFileMgr, &fi))
        WriteLine(pMe, fi.szName);

    // Write the three test sentences to the file we just opened.  IFILE_Write
    // returns the number of bytes it wrote, which we check to make sure the 
    // write operations were successful.
    if (IFILE_Write(pIFile1, szFirstStr, sizeof(szFirstStr)) != sizeof(szFirstStr))
    {
        WriteLine(pMe, "1st Write failed");
    }
    else
    {
        WriteLine(pMe, "1st Write OK");
    }
    
    if (IFILE_Write(pIFile1, szSecondStr, sizeof(szSecondStr)) != sizeof(szSecondStr))
    {
        WriteLine(pMe, "2nd Write failed");
    }
    else
    {
        WriteLine(pMe, "2nd Write OK");
    }
    
    if (IFILE_Write(pIFile1, szThirdStr, sizeof(szThirdStr)) != sizeof(szThirdStr))
    {
        WriteLine(pMe, "3rd Write failed");
    }
    else
    {
        WriteLine(pMe, "3rd Write OK");
    }

    // To verify that we wrote to the file successfully,
    // retrieve its size in bytes using GetInfo.
    IFILE_GetInfo(pIFile1, &fi);
    SPRINTF(szBuffer, "Wrote %d bytes", fi.dwSize); 
    WriteLine(pMe, szBuffer);

    // Read back the second sentence from the file.
    // First, we seek to the start position of the sentence
    // by hopping over the first sentence
    if (IFILE_Seek(pIFile1, _SEEK_START, sizeof(szFirstStr)) == SUCCESS)
    {
        // Read the second sentence and echo it back to the screen
        // (when successful, IFile_Read returns the number of bytes read)
        if (IFILE_Read(pIFile1, szBuffer, sizeof(szSecondStr)) == sizeof(szSecondStr))
          WriteLine(pMe, szBuffer);
    }

    // Clean up--first remove the two files we created
    // (must close them first--second file is still open from when 
    // we created it)
    IFILE_Release(pIFile1);
    if (IFILEMGR_Remove(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir/xx1.fil") != SUCCESS)
    {
      WriteLine(pMe, "1st Remove Failed");
    }
    else
    {
      WriteLine(pMe, "1st Remove OK");
    }

    IFILE_Release(pIFile2);
    if (IFILEMGR_Remove(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir/xx2.fil") != SUCCESS)
    {
      WriteLine(pMe, "2st Remove Failed");
    }
    else
    {
      WriteLine(pMe, "2st Remove OK");
    }
    
    // The directory we created is now empty, so we can remove it
    // as well (note that we don't need to open and close directories)
    if (IFILEMGR_RmDir(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir") != SUCCESS)
    {
        WriteLine(pMe, "Dir Remove Failed");
    }
    else
    {
        WriteLine(pMe, "Dir Remove OK");
    }

    // To verify that our removals really happened, we can test if the
    // directory and its files are still there
    if (IFILEMGR_Test(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir") == SUCCESS)
      WriteLine(pMe, "Dir Still There!");

    if (IFILEMGR_Test(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir/xx1.fil") == SUCCESS)
      WriteLine(pMe, "xxxdir/xx1.fil Still There!");

    if (IFILEMGR_Test(pMe->pMyFileMgr, AEEFS_HOME_DIR"xxxdir/xx2.fil") == SUCCESS)
      WriteLine(pMe, AEEFS_HOME_DIR"xxxdir/xx2.fil Still There!");
    
    IDISPLAY_Update(pMe->pIDisplay);

    pMe->status = STATUS_FS_PREFIX;
 }

⌨️ 快捷键说明

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