示例#1
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
bool FDrive_GetNextNameDir(char *nameDirOut, StructForReadDir *s)
{
    DIR *pDir = &s->dir;
    FILINFO *pFNO = &s->fno;
    bool alreadyNull = false;
    while (true)
    {
        if (f_readdir(pDir, pFNO) != FR_OK)
        {
            *nameDirOut = '\0';
            f_closedir(pDir);
            return false;
        }
        else if (pFNO->fname[0] == 0)
        {
            if (alreadyNull)
            {
                *nameDirOut = '\0';
                f_closedir(pDir);
                return false;
            }
            alreadyNull = true;
        }
        else
        {
            char *fn = *(pFNO->lfname) ? pFNO->lfname : pFNO->fname;
            if (pFNO->fattrib & AM_DIR)
            {
                strcpy(nameDirOut, fn);
                return true;
            }
        }
    }
}
示例#2
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
bool FDrive_GetNextNameFile(char *nameFileOut, StructForReadDir *s)
{
    FILINFO *pFNO = &s->fno;
    bool alreadyNull = false;
    while (true)
    {
        if (f_readdir(&s->dir, &s->fno) != FR_OK)
        {
            *nameFileOut = '\0';
            f_closedir(&s->dir);
            return false;
        }
        if (s->fno.fname[0] == 0)
        {
            if (alreadyNull)
            {
                *nameFileOut = '\0';
                f_closedir(&s->dir);
                return false;
            }
            alreadyNull = true;
        }
        else
        {
            char *fn = *(pFNO->lfname) ? pFNO->lfname : pFNO->fname;
            if ((pFNO->fattrib & AM_DIR) == 0 && pFNO->fname[0] != '.')
            {
                strcpy(nameFileOut, fn);
                return true;
            }
        }
    }
}
示例#3
0
/**
  * @brief  Return the first file present inside a direcory with FileExt
  * @param  DirName: Directory name
  * @param  Action :  Opendir, previous or next files, Closedir
  * @param  FileExt:  extension filter if NULL not filter
  * @retval STORAGE_RETURN
  */
STORAGE_RETURN kStorage_GetDirectoryFiles(const uint8_t *DirName, uint8_t action, uint8_t *FileName, uint8_t *FileExt)
{
  static DIR MyDirectory;
  static uint16_t count = 0;
  uint16_t prev = 0;
  FILINFO MyFileInfo;
  uint8_t ext[4];
  
  switch(action)
  {
  case KSTORAGE_FINDPREV :
    /* Recherche du prev */
    if(count == 1 ) return KSTORAGE_FIND_NOPREV;
    prev = count-1;
    count = 0;
    f_closedir(&MyDirectory);
  case KSTORAGE_FINDFIRST :
    if(f_opendir(&MyDirectory, (char const *)DirName) != FR_OK)
    {
      return KSTORAGE_FIND_DIRDOESNTEXSIT;
    }
  case KSTORAGE_FINDNEXT :     
    do 
    {
      /* Get the first file */
      if((f_readdir(&MyDirectory, &MyFileInfo) != FR_OK) || (MyFileInfo.fname[0] == '\0'))
      {
        return KSTORAGE_FIND_NOFILE;
      }
      
      /* check the file extension */
      kStorage_GetExt(MyFileInfo.fname, (char *)ext);
      
      /* part to handle previous */
      if((prev != 0 ) && ((FileExt == NULL) || (strcmp((char const*)ext, (char const*)FileExt) == 0)))
      {
          count++;
          if(count != prev)
          {
            /* go to next picture */
            ext[0] = '\0';
          }
          else
          {
            count--;
          }
      }
    } 
    while((FileExt != NULL) && strcmp((char const*)ext, (char const*)FileExt) != 0);
    count++;
    strcpy((char *)FileName,MyFileInfo.fname);
    break;
  case KSTORAGE_FINDCLOSE : 
    f_closedir(&MyDirectory);
    break;
  }
  
  return KSTORAGE_NOERROR;
}
示例#4
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
bool FDrive_GetNameFile(const char *fullPath, int numFile, char *nameFileOut, StructForReadDir *s)
{
#ifdef _MS_VS
    numFile = numFile;
#else
    int numFiles = 0;
#endif

    memcpy(s->nameDir, fullPath, strlen(fullPath));
    s->nameDir[strlen(fullPath)] = '\0';

    s->fno.lfname = s->lfn;
    s->fno.lfsize = sizeof(s->lfn);

    DIR *pDir = &s->dir;
    FILINFO *pFNO = &s->fno;
    if (f_opendir(pDir, s->nameDir) == FR_OK)
    {
        bool alreadyNull = false;
        bool run = true;
        while (run)
        {
            if (f_readdir(pDir, pFNO) != FR_OK)
            {
                *nameFileOut = '\0';
                f_closedir(pDir);
                return false;
            }
            if (pFNO->fname[0] == 0)
            {
                if (alreadyNull)
                {
                    *nameFileOut = '\0';
                    f_closedir(pDir);
                    return false;
                }
                alreadyNull = true;
            }
#ifndef _MS_VS
            char *fn = *(pFNO->lfname) ? pFNO->lfname : pFNO->fname;
            if (numFile == numFiles && (pFNO->fattrib & AM_DIR) == 0)
            {
                strcpy(nameFileOut, fn);
                return true;
            }
            if ((pFNO->fattrib & AM_DIR) == 0 && (pFNO->fname[0] != '.'))
            {
                numFiles++;
            }
#endif
        }
    }
    return false;
}
int LoadModuleView::load_image() {
	const char magic[6] = {'P', 'P', 'M', ' ', 0x02, 0x00};
	UINT bw;
	uint8_t i;
	uint32_t cnt;
	char md5sum[16];
	FILINFO modinfo;
	FIL modfile;
	DIR rootdir;
	FRESULT res;
	
	// Scan SD card root directory for files with the right MD5 fingerprint at the right location
	if (f_opendir(&rootdir, "/") == FR_OK) {
		for (;;) {
			res = f_readdir(&rootdir, &modinfo);
			if (res != FR_OK || modinfo.fname[0] == 0) break;	// Reached last file, abort
			// Only care about files with .bin extension
			if ((!(modinfo.fattrib & AM_DIR)) && (modinfo.fname[9] == 'B') && (modinfo.fname[10] == 'I') && (modinfo.fname[11] == 'N')) {
				res = f_open(&modfile, modinfo.fname, FA_OPEN_EXISTING | FA_READ);
				if (res != FR_OK) return 0;
				// Magic bytes and version check
				f_read(&modfile, &md5sum, 6, &bw);
				for (i = 0; i < 6; i++)
					if (md5sum[i] != magic[i]) break;
				if (i == 6) {
					f_lseek(&modfile, 26);
					f_read(&modfile, &md5sum, 16, &bw);
					for (i = 0; i < 16; i++)
						if (md5sum[i] != _hash[i]) break;
					// f_read can't read more than 512 bytes at a time ?
					if (i == 16) {
						f_lseek(&modfile, 512);
						for (cnt = 0; cnt < 64; cnt++) {
							if (f_read(&modfile, reinterpret_cast<void*>(portapack::memory::map::m4_code.base() + (cnt * 512)), 512, &bw)) return 0;
						}
						f_close(&modfile);
						f_closedir(&rootdir);
						LPC_RGU->RESET_CTRL[0] = (1 << 13);
						return 1;
					}
				}
				f_close(&modfile);
			}
		}
		f_closedir(&rootdir);
	}
	
	return 0;
}
示例#6
0
FRESULT scan_files (
    char* path        /* Start node to be scanned (***also used as work area***) */
)
{
    FRESULT res;
    DIR dir;
    UINT i;
    static FILINFO fno;


    res = f_opendir(&dir, path);                       /* Open the directory */
    if (res == FR_OK) {
        for (;;) {
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
            if (fno.fattrib & AM_DIR) {                    /* It is a directory */
                sprintf(&path[i = strlen(path)], "/%s", fno.fname);
                res = scan_files(path);                    /* Enter the directory */
                if (res != FR_OK) break;
                path[i] = 0;
            } else {                                       /* It is a file. */
                send_uart(path);
                send_uart("/");
                send_uart(fno.fname);
                send_uart("\n");
                //printf("%s/%s\n", path, fno.fname);
            }
        }
        f_closedir(&dir);
    }

    return res;
}
示例#7
0
/*********************************************
*@brief  在文件夹中遍历子文件,记录文件大小信息
*@param [in ]  directory_path
*@param [out]  directory_name
*@param [in ]  pattern 匹配模式,比如“*.fsn”
*@return
**********************************************
*/
static int traverse_subfile(char *file_path, sd_file_manage_t *p_sd_file_manage, char *pattern)
{
	int res;
	DIR directory_object;
	FILINFO file_object;

#if _USE_LFN
	char lfn[_MAX_LFN + 1];
	file_object.lfname = lfn;
	file_object.lfsize = _MAX_LFN + 1;
#endif

	res = f_findfirst(&directory_object, &file_object, file_path, pattern);
	while (res == FR_OK && file_object.fname[0])
	{
#if _USE_LFN
		DBG_print(DBG_DEBUG, "%-12s  %s", file_object.fname, file_object.lfname);
#else
		DBG_print(DBG_DEBUG, "%s", (file_object.fname));
		p_sd_file_manage->unload_file_num++;
		p_sd_file_manage->unload_file_size += file_object.fsize;

#endif
		res = f_findnext(&directory_object, &file_object);
	}
	f_closedir(&directory_object);

	return 0;
}
示例#8
0
bool findPayload(char *path, u32 pressed)
{
    const char *pattern;

    if(pressed & BUTTON_LEFT) pattern = PATTERN("left");
    else if(pressed & BUTTON_RIGHT) pattern = PATTERN("right");
    else if(pressed & BUTTON_UP) pattern = PATTERN("up");
    else if(pressed & BUTTON_DOWN) pattern = PATTERN("down");
    else if(pressed & BUTTON_START) pattern = PATTERN("start");
    else if(pressed & BUTTON_B) pattern = PATTERN("b");
    else if(pressed & BUTTON_X) pattern = PATTERN("x");
    else if(pressed & BUTTON_Y) pattern = PATTERN("y");
    else if(pressed & BUTTON_R1) pattern = PATTERN("r");
    else if(pressed & BUTTON_A) pattern = PATTERN("a");
    else pattern = PATTERN("select");

    DIR dir;
    FILINFO info;
    FRESULT result;

    result = f_findfirst(&dir, &info, "payloads", pattern);

    if(result != FR_OK) return false;

    f_closedir(&dir);

    if(!info.fname[0]) return false;

    sprintf(path, "payloads/%s", info.fname);

    return true;
}
示例#9
0
u16 CheckJobFileCount(void)
{
    u16 nIndex = 0;
    FRESULT fr = FR_OK;

    // Æú´õ ¿­±â ¿¡·¯½Ã Ãë¼Ò
    fr = f_opendir(&gxDir, DIR_JOB);
    if(fr != FR_OK)
        gxFileCount = 0;

    // ÆÄÀÏ ¸ñ·Ï °¡Á®¿Í¼­ ¸µÅ©µå ¸®½ºÆ® Á¦ÀÛ
    while(fr == FR_OK && ++nIndex)
    {
        // ÆÄÀÏ Ã³À½ºÎÅÍ ³¡±îÁö ºÒ·¯¿À±â
        fr = f_readdir(&gxDir, &gxFileInfo);
        if(fr != FR_OK || gxFileInfo.fname[0] == 0)
        {
            if(nIndex == 1)
                // ÆÄÀÏÀÌ Çϳªµµ ¾øÀ¸¸é gxFileCount ÃʱâÈ­
                return gxFileCount = 0;
            break;
        }

        // Àüü ÆÄÀÏ °³¼ö
        gxFileCount = nIndex;
    }
    fr = f_closedir(&gxDir);

    return gxFileCount;
}
示例#10
0
文件: main.c 项目: duddled/Luma3DS
static u32 loadPayload(const char *pattern)
{
    char path[30] = "/luma/payloads";

    DIR dir;
    FILINFO info;

    FRESULT result = f_findfirst(&dir, &info, path, pattern);

    f_closedir(&dir);

    if(result != FR_OK || !info.fname[0])
        return 0;

    path[14] = '/';
    u32 i;
    for(i = 0; info.fname[i]; i++)
        path[15 + i] = info.fname[i];
    path[15 + i] = '\0';

    FIL payload;
    unsigned int br;

    f_open(&payload, path, FA_READ);
    f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br);
    f_close(&payload);

    return 1;
}
示例#11
0
文件: fs.c 项目: masterspike52/ReiNX
size_t enumerateDir(char ***output, char *path, char *pattern) {
    DIR dp;
    FILINFO fno;
    FRESULT fr;
    char **out = NULL;
    size_t pathlen = strlen(path);

    if (pathlen >= FF_LFN_BUF)
        goto end;

    fr = f_findfirst(&dp, &fno, path, pattern);

    char pathb[FF_LFN_BUF] = {0};
    strcpy(pathb, path);
    pathb[pathlen] = '/';

    int i = 0; 
    while (fno.fname[0] != 0 && fr == FR_OK) {
        if (fno.fname[0] == '.') goto next;  
        out = (char **)realloc(out, (i+1) * sizeof(char *));
        out[i] = (char *)malloc(FF_LFN_BUF);
        strcpy(out[i], pathb);
        strcat(out[i], fno.fname);
        pathb[pathlen+1] = 0;
        i++;
       next:
        f_findnext(&dp, &fno);
    }

    end:
    f_closedir(&dp);
    *output = out;
    return i;
}
示例#12
0
/**
  * @brief  Add entire folder to play list.
  * @param  Foldername: pointer to folder name.
  * @retval None
  */
static void _AddEntireFolder(char *Foldername)
{
  FRESULT res;
  FILINFO fno;
  DIR dir;
  char *fn;
  char tmp[FILEMGR_FULL_PATH_SIZE]; 
  WM_HWIN hItem;  
  
#if _USE_LFN
  static char lfn[_MAX_LFN];
  fno.lfname = lfn;
  fno.lfsize = sizeof(lfn);
#endif
  
  res = f_opendir(&dir, Foldername);
  
  if (res == FR_OK)
  {
    
    while (1)
    {
      res = f_readdir(&dir, &fno);
      
      if (res != FR_OK || fno.fname[0] == 0)
      {
        break;
      }
      if (fno.fname[0] == '.')
      {
        continue;
      }
#if _USE_LFN
      fn = *fno.lfname ? fno.lfname : fno.fname;
#else
      fn = fno.fname;
#endif
      
      if (pVideoList->ptr < FILEMGR_LIST_DEPDTH)
      {
        if ((fno.fattrib & AM_DIR) == 0)
        {
          if(((strstr(fn, ".emf")) || (strstr(fn, ".EMF"))) && (VIDEOPLAYER_hWin != 0))
          {
            strcpy(tmp, Foldername);
            strcat(tmp, "/");
            strcat(tmp, fn);
            strncpy((char *)pVideoList->file[pVideoList->ptr].name, (char *)tmp, FILEMGR_FILE_NAME_SIZE);
            hItem = WM_GetDialogItem(VIDEOPLAYER_hWin, ID_VIDEO_LIST);
            LISTVIEW_AddRow(hItem, NULL);  
            FILEMGR_GetFileOnly (tmp, fn);
            LISTVIEW_SetItemText(hItem, 0, pVideoList->ptr, fn);
            pVideoList->ptr++;
          }
        }
      }   
    }
  }
  f_closedir(&dir);
}
示例#13
0
int ExploreFolders(char* folder){
	int nfiles = 0;
	DIR myDir;
	FILINFO curInfo;
	FILINFO *myInfo = &curInfo;

	myInfo->fname[0] = 'A';
	while(f_opendir(&myDir, folder) != FR_OK);
	for(int i = 0; myInfo->fname[0] != 0; i++){
		if( f_readdir(&myDir, myInfo)) break;
		if(myInfo->fname[0] == '.' || !strcmp(myInfo->fname, "NINTEN~1")) continue;

		char path[1024];
		sprintf(path, "%s/%s", folder, myInfo->fname);
		if(path[strlen(path) - 1] == '/') break;

		if(myInfo->fattrib & AM_DIR){
			nfiles += ExploreFolders(path);
		}else if(true){
			if(ProcessCTR(path) == 0){
				nfiles++;
			}
		}

	}
	f_closedir(&myDir);
	return nfiles;
}
示例#14
0
/*********************************************
*@brief  在文件夹中遍历子文件夹,返回最后文件夹名字指针
*@param [in ]  directory_path
*@param [out]  directory_name
*@param [in ]  pattern 匹配模式
*@return
**********************************************
*/
static int traverse_subcatalog(char *directory_path, char *directory_name, char *pattern)
{
	int res;
	DIR directory_object;
	FILINFO file_object;

#if _USE_LFN
	char lfn[_MAX_LFN + 1];
	file_object.lfname = lfn;
	file_object.lfsize = _MAX_LFN + 1;
#endif

	res = f_findfirst(&directory_object, &file_object, directory_path, pattern);
	while (res == FR_OK && file_object.fname[0])
	{
#if _USE_LFN
		DBG_print(DBG_DEBUG, "%-12s  %s", file_object.fname, file_object.lfname);
#else
		
		DBG_print(DBG_DEBUG, "%s", (file_object.fname));
#endif
		strcpy(directory_name, file_object.fname); //TODO: 要优化效率
		res = f_findnext(&directory_object, &file_object);
	}

//	if (0 != file_object.fname[0])
//	{
//		strcpy(directory_name, file_object.fname);
		//directory_name = file_object.fname;
//	}
	f_closedir(&directory_object);

	return 0;
}
SDFS_status_type SDFS_scandir(char* path, file_list_type* fl) {
	FRESULT res;
	FILINFO fno;
	DIR dir;
	WORD n = 0;

	fno.lfname = lfn;
	fno.lfsize = _MAX_LFN - 1;

	res = f_opendir(&dir, path);
	if (res == FR_OK) {
		for (;;) {
			res = f_readdir(&dir, &fno); /* Read dir object */
			if (res != FR_OK || fno.fname[0] == 0)
				break;
			if (fno.fname[0] == '.')
				continue; /* Ignore element "." */
			if (!(fno.fattrib & AM_DIR)) { /* It is file not dir */
				strcpy(fl->names[n], *fno.lfname ? fno.lfname : fno.fname);
				n++;
			}
		}
		fl->num = n;
		f_closedir(&dir);
		return SDFS_OK;
	} else {
       return SDFS_DIR_OPEN_ERR;
	}
}
示例#16
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
bool FDrive_GetNameDir(const char *fullPath, int numDir, char *nameDirOut, StructForReadDir *s)
{
    memcpy(s->nameDir, fullPath, strlen(fullPath));
    s->nameDir[strlen(fullPath)] = '\0';

    s->fno.lfname = s->lfn;
    s->fno.lfsize = sizeof(s->lfn);

    DIR *pDir = &s->dir;
    if (f_opendir(pDir, s->nameDir) == FR_OK)
    {
        int numDirs = 0;
        FILINFO *pFNO = &s->fno;
        bool alreadyNull = false;
        while (true)
        {
            if (f_readdir(pDir, pFNO) != FR_OK)
            {
                *nameDirOut = '\0';
                f_closedir(pDir);
                return false;
            }
            if (pFNO->fname[0] == 0)
            {
                if (alreadyNull)
                {
                    *nameDirOut = '\0';
                    f_closedir(pDir);
                    return false;
                }
                alreadyNull = true;
            }
            char *fn = *(pFNO->lfname) ? pFNO->lfname : pFNO->fname;
            if (numDir == numDirs && (pFNO->fattrib & AM_DIR))
            {
                strcpy(nameDirOut, fn);
                return true;
            }
            if ((pFNO->fattrib & AM_DIR) && (pFNO->fname[0] != '.'))
            {
                numDirs++;
            }
        }
    }
    return false;
}
示例#17
0
int closedir(DIR * dirp)
{
    if (dirp)
    {
        f_closedir(dirp);
        return 0;
    }
    return -1;
}
/**
  * @brief  Copy disk content in the explorer list
  * @param  path: pointer to root path
  * @param  list: pointer to file list
  * @retval Status
  */
uint8_t  FILEMGR_ParseDisks (char *path, FILELIST_FileTypeDef *list)
{
  FRESULT res;
  FILINFO fno;
  DIR dir;
  char *fn;
  
#if _USE_LFN
  static char lfn[_MAX_LFN];
  fno.lfname = lfn;
  fno.lfsize = sizeof(lfn);
#endif
  
  res = f_opendir(&dir, path);
  list->ptr = 0;
  
  if (res == FR_OK)
  {
    
    while (1)
    {
      res = f_readdir(&dir, &fno);
      
      if (res != FR_OK || fno.fname[0] == 0)
      {
        break;
      }
      if (fno.fname[0] == '.')
      {
        continue;
      }
#if _USE_LFN
      fn = *fno.lfname ? fno.lfname : fno.fname;
#else
      fn = fno.fname;
#endif
      
      if (list->ptr < FILEMGR_LIST_DEPDTH)
      {
        if ((fno.fattrib & AM_DIR) == AM_DIR)
        {
          strncpy((char *)list->file[list->ptr].name, (char *)fn, FILEMGR_FILE_NAME_SIZE);
          list->file[list->ptr].type = FILETYPE_DIR;
          list->ptr++;
        }
        else
        {
          strncpy((char *)list->file[list->ptr].name, (char *)fn, FILEMGR_FILE_NAME_SIZE);
          list->file[list->ptr].type = FILETYPE_FILE;
          list->ptr++;
        }
      }   
    }
  }
  f_closedir(&dir);
  return res;
}
示例#19
0
/**
  * @brief  Add entire folder to play list.
  * @param  Foldername: pointer to folder name.
  * @retval None
  */
static void _AddEntireFolder(char *Foldername)
{
  FRESULT res;
  FILINFO fno;
  DIR dir;
  char *fn;
  static char tmp[FILEMGR_FILE_NAME_SIZE]; 
  
#if _USE_LFN
  static char lfn[_MAX_LFN];
  fno.lfname = lfn;
  fno.lfsize = sizeof(lfn);
#endif
  
  res = f_opendir(&dir, Foldername);
  
  if (res == FR_OK)
  {
    
    while (1)
    {
      res = f_readdir(&dir, &fno);
      
      if (res != FR_OK || fno.fname[0] == 0)
      {
        break;
      }
      if (fno.fname[0] == '.')
      {
        continue;
      }
#if _USE_LFN
      fn = *fno.lfname ? fno.lfname : fno.fname;
#else
      fn = fno.fname;
#endif
      
      if (VideoList.ptr < FILEMGR_LIST_DEPDTH)
      {
        if ((fno.fattrib & AM_DIR) == 0)
        {
          if((strstr(fn, ".emf")) || (strstr(fn, ".EMF")))
          {
            strcpy(tmp, Foldername);
            strcat(tmp, "/");
            strcat(tmp, fn);
            
            strncpy((char *)VideoList.file[VideoList.ptr].name, (char *)tmp, FILEMGR_FILE_NAME_SIZE);
            VideoList.ptr++;
          }
        }
      }   
    }
  }
  f_closedir(&dir);
}
示例#20
0
/**
  * @brief  Image browser
  * @param  path: pointer to root path
  * @retval None
  */
static uint8_t Image_Browser(char *path)
{
  FRESULT res;
  uint8_t ret = 1;
  FILINFO fno;
  DIR dir;
  char *fn;
  
  res = f_opendir(&dir, path);
  if (res != FR_OK) 
  {
    Error_Handler();
  }
  else
  {    
    for (;;) {
      res = f_readdir(&dir, &fno);
      if (res != FR_OK || fno.fname[0] == 0) break;
      if (fno.fname[0] == '.') continue;
      
      fn = fno.fname;
      
      if (fno.fattrib & AM_DIR) 
      {
        continue;
      } 
      else 
      {
        if((strstr(fn, "bmp")) || (strstr(fn, "BMP")))
        {
          res = f_open(&file, fn, FA_OPEN_EXISTING | FA_READ);
          Show_Image();
          USBH_Delay(100);
          ret = 0;
          while((Appli_state == APPLICATION_START) && \
            (BSP_PB_GetState (BUTTON_KEY) != SET))
          {
            Toggle_Leds();
          }
          f_close(&file);
          
        }
      }
    }  
  }
  
    /* LCD Log initialization */
  LCD_LOG_Init(); 

  LCD_LOG_SetHeader((uint8_t *)"LTDC Application"); 
  LCD_LOG_SetFooter ((uint8_t *)"     USB Host Library V3.2.0" );
  USBH_USR_ApplicationState = USH_USR_FS_READLIST;
  
  f_closedir(&dir);
  return ret;
}
示例#21
0
int FATFileSystem::dir_close(fs_dir_t dir) {
    FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);

    lock();
    FRESULT res = f_closedir(dh);
    unlock();

    delete dh;
    return fat_error_remap(res);
}
示例#22
0
u32 defPayloadExists(void)
{
    DIR dir;
    FILINFO info;

    FRESULT result = f_findfirst(&dir, &info, "/luma/payloads", "def_*.bin");

    f_closedir(&dir);

    return (result == FR_OK && info.fname[0]);
}
示例#23
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
void FDrive_GetNumDirsAndFiles(const char* fullPath, int *numDirs, int *numFiles)
{
    FILINFO fno;
    DIR dir;

    *numDirs = 0;
    *numFiles = 0;
    

    char nameDir[_MAX_LFN + 1];
    memcpy(nameDir, fullPath, strlen(fullPath));
    nameDir[strlen(fullPath)] = '\0';

    char lfn[(_MAX_LFN + 1)];
    fno.lfname = lfn;
    fno.lfsize = sizeof(lfn);

    if (f_opendir(&dir, nameDir) == FR_OK)
    {
        int numReadingElements = 0;
        bool alreadyNull = false;
        bool run = true;
        while (run)
        {
            if (f_readdir(&dir, &fno) != FR_OK)
            {
                break;
            }
            if (fno.fname[0] == 0)
            {
                if(alreadyNull)
                {
                    break;
                }
                alreadyNull = true;
                continue;
            }
            numReadingElements++;
            char *fn = *fno.lfname ? fno.lfname : fno.fname;
            if (fn[0] != '.')
            {
                if (fno.fattrib & AM_DIR)
                {
                    (*numDirs)++;
                }
                else
                {
                    (*numFiles)++;
                }
            }
        }
        f_closedir(&dir);
    }
}
示例#24
0
/**
  * @brief  Copies disk content in the explorer list.
  * @param  None
  * @retval Operation result
  */
