int ReadFile( char *folder ) { char str[FILENAMEMAX]; FONTCHARACTER find_path[50]; FONTCHARACTER find_name[50]; FILE_INFO file_info; int find_h; int size, i; int iError=0; int iFirst=0; size = 0; FilePath( folder, find_path); // Get File count do { if(iFirst==0) { iError=Bfile_FindFirst(find_path,&find_h,find_name,&file_info); iFirst=1; } else { iError=Bfile_FindNext(find_h,find_name,&file_info); } if( iError == 0 && ( file_info.type == DT_DIRECTORY || IsCsvFile( find_name ) ) ) ++size ; } while (iError == 0); Bfile_FindClose(find_h); // Get File name files = (Files *)calloc(1,size*FILENAMEMAX); i = 0; iError=0; iFirst=0; do { if(iFirst==0) { iError=Bfile_FindFirst(find_path,&find_h,find_name,&file_info); iFirst=1; } else { iError=Bfile_FindNext(find_h,find_name,&file_info); } if( iError == 0 && ( file_info.type == DT_DIRECTORY || IsCsvFile( find_name ) ) ){ FontToChar(find_name,str); strncpy( files[i].filename, str, FILENAMEMAX); files[i].filesize = (file_info.type == DT_DIRECTORY ? -1 : file_info.dsize); ++i; } } while (iError == 0); Bfile_FindClose(find_h); return size; }
int memory_find(char *adresse, char **files, int max) { FONTCHARACTER *adr = memory_char2font(adresse); FONTCHARACTER found[30]; FILE_INFO fileInfo; int searchHandle,i=1,j,x; if(x = Bfile_FindFirst(adr,&searchHandle,found,&fileInfo)) return 0; for(j=0;j<14 && *(found+j);j++) *(*files+j) = *(found+j); while(Bfile_FindNext(searchHandle,found,&fileInfo)==0 && i<max) { for(j=0;j<14 && *(found+j);j++) *(*(files+i)+j) = *(found+j); i++; } Bfile_FindClose(searchHandle); free(adr); return i; }
int stat(const char *path, struct stat *buf){ //Emulate unix paths convert slashes to backslashes and add \\fls0\ to filename char found[266]; int plen = strlen(path); plen+=7; char * fpath=alloca(plen+1); strcpy(fpath,"\\\\fls0\\"); strcpy(fpath+7,path); int i; for(i=7;i<plen;++i){ if(fpath[i]=='/') fpath[i]='\\'; } printf("stat %s\n",fpath); unsigned short * strC=(unsigned short *)alloca(plen*2+2); Bfile_StrToName_ncpy(strC,fpath,plen+1); struct file_type info; int handle,ret; ret = Bfile_FindFirst(strC, &handle, found, &info); if(!ret){ printf("found %d %d %d %d %d %d\n",info.id,info.type,info.fsize,info.dsize,info.property,info.address); memset(buf,0,sizeof(struct stat)); buf->st_size=info.fsize; buf->st_blocks=info.fsize/512; if(info.fsize) buf->st_mode=S_IFREG; else buf->st_mode=S_IFDIR; return 0; }else if(ret==-16){ fputs("not found",stderr); errno=ENOENT; }else{ fprintf(stderr,"error %d\n",ret); errno=EIO; } Bfile_FindClose(handle); return (ret==0)?0:-1; }
int changeWalletScreen(char* currentWallet) { // returns 1 if user changes to another wallet char* currentWalletNice = filenameToName(currentWallet); Menu menu; menu.title = (char*)"Wallet List"; menu.scrollout=1; menu.type=MENUTYPE_FKEYS; menu.height = 7; MenuItem items[MAX_WALLETS]; int mustRefresh = 0; while(1) { char wallets[MAX_WALLETS][MAX_WALLETNAME_SIZE]; // build wallet list: unsigned short path[MAX_FILENAME_SIZE+1], found[MAX_FILENAME_SIZE+1]; char buffer[MAX_FILENAME_SIZE+1]; // make the buffer strcpy(buffer, BALANCEFOLDER"\\*"); file_type_t fileinfo; int findhandle; Bfile_StrToName_ncpy(path, buffer, MAX_FILENAME_SIZE+1); int ret = Bfile_FindFirst_NON_SMEM((const char*)path, &findhandle, (char*)found, &fileinfo); int i = 0; while(!ret) { Bfile_NameToStr_ncpy(buffer, found, MAX_FILENAME_SIZE+1); if(fileinfo.fsize == 0 && !(strcmp((char*)buffer, "..") == 0 || strcmp((char*)buffer, ".") == 0)) { // find folders strcpy(wallets[i], buffer); items[i].text = wallets[i]; i++; if(!strcmp(buffer, currentWalletNice)) menu.selection = i; if(i == MAX_WALLETS) break; } ret = Bfile_FindNext_NON_SMEM(findhandle, (char*)found, (char*)&fileinfo); } menu.items = items; menu.numitems = i; Bfile_FindClose(findhandle); drawFkeyLabels(0x000F, 0x0186, 0x0188, 0x0038, 0, 0); // SELECT, NEW, RENAME, DELETE int res = doMenu(&menu); switch(res) { case MENU_RETURN_EXIT: return mustRefresh; break; case KEY_CTRL_F1: case MENU_RETURN_SELECTION: if(strcmp(currentWalletNice, wallets[menu.selection-1])) { walletNameToPath(buffer, wallets[menu.selection-1]); setCurrentWallet(buffer); return 1; } return mustRefresh; break; case KEY_CTRL_F2: if(menu.numitems >= MAX_WALLETS) { AUX_DisplayErrorMessage( 0x2E ); } else { createWalletWizard(0); } break; case KEY_CTRL_F3: char newWallet[MAX_FILENAME_SIZE]; if(renameWalletScreen(wallets[menu.selection-1], newWallet)) { walletNameToPath(buffer, wallets[menu.selection-1]); if(!strcmp(currentWallet, buffer)) { // if the renamed wallet was the current one, we must set the current wallet to the // new name. setCurrentWallet(newWallet); mustRefresh = 1; } } break; case KEY_CTRL_F4: case KEY_CTRL_DEL: walletNameToPath(buffer, wallets[menu.selection-1]); if(deleteWalletPrompt(buffer)) { if(menu.numitems <= 1) { // this was the only wallet: delete pointer file too, so that user is prompted to create // a new wallet. unsigned short path[MAX_FILENAME_SIZE+1]; strcpy(buffer, BALANCEFOLDER"\\Wallet"); Bfile_StrToName_ncpy(path, buffer, MAX_FILENAME_SIZE); Bfile_DeleteEntry(path); return 1; } if(!strcmp(currentWallet, buffer)) { // if the deleted wallet was the current one, we must set the current wallet to the // first one on the list that is not the deleted one. // (by now we know there is more than one wallet in the list) for(int i = 0; i < menu.numitems; i++) { walletNameToPath(buffer, wallets[i]); if(strcmp(currentWallet, buffer)) break; } setCurrentWallet(buffer); mustRefresh = 1; } } break; } } }
/////////////////////////////////////////////////////////////// // File List /////////////////////////////////////////////////////////////// int SelectFiles3 (char * file_name) // -1 no file , 1 complate ,0 cancel { int key; char str[50]; //字符数组长度下标从0开始,共50个元素 FONTCHARACTER find_path[50]; //获得路径 FONTCHARACTER find_name[50]; //获得名字 int find_h; int size = 0; int top = 0; int buttom = 0; int index,r,y; char *files; FILE_INFO file_info; // CharToFont("\\\\fls0\\ZDM\\*.zdm",find_path); sprintf(str,"%s\\*.zdm",szSrdDir3); CharToFonts3(str,find_path); if(Bfile_FindFirst (find_path,&find_h,find_name,&file_info)==0) //函数搜索目录中文件的名称符合指定的文件名 { int i=0,ret; BOOL bFindFirst=TRUE; //定义一个布尔型变量初始化为真(true),对于bool类型,值只要不是0就是为真,即true;当值为0时为假,即false; size ++; //使用size之后再加一(先计算再操作) while(Bfile_FindNext(find_h,find_name,&file_info)==0) //Bfile_FindNext 函数使用搜索处理定位匹配一个给定名称的文件名称。 size++; Bfile_FindClose(find_h); //Bfile_FindClose 关闭搜索指定处理函数 files = (char*)malloc(size*13); index = 0; for(;;) { if(bFindFirst) //if 值为真 ret=Bfile_FindFirst (find_path,&find_h,find_name,&file_info); else ret=Bfile_FindNext(find_h,find_name,&file_info); if(ret!=0) //if break; strncpy((files+13*i),FontToChars3(find_name,str),13); if(strcmp((files+13*i),setup_data.zdmroute_name)==0) //文件选中后,现在记忆位置 index=i; i++; bFindFirst=FALSE; //令值为假 即=0 } Bfile_FindClose(find_h); //Bfile_FindClose 关闭搜索指定处理函数 r = 1; top = 0; buttom = 4; while(1) { if (r) { Bdisp_AllClr_VRAM(); //PopUpWin(6); DispStr(20,8,"纵断面文件: "); if (buttom-top>3)buttom = top + 3; if(top>index) { top = index; buttom = index + 3; } if (index>buttom) { buttom = index; top = buttom - 3; } if(buttom>size - 1)buttom = size - 1; if(top<0) top = 0; for (i=top;i<=buttom;++i) { //sprintf(str,"%13.13s",(files+13*i)); //y=2+(i-top)*13; //顶部文件位置 //SetMyFont(&stHz12x12,&stAsc6x12); //DispStr(18,y,str); //str[]是字符串 //if(index==i) //Bdisp_AreaReverseVRAM(15,y,20+13*6,y+11); PrintfXY(20,22+(i-top)*8,index==i,"%13.13s",(files+13*i)); } PrintXY(100,22,top>0?"\xE6\x92":" ",0); PrintXY(100,46,buttom<size-1?"\xE6\x93":" ",0); r = 0; } GetKey(&key); if (key==KEY_CTRL_UP) {if(--index<0) index = size - 1;r = 1;} if (key==KEY_CTRL_DOWN) {if(++index>size - 1) index = 0;r = 1;} if (key==KEY_CTRL_EXE) { strcpy(file_name,(files+13*index)); free (files); return 1; } if (key==KEY_CTRL_EXIT) { free (files); return 0; } } } else return -1; }