Example #1
0
int get_idx_filename(char *result, const char *dir, const char *ext, int idx, const char *prefix)
{
    if (! FS_OpenDir(dir))
        return 0;
    char filename[13];
    int type;
    int count = 0;
    while((type = FS_ReadDir(filename)) != 0) {
        if (type == 1 && strncasecmp(filename + strlen(filename) - 4, ext, 4) == 0) {
            count++;
            if (idx + 1 == count) {
                sprintf(result, "%s%s", prefix, filename);
                FS_CloseDir();
                return 1;
            }
        }
    }
    FS_CloseDir();
    return 0;
}
Example #2
0
bool FS_RecDeleteDir(const char* path)
{
    FS_Dir      dir;
    FS_DirEntry entry;
    bool        ret;
    const char* dirname;
    size_t      pathlen;
    size_t      tmplen;
    char*       tmp;

    if (!FS_IsDirectory(path))
        return false;

    if (FS_IsSpecial(path))
        return false;

    dir = FS_OpenDir(path);
    if (dir == FS_INVALID_DIR)
        return false;

    pathlen = strlen(path);
    while ((entry = FS_ReadDir(dir)) != FS_INVALID_DIR_ENTRY)
    {
        dirname = FS_DirEntryName(entry);
        if (FS_IsSpecial(dirname))
            continue;

        // create relative path in temporary buffer
        tmplen = pathlen + 1 + strlen(dirname) + 1;
        tmp = new char[tmplen];
        memcpy(tmp, path, pathlen);
        tmp[pathlen] = FS_Separator();
        memcpy(tmp + pathlen + 1, dirname, strlen(dirname));
        tmp[tmplen - 1] = '\0';

        if (FS_IsDirectory(tmp))
            ret = FS_RecDeleteDir(tmp);
        else
            ret = FS_Delete(tmp);

        delete[] tmp;
        if (!ret)
            return false;
    }

    FS_CloseDir(dir);
    return FS_DeleteDir(path);
}
Example #3
0
int FS_RmDir(const char *pDirName) {
  FS_DIR *dirp;
  struct FS_DIRENT *direntp;
  int idx;
  int i;
  char *s;
  
  /* Check if directory is empty */
  dirp = FS_OpenDir(pDirName);
  if (!dirp) {
    /* Directory not found */
    return -1;
  } 
  i=0;
  while (1) {
    direntp = FS_ReadDir(dirp);
    i++;
    if (i >= 4) {
      break;  /* There is more than '..' and '.' */
    }
    if (!direntp) {
      break;  /* There is no more entry in this directory. */
    }
  }
  FS_CloseDir(dirp);
  if (i >= 4) {
    /* 
        There is more than '..' and '.' in the directory, so you 
        must not delete it.
    */
    return -1;
  }
  /* Find correct FSL (device:unit:name) */
  idx = FS__find_fsl(pDirName, &s);
  if (idx < 0) {
    return -1;  /* Device not found */
  }
  if (FS__pDevInfo[idx].fs_ptr->fsl_rmdir) {
    /* Execute the FSL function */
    FS_X_OS_LockDirHandle();
    i = (FS__pDevInfo[idx].fs_ptr->fsl_rmdir)(s, idx, 0);
    FS_X_OS_UnlockDirHandle();
    return i;
  }
  return -1;
}
Example #4
0
static const char *string_cb(u8 idx, void *data)
{
    (void)data;
    FILE *fh;
    char filename[13];
    int type;
    if (idx == 0) {
        return "English";
    }
    if (! FS_OpenDir("language"))
        return _tr("Unknown");
    while((type = FS_ReadDir(filename)) != 0) {
        if (type == 1 && strncasecmp(filename, "lang", 4) == 0) {
            idx--;
            if (idx == 0) {
                sprintf(cp->tmpstr, "language/%s", filename);
                break;
            }
        }
    }
    FS_CloseDir();
    if(idx == 0) {
        fh = fopen(cp->tmpstr, "r");
        if (fh) {
            if(fgets(cp->tmpstr, sizeof(cp->tmpstr), fh) == NULL)
                cp->tmpstr[0] = 0;
            fclose(fh);
            unsigned len = strlen(cp->tmpstr);
            if(len && cp->tmpstr[0] != ':') {
                cp->tmpstr[len-1] = '\0';
                if ((u8)cp->tmpstr[0] == 0xef
                    && (u8)cp->tmpstr[1] == 0xbb
                    && (u8)cp->tmpstr[2] == 0xbf)
                {
                    //Remove BOM
                    for(u32 i = 3; i < len; i++)
                        cp->tmpstr[i-3] = cp->tmpstr[i];
                    len -= 3;
                }
                return cp->tmpstr;
            }
        }
    }
    return _tr("Unknown");
}
Example #5
0
int count_files(const char *dir, const char *ext, const char *match)
{
    int num_files = 0;
    if (FS_OpenDir(dir)) {
        char filename[13];
        int type;
        while((type = FS_ReadDir(filename)) != 0) {
            if (type == 1 && strncasecmp(filename + strlen(filename) - 4, ext, 4) == 0) {
                num_files++;
                if(match && strncasecmp(match, filename, 13) == 0) {
                    mp->selected = num_files;
                }
            }
        }
        FS_CloseDir();
    }
    return num_files;
}
Example #6
0
static void select_cb(guiObject_t *obj, u16 sel, void *data)
{
    (void)obj;
    (void)data;
    const char *ico;
    mp->selected = sel + 1;
    if(! OBJ_IS_USED(&gui->image))
        return;
    if ((long)data == LOAD_ICON) {
        ico = CONFIG_GetIcon(mp->modeltype);
        if (sel > 0 && FS_OpenDir("modelico")) {
            char filename[13];
            int count = 0;
            int type;
            while((type = FS_ReadDir(filename)) != 0) {
                if (type == 1 && strncasecmp(filename + strlen(filename) - 4, ".bmp", 4) == 0) {
                    count++;
                    if (sel == count) {
                        CONFIG_ParseIconName(mp->iconstr, filename);
                        ico = mp->iconstr;
                        break;
                    }
                }
            }
            FS_CloseDir();
        }
    } else {
        sprintf(tempstring, "models/model%d.ini", mp->selected);
        mp->modeltype = 0;
        mp->iconstr[0] = 0;
        ini_parse(tempstring, ini_handle_icon, NULL);
        if (mp->selected == CONFIG_GetCurrentModel() && Model.icon[0])
            ico = Model.icon;
        else {
            if (mp->iconstr[0])
                ico = mp->iconstr;
            else
                ico = CONFIG_GetIcon(mp->modeltype);
        }
        if (! fexists(ico))
            ico = UNKNOWN_ICON;
    }
    GUI_ReplaceImage(&gui->image, ico, 0, 0);
}
Example #7
0
u32 PageModelSel(u8 event)
{	
	static u32 DrawMask;
	
	if(event==PV_INIT)
	{
		LcdClear(0);
		LcdDrawStart(0, 0,LCD_W-1, LCD_H-1, DRAW_NWSE);  
		LcdDrawText(3,0,"选择模型");		
		LcdDrawHLine(0,128,14,1);
		LcdDrawHLine(0,128,15,1);
		LcdDrawStop();
		
		DrawMask=PD_ALL;
		
		PageModFileCnt=0;
		PageModFileIdx=0;
		PageModFileStart=0;
		
		//枚举所有模型图标
    	if(FS_OpenDir("model"))
    	{
			char modfile[13];
        	int type;
        	while((type = FS_ReadDir(modfile)) != 0 && PageModFileCnt<MODCFG_NUM)
        	{
        		BeepHandler();//此循环耗时太长,需要执行一些必要过程
            	if (type == 1)
            	{
            		//打开配置文件读取模型名称
            		char filename[32];
            		strcpy(filename,"model/");
            		strcat(filename,modfile);
            		FILE *fcfg=fopen(filename,"rb");
            		if(fcfg)
            		{
            			MODEL model;
            			fread(&model,sizeof(model),1,fcfg);
            			if(model.Mark==CFGMARK || model.Mark==CFGMARKOLD)
            			{            	
		            		u16 idx=(modfile[0]-'0')*10+(modfile[1]-'0');       
		            		
            				PageModFiles[PageModFileCnt][0]=modfile[0];
            				PageModFiles[PageModFileCnt][1]=modfile[1];
            				PageModFiles[PageModFileCnt][2]=0xba;//号
            				PageModFiles[PageModFileCnt][3]=0xc5;//号
            				PageModFiles[PageModFileCnt][4]='.';
            				if(idx==TxSys.ModelNo)	strcpy(&PageModFiles[PageModFileCnt][5],Model.Name);
            				else					strcpy(&PageModFiles[PageModFileCnt][5],model.Name);
            					    		
		            		if(idx==TxSys.ModelNo)//寻找当前配置文件
		            		{
		            			PageModFileIdx=PageModFileCnt;
		            		}
		            		PageModFileCnt++;    
		            	}
		            	fclose(fcfg);
            		}            
            	}
            }
        	FS_CloseDir();
        }
		
		//判断是否有配置文件
		if(PageModFileCnt==0)
		{
			PageAlert("没有配置文件...",1000,PV_END);
		}
		
		return 1;
	}	
	
	//绘制界面
	if(DrawMask)
	{		
		//起始位置整理
		if(PageModFileIdx<PageModFileStart) 				PageModFileStart=PageModFileIdx;
		if(PageModFileIdx>PageModFileStart+LCD_MENULINES-1)	PageModFileStart=PageModFileIdx-LCD_MENULINES+1;	
	
		LcdDrawStart(0, 0,LCD_W-1, LCD_H-1, DRAW_NWSE);  
		/*
		//菜单项索引号
		if(DrawMask&PD_IDX)
		{
			if(PageModFileCnt>9)
			{
				LcdDrawMiniInt(110,4,PageModFileIdx+1,2,0,0xff,1);
				LcdDrawMiniNum(110,4,LCD_MN_SPA);
				LcdDrawMiniInt(114,4,PageModFileCnt,2,0,0xff,0);
			}
			else
			{
				LcdDrawMiniInt(120,4,PageModFileIdx+1,2,0,0xff,1);
				LcdDrawMiniNum(120,4,LCD_MN_SPA);
				LcdDrawMiniInt(124,4,PageModFileCnt,1,0,0xff,0);
			}
		}
		*/
		
		//绘制文件列表和模型图标
		if(DrawMask&PD_LIST)
		{			
			//显示列表
			int i,y,idx;
			for(i=0,y=16;i<LCD_MENULINES;i++,y+=16)
			{
				idx=PageModFileStart+i;
				LcdBw=(idx==PageModFileIdx);				
				LcdDrawRect(2,y,125,y+15,LcdBw);		//绘制选中框
				LcdDrawText(3,y,PageModFiles[idx]);	//绘制名称
				LcdBw=0;
			}
		}
		LcdDrawStop();
		DrawMask=0;
	}
	
	//上下按键处理
	if(KeyTstDown(KEY_UP))
	{
		if(PageModFileIdx>0)	PageModFileIdx--;
		else		 			PageModFileIdx=PageModFileCnt-1;
		DrawMask=PD_LIST|PD_IDX;
	}
	if(KeyTstDown(KEY_DW))
	{
		if(PageModFileIdx<PageModFileCnt-1)	PageModFileIdx++;
		else		 							PageModFileIdx=0;
		DrawMask=PD_LIST|PD_IDX;
	}
	
	//选中位图
	if(KeyTstDown(KEY_ENT))
	{
		//取得选中的模型号
		PageModFileIdx= 10*(PageModFiles[PageModFileIdx][0]-'0')+PageModFiles[PageModFileIdx][1]-'0';
		
		//保存现有模型的配置
		ModelSave(TxSys.ModelNo);
		
		//加载新遥控器配置
		ModelLoad(TxSys.ModelNo=PageModFileIdx,1);
		
		PageAlert("模型已切换!",1000,PV_END);
	}
	
	//退出消息
	if(KeyTstDown(KEY_EXT) || event==PV_END)	PageReturn(PV_INIT);//这里不要用REDRAW,要用INIT,让模型菜单初始化
	KeyClearDown(KEY_MENUALL);	
	
	return 0;
}