FRESULT SD_StorageParse(void)
{
  FRESULT res;
  FILINFO fno;
  DIR dir;
  char *fn;
  
#if _USE_LFN
  static char lfn[_MAX_LFN];
  fno.lfname = lfn;
  fno.lfsize = sizeof(lfn);
#endif
  
  res = f_opendir(&dir, SD_Path);
  FileList.ptr = 0;
  
  if(res == FR_OK)
  {
    while (1)
    {
      res = f_readdir(&dir, &fno);
      
      if(res != FR_OK || fno.fname[0] == 0)
      {
        break;
      }
      if(fno.fname[0] == '.')
      {
        continue;
      }
#if _USE_LFN
      fn = *fno.lfname ? fno.lfname : fno.fname;
#else
      fn = fno.fname;
#endif
      
      if(FileList.ptr < FILEMGR_LIST_DEPDTH)
      {
        if((fno.fattrib & AM_DIR) == 0)
        {
          if((strstr(fn, "wav")) || (strstr(fn, "WAV")))
          {
            strncpy((char *)FileList.file[FileList.ptr].name, (char *)fn, FILEMGR_FILE_NAME_SIZE);
            FileList.file[FileList.ptr].type = FILETYPE_FILE;
            FileList.ptr++;
          }
        }
      }   
    }
  }
  f_closedir(&dir);
  return res;
}
示例#25
0
/*find a vaild .fsn or .txt file*/
int find_one_vaild_file(char *dirPath, char * matchFile, char *dstName)
{
	FRESULT res;
	DIR dj;
	FILINFO fno;
#if _USE_LFN
	char lfn[_MAX_LFN + 1];
	fno.lfname = lfn;
	fno.lfsize = _MAX_LFN + 1;
#endif
	res = f_findfirst(&dj, &fno, dirPath, matchFile);
	if (res == FR_OK && fno.fname[0])
	{
		f_closedir(&dj);
		strcpy(dstName, fno.fname);
		return 0;
	}
	f_closedir(&dj);

	return 1;

}
示例#26
0
bool TestExtFile::test_readdir() {
  Variant d = f_opendir("test");
  Variant entry;
  bool seen = false;
  while (!same(entry = f_readdir(d), false)) {
    if (same(entry, "test_ext_file.txt")) {
      seen = true;
    }
  }
  f_closedir(d);
  VERIFY(seen);
  return Count(true);
}
示例#27
0
bool TestExtFile::test_dir() {
  Variant d = f_dir("test");
  VS(d.toArray()["path"], "test");
  Variant entry;
  bool seen = false;
  while (!same(entry = f_readdir(d.toArray()["handle"]), false)) {
    if (same(entry, "test_ext_file.txt")) {
      seen = true;
    }
  }
  f_closedir(d);
  VERIFY(seen);
  return Count(true);
}
示例#28
0
/* 扫描磁盘BMP文件 */
static FRESULT scan_files(char* path)
{
    FRESULT res;
    FILINFO fno;
    DIR dir;
    char *fn;   /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
    static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
    fno.lfname = lfn;
    fno.lfsize = sizeof lfn;
#endif
    
    char full_path[64];
    res = f_opendir(&dir, path);                       /* Open the directory */
    if (res == FR_OK)
    {
        for (;;)
        {
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
            if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
#if _USE_LFN
            fn = *fno.lfname ? fno.lfname : fno.fname;
#else
            fn = fno.fname;
#endif
            if (fno.fattrib & AM_DIR)
            {                    /* It is a directory */
                //printf("%s <DIR>\r\n", fn);
                res = scan_files(fn);
                if (res != FR_OK) break;
            }
            else
            {
                /* It is a file. */
                //printf("File:%s\r\n", fn);
                if(!strncmp((const char *)(uint32_t)fn + strlen(fn)-3 , "BMP", 3))
                {
                    sprintf(full_path, "%s/%s", path, fn);
                    printf("openning file:%s/%s...\r\n", path, fn); 
                    _DrawBMPFile(full_path);
                    DelayMs(500);
                }
            }
        }
        f_closedir(&dir);
    }
    return res;
}
示例#29
0
extern int closedir(FATFS_DIR* dp)
{
	FRESULT res;

	if (!dp) return -1;

	res = f_closedir(&dp->dir);
	free(dp);

	if (res != FR_OK) {
		return -1;
	}

	return 0;
}
示例#30
0
void firmRead(void *dest, const char *firmFolder)
{
    char path[48] = "1:/title/00040138/00000000/content";
    memcpy(&path[18], firmFolder, 8);

    DIR dir;
    FILINFO info;

    f_opendir(&dir, path);

    u32 id = 0;

    //Parse the target directory
    while(f_readdir(&dir, &info) == FR_OK && info.fname[0])
    {
        //Not a cxi
        if(info.altname[9] != 'A') continue;

        //Convert the .app name to an integer
        u32 tempId = 0;
        for(char *tmp = info.altname; *tmp != '.'; tmp++)
        {
            tempId <<= 4;
            tempId += *tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0';
        }

        //Found a newer cxi
        if(tempId > id) id = tempId;
    }

    f_closedir(&dir);

    //Complete the string with the .app name
    memcpy(&path[34], "/00000000.app", 14);

    u32 i = 42;

    //Convert back the .app name from integer to array
    while(id > 0)
    {
        //Last digit of the .app
        static const char hexDigits[] = "0123456789ABCDEF";
        path[i--] = hexDigits[id & 0xF];
        id >>= 4;
    }

    fileRead(dest, path, 0);
}