Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.67 KB | None | 0 0
  1. //COTO: FROM HBMENU (NDS) modified
  2.  
  3. //filebrowser(FILE * file to run)
  4. void browsefile(){
  5. //requires
  6. extern int toggle;
  7. //extern bool dldiload;
  8. //-->extern char temppath[];
  9. //res=res; //used for pointer
  10. stub=0; //used for enum files, must be zero then will increase then list
  11. temp=0; //used as a pointer increase to show files & enum file index
  12. temp2=0;//used for controlling pointer top accordingly to enum filetop
  13.    
  14.     //key input
  15.     if((0 == (REG_KEYINPUT & (KEY_A))) && (argarray2[res] == DT_DIR )){
  16.     if((REG_DISPSTAT & DISP_IN_VBLANK)) while(!(REG_DISPSTAT & DISP_IN_VBLANK));
  17.         //clean..
  18.         for(i=0;i<9;i++) printf ("\x1b[%d;1H                                  ",i);
  19.        
  20.         toggle=0;
  21.        
  22.         for(i=0;i<PATH_MAX;i++) temppath[i]=0;
  23.        
  24.         //refresh dir into current dir
  25.         strcat((char*)argarray[res].c_str(),"/");
  26.         strcat(temppath,argarray[res].c_str());
  27.         chdir (argarray[res].c_str());
  28.        
  29.         //clean and generate newpath
  30.         for(i=0;i<PATH_MAX;i++) temppath[i]=0; 
  31.         getcwd (temppath, PATH_MAX);
  32.        
  33.         stub=0;
  34.         argarray.clear();
  35.         argarray2.clear();
  36.        
  37.         if(strcmp(".", argarray[res].c_str()))
  38.             for(i=0;i<9;i++) printf ("\x1b[%d;1H                                  ",i);
  39.        
  40.         else if (strcmp("..", argarray[stub].c_str()) == 0){
  41.             //clean..
  42.             for(i=0;i<9;i++) printf ("\x1b[%d;1H                                  ",i);
  43.             chdir ("..");
  44.            
  45.             for(i=0;i<PATH_MAX;i++) temppath[i]=0;
  46.            
  47.             getcwd (temppath, PATH_MAX);
  48.             argarray.clear();
  49.             argarray2.clear();
  50.             stub=0;
  51.             //temp2=0;
  52.             toggle=0;  
  53.         }
  54.     }
  55.    
  56.     else if(0 == (REG_KEYINPUT & (KEY_A)) && (argarray2[res] != DT_DIR )){
  57.    
  58.         //iprintf("\x1b[20;1H [%s] not a dir!!",argarray[res].c_str());
  59.         iprintf("\x1b[20;1H [%s] file details: \n",argarray[res].c_str());
  60.    
  61.         getcwd (temppath, PATH_MAX);
  62.         strcat(temppath,argarray[res].c_str());
  63.        
  64.                 PARTITION * partition;
  65.                 partition = _FAT_partition_getPartitionFromPath (temppath);
  66.                 if (partition == NULL) {
  67.                     printf("partition couldn't be alloced. path:[%s]",temppath);
  68.                     while(1);
  69.                 }
  70.        
  71.                 //if(!(_io_dldi_stub.friendlyName[0] == 0x52 && _io_dldi_stub.friendlyName[5] == 0x4E)){
  72.                 //  iprintf("\x1b[16;1HCurrent dldi driver[%s]: \n",_io_dldi_stub.friendlyName);
  73.                 //}
  74.                 //(char const*) argarray[res].c_str()
  75.                
  76.                 //-->> works for zip:fseek(pFile, 0L, SEEK_END);
  77.                 //-->> works for zip:int sizef = ftell(pFile);
  78.                 //-->> works for zip:fseek(pFile, 0L, SEEK_SET);
  79.                
  80.                 //rewind(zipfile);
  81.                 //fwrite((void*)rs_sappy_bin,1,rs_sappy_bin_size,zipfile);
  82.                 //rewind(zipfile);
  83.                 //size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
  84.                 //-->> works for zip: fread((void*)uncompr,sizeof(char),sizef,pFile);
  85.                 //int runNds (const void* loader, u32 loaderSize, u32 cluster, bool initDisc, bool dldiPatchNds, int argc, const char** argv)
  86.                 //partition->sectorsPerCluster partition->cwdCluster
  87.                 //-->> works for zip:iprintf("\x1b[18;1H offset:[%x] ",(int)&pFile);
  88.                 //-->> works for zip:iprintf("\x1b[19;1H size:[%d] ",sizef);
  89.                 //iprintf("\x1b[20;1H clustersize:[%d] bytes ",partition->sectorsPerCluster);  
  90.                 bool failed = false;
  91.                 iprintf("\x1b[21;1H CPULoadRom...");
  92.                 if(failed){
  93.                     while(1){
  94.                     printf("\n failed");
  95.                     }
  96.                 }
  97.                 iprintf("OK\n");
  98.    
  99.     }
  100.  
  101.     if(0 == (REG_KEYINPUT & (KEY_B))){
  102.         if((REG_DISPSTAT & DISP_IN_VBLANK)) while(!(REG_DISPSTAT & DISP_IN_VBLANK));
  103.         //clean..
  104.         for(i=0;i<9;i++) printf ("\x1b[%d;1H                                  ",i);
  105.    
  106.         chdir (".."); //go BACK
  107.         for(i=0;i<PATH_MAX;i++) temppath[i]=0;
  108.        
  109.         getcwd (temppath, PATH_MAX);
  110.         argarray.clear();
  111.         argarray2.clear();
  112.         stub=0;
  113.         toggle=0;
  114.     }
  115.    
  116.     if(0 == (REG_KEYINPUT & (KEY_UP))){
  117.         res--;
  118.         dirloaded=false;
  119.     }
  120.            
  121.     if(0 == (REG_KEYINPUT & (KEY_DOWN))){
  122.         res++;
  123.         dirloaded=false;
  124.     }
  125.    
  126.     if (toggle==0) {
  127.         pdir=opendir(temppath);
  128.         dirloaded=false;
  129.         toggle=1;
  130.     }
  131.    
  132.     if(dirloaded==false){
  133.         while((pent=readdir(pdir))!=NULL) {
  134.         argarray.push_back(pent->d_name);
  135.         argarray2.push_back(pent->d_type);
  136.         }
  137.     dirloaded=true;
  138.     }
  139.    
  140.     //clean upon new data (because of interrupt)
  141.     for(i=0;i<9;i++) printf ("\x1b[%d;1H                                  ",i);
  142.    
  143.     do{
  144.         if(argarray2[stub] == DT_DIR)   iprintf("\x1b[%d;1H [%s]", stub, argarray[stub].c_str());
  145.         else iprintf("\x1b[%d;1H %s", stub, argarray[stub].c_str());           
  146.         stub++;
  147.     }
  148.     while((argarray[stub].c_str())!=NULL);
  149.    
  150.     //debug
  151.     for(i=0;i<PATH_MAX;i++) temppath[i]=0;
  152.  
  153.     //checks top cursor
  154.     if(res>stub) {
  155.         res = stub-1;
  156.     }
  157.     else if (res<0) {
  158.         res = 0;
  159.     }
  160.     // Show cursor (after cursor pos)
  161.     iprintf ("\x1b[%d;0H*", res);
  162.     // And not the last ones
  163.     iprintf ("\x1b[%d;0H ", res-1);
  164.     iprintf ("\x1b[%d;0H ", res+1);
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement