Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //COTO: FROM HBMENU (NDS) modified
- //filebrowser(FILE * file to run)
- void browsefile(){
- //requires
- extern int toggle;
- //extern bool dldiload;
- //-->extern char temppath[];
- //res=res; //used for pointer
- stub=0; //used for enum files, must be zero then will increase then list
- temp=0; //used as a pointer increase to show files & enum file index
- temp2=0;//used for controlling pointer top accordingly to enum filetop
- //key input
- if((0 == (REG_KEYINPUT & (KEY_A))) && (argarray2[res] == DT_DIR )){
- if((REG_DISPSTAT & DISP_IN_VBLANK)) while(!(REG_DISPSTAT & DISP_IN_VBLANK));
- //clean..
- for(i=0;i<9;i++) printf ("\x1b[%d;1H ",i);
- toggle=0;
- for(i=0;i<PATH_MAX;i++) temppath[i]=0;
- //refresh dir into current dir
- strcat((char*)argarray[res].c_str(),"/");
- strcat(temppath,argarray[res].c_str());
- chdir (argarray[res].c_str());
- //clean and generate newpath
- for(i=0;i<PATH_MAX;i++) temppath[i]=0;
- getcwd (temppath, PATH_MAX);
- stub=0;
- argarray.clear();
- argarray2.clear();
- if(strcmp(".", argarray[res].c_str()))
- for(i=0;i<9;i++) printf ("\x1b[%d;1H ",i);
- else if (strcmp("..", argarray[stub].c_str()) == 0){
- //clean..
- for(i=0;i<9;i++) printf ("\x1b[%d;1H ",i);
- chdir ("..");
- for(i=0;i<PATH_MAX;i++) temppath[i]=0;
- getcwd (temppath, PATH_MAX);
- argarray.clear();
- argarray2.clear();
- stub=0;
- //temp2=0;
- toggle=0;
- }
- }
- else if(0 == (REG_KEYINPUT & (KEY_A)) && (argarray2[res] != DT_DIR )){
- //iprintf("\x1b[20;1H [%s] not a dir!!",argarray[res].c_str());
- iprintf("\x1b[20;1H [%s] file details: \n",argarray[res].c_str());
- getcwd (temppath, PATH_MAX);
- strcat(temppath,argarray[res].c_str());
- PARTITION * partition;
- partition = _FAT_partition_getPartitionFromPath (temppath);
- if (partition == NULL) {
- printf("partition couldn't be alloced. path:[%s]",temppath);
- while(1);
- }
- //if(!(_io_dldi_stub.friendlyName[0] == 0x52 && _io_dldi_stub.friendlyName[5] == 0x4E)){
- // iprintf("\x1b[16;1HCurrent dldi driver[%s]: \n",_io_dldi_stub.friendlyName);
- //}
- //(char const*) argarray[res].c_str()
- //-->> works for zip:fseek(pFile, 0L, SEEK_END);
- //-->> works for zip:int sizef = ftell(pFile);
- //-->> works for zip:fseek(pFile, 0L, SEEK_SET);
- //rewind(zipfile);
- //fwrite((void*)rs_sappy_bin,1,rs_sappy_bin_size,zipfile);
- //rewind(zipfile);
- //size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
- //-->> works for zip: fread((void*)uncompr,sizeof(char),sizef,pFile);
- //int runNds (const void* loader, u32 loaderSize, u32 cluster, bool initDisc, bool dldiPatchNds, int argc, const char** argv)
- //partition->sectorsPerCluster partition->cwdCluster
- //-->> works for zip:iprintf("\x1b[18;1H offset:[%x] ",(int)&pFile);
- //-->> works for zip:iprintf("\x1b[19;1H size:[%d] ",sizef);
- //iprintf("\x1b[20;1H clustersize:[%d] bytes ",partition->sectorsPerCluster);
- bool failed = false;
- iprintf("\x1b[21;1H CPULoadRom...");
- if(failed){
- while(1){
- printf("\n failed");
- }
- }
- iprintf("OK\n");
- }
- if(0 == (REG_KEYINPUT & (KEY_B))){
- if((REG_DISPSTAT & DISP_IN_VBLANK)) while(!(REG_DISPSTAT & DISP_IN_VBLANK));
- //clean..
- for(i=0;i<9;i++) printf ("\x1b[%d;1H ",i);
- chdir (".."); //go BACK
- for(i=0;i<PATH_MAX;i++) temppath[i]=0;
- getcwd (temppath, PATH_MAX);
- argarray.clear();
- argarray2.clear();
- stub=0;
- toggle=0;
- }
- if(0 == (REG_KEYINPUT & (KEY_UP))){
- res--;
- dirloaded=false;
- }
- if(0 == (REG_KEYINPUT & (KEY_DOWN))){
- res++;
- dirloaded=false;
- }
- if (toggle==0) {
- pdir=opendir(temppath);
- dirloaded=false;
- toggle=1;
- }
- if(dirloaded==false){
- while((pent=readdir(pdir))!=NULL) {
- argarray.push_back(pent->d_name);
- argarray2.push_back(pent->d_type);
- }
- dirloaded=true;
- }
- //clean upon new data (because of interrupt)
- for(i=0;i<9;i++) printf ("\x1b[%d;1H ",i);
- do{
- if(argarray2[stub] == DT_DIR) iprintf("\x1b[%d;1H [%s]", stub, argarray[stub].c_str());
- else iprintf("\x1b[%d;1H %s", stub, argarray[stub].c_str());
- stub++;
- }
- while((argarray[stub].c_str())!=NULL);
- //debug
- for(i=0;i<PATH_MAX;i++) temppath[i]=0;
- //checks top cursor
- if(res>stub) {
- res = stub-1;
- }
- else if (res<0) {
- res = 0;
- }
- // Show cursor (after cursor pos)
- iprintf ("\x1b[%d;0H*", res);
- // And not the last ones
- iprintf ("\x1b[%d;0H ", res-1);
- iprintf ("\x1b[%d;0H ", res+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement