Ejemplo n.º 1
0
s32 __Menu_RetrieveList(void)
{
	fatDevice *dev = &deviceList[device];
	DIR_ITER  *dir = NULL;

	struct stat filestat;

	char dirpath[128], filename[1024];
	u32  cnt = 0, len;

	/* Generate dirpath */
	sprintf(dirpath, "%s:" WAD_DIRECTORY, dev->mount);

	/* Open directory */
	dir = diropen(dirpath);
	if (!dir)
		return -1;

	/* Count entries */
	while (!dirnext(dir, filename, &filestat)) {
		if (!(filestat.st_mode & S_IFDIR))
			cnt++;
	}

	/* Reset directory */
	dirreset(dir);

	/* Buffer length */
	len = sizeof(fatFile) * cnt;

	/* Allocate memory */
	fileList = (fatFile *)realloc(fileList, len);
	if (!fileList) {
		dirclose(dir);
		return -2;
	}

	/* Reset file counter */
	fileCnt = 0;

	/* Get entries */
	while (!dirnext(dir, filename, &filestat)) {
		if (!(filestat.st_mode & S_IFDIR)) {
			fatFile *file = &fileList[fileCnt++];

			/* Copy file info */
			strcpy(file->filename, filename);
			file->filestat = filestat;
		}
	}

	/* Close directory */
	dirclose(dir);

	/* Sort list */
	qsort(fileList, fileCnt, sizeof(fatFile), __Menu_EntryCmp);

	return 0;
}
Ejemplo n.º 2
0
void FileSelector::initialize(char* path, int screen)
{
	int file_number = 0;
	struct stat st;
	char filename[256]; // to hold a full filename and string terminator

	string fileext;
	string s;

	this->screen = screen;
	this->selected_file_position = 0;
	
	DIR_ITER* dir = diropen(path);

	if (dir == NULL) 
	{
		PA_OutputText(screen,2,2,(char*)"Unable to open the directory.");
		PA_OutputText(screen,2,3,path);
	}
	else
	{
	   dirnext(dir, filename, &st); // eat up .
	   dirnext(dir, filename, &st); // eat up ..
	   
		while (dirnext(dir, filename, &st) == 0)
		{  
		   // fileext.assign(filename);
		   //fileext = fileext.substr(fileext.length()-4);

		   //if (fileext == ".lua") 
			//{
				s.assign(filename);
			   
				for (int j=0; j < (int)s.length(); ++j)
				{
					s[j]=tolower(s[j]);
				}
			   
			   this->filenames[file_number].assign(s);
				file_number++;	 
			//}			
		}
	} 
	
	this->number_of_files = file_number - 1;
	this->key_hold_time = 0;
	this->file_offset = -4;
}
Ejemplo n.º 3
0
// search in directory for the NDS file
bool SearchDirectory() {
    DIR_ITER *dir;
    bool found = false;
    char path[EFS_MAXPATHLEN];
    char filename[EFS_MAXPATHLEN];
    struct stat st; 
 
    dir = diropen(".");
    while((dirnext(dir, filename, &st) == 0) && (!found)) {
        if(st.st_mode & S_IFDIR) {
            if(((strlen(filename) == 1) && (filename[0]!= '.')) ||
                ((strlen(filename) == 2) && (strcasecmp(filename, "..")))  ||
                (strlen(filename) > 2))
            {
                chdir(filename);
                found = SearchDirectory();
                chdir("..");
            }
        } else {
            getcwd(path, EFS_MAXPATHLEN-1);
            strcat(path, filename);
        
            if(CheckFile(path, true)) {
                found = true;
                break;
            }
        }
    }
    dirclose(dir);
    
    return found;
} 
Ejemplo n.º 4
0
int fileBrowser_libfat_readDir(fileBrowser_file* file, fileBrowser_file** dir){
  
  pauseRemovalThread();
	
  DIR_ITER* dp = diropen( file->name );
	if(!dp) return FILE_BROWSER_ERROR;
	struct stat fstat;
	
	// Set everything up to read
	char filename[MAXPATHLEN];
	int num_entries = 2, i = 0;
	*dir = malloc( num_entries * sizeof(fileBrowser_file) );
	// Read each entry of the directory
	while( dirnext(dp, filename, &fstat) == 0 ){
		// Make sure we have room for this one
		if(i == num_entries){
			++num_entries;
			*dir = realloc( *dir, num_entries * sizeof(fileBrowser_file) ); 
		}
		sprintf((*dir)[i].name, "%s/%s", file->name, filename);
		(*dir)[i].offset = 0;
		(*dir)[i].size   = fstat.st_size;
		(*dir)[i].attr   = (fstat.st_mode & S_IFDIR) ?
		                     FILE_BROWSER_ATTR_DIR : 0;
		++i;
	}
	
	dirclose(dp);
	continueRemovalThread();

	return num_entries;
}
Ejemplo n.º 5
0
void cFileIcons::LoadFolder(cIconPaths& aPaths,const std::string& aFolder)
{
  DIR_ITER* dir=diropen(aFolder.c_str());
  if(NULL!=dir)
  {
    struct stat st;
    char longFilename[MAX_FILENAME_LENGTH];
    while(dirnext(dir,longFilename,&st)==0)
    {
      if((st.st_mode&S_IFDIR)==0)
      {
        size_t len=strlen(longFilename);
        if(len>4)
        {
          char* extName=longFilename+len-4;
          if(strcasecmp(extName,".bmp")==0)
          {
            *extName=0;
            aPaths.insert(cFileIconItem(aFolder,longFilename));
          }
        }
      }
    }
    dirclose(dir);
  }
}
Ejemplo n.º 6
0
/***************************************************************************
 * FAT_ParseDirectory
 *
 * List files into one FAT directory
 ***************************************************************************/ 
int FAT_ParseDirectory(void)
{
  int nbfiles = 0;
  char filename[MAXPATHLEN];
  struct stat filestat;

  /* open directory */
  DIR_ITER *dir = diropen (fatdir);
  if (dir == NULL) 
  {
    GUI_WaitPrompt("Error","Unable to open directory !");
    return -1;
  }

  while ((dirnext(dir, filename, &filestat) == 0) && (nbfiles < MAXFILES))
  {
    if (strcmp(filename,".") != 0)
    {
      memset(&filelist[nbfiles], 0, sizeof (FILEENTRIES));
      sprintf(filelist[nbfiles].filename,"%s",filename);
      filelist[nbfiles].length = filestat.st_size;
      filelist[nbfiles].flags = (filestat.st_mode & S_IFDIR) ? 1 : 0;
      nbfiles++;
    }
  }

  dirclose(dir);

  /* Sort the file list */
  qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);

  return nbfiles;
}
Ejemplo n.º 7
0
bool GuiBGM::ParsePath(const char * folderpath)
{
    ClearList();

    if(currentPath)
        delete [] currentPath;

    currentPath = new char[strlen(folderpath)+1];
    sprintf(currentPath, "%s", folderpath);

    char * isdirpath = strrchr(folderpath, '.');
    if(isdirpath)
    {
        char * pathptr = strrchr(currentPath, '/');
        if(pathptr)
        {
            pathptr++;
            pathptr[0] = 0;
        }
    }

    char * LoadedFilename = strrchr(folderpath, '/')+1;

    char filename[1024];
    struct stat st;

    DIR_ITER * dir = diropen(currentPath);
    if (dir == NULL)
    {
        LoadStandard();
        return false;
    }
    u32 counter = 0;

    while (dirnext(dir,filename,&st) == 0)
    {
        char * fileext = strrchr(filename, '.');
        if(fileext)
        {
            if(strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0
                || strcasecmp(fileext, ".wav") == 0)
            {
                AddEntrie(filename);

                if(strcmp(LoadedFilename, filename) == 0)
                    currentPlaying = counter;

                counter++;
            }
        }
    }

    dirclose(dir);

    snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s", folderpath);

    return true;
}
Ejemplo n.º 8
0
compat_dir_result_t
compat_readdir( compat_dir directory, char *path, size_t length )
{
  struct stat fstat;

  int done = dirnext( directory, path, &fstat );

  return done ? COMPAT_DIR_RESULT_END : COMPAT_DIR_RESULT_OK;
}
Ejemplo n.º 9
0
/***************************************************************************
 * Browse FAT subdirectories
 **************************************************************************/
int
ParseFATdirectory(int method)
{
	int nbfiles = 0;
	DIR_ITER *fatdir;
	char filename[MAXPATHLEN];
	struct stat filestat;
	char msg[128];

	// initialize selection
	selection = offset = 0;

	// Clear any existing values
	memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES);

	// open the directory
	fatdir = diropen(currentdir);
	if (fatdir == NULL)
	{
		sprintf(msg, "Couldn't open %s", currentdir);
		WaitPrompt(msg);

		// if we can't open the dir, open root dir
		sprintf(currentdir,"%s",ROOTFATDIR);

		fatdir = diropen(currentdir);

		if (fatdir == NULL)
		{
			sprintf(msg, "Error opening %s", currentdir);
			WaitPrompt(msg);
			return 0;
		}
	}

	// index files/folders
	while(dirnext(fatdir,filename,&filestat) == 0)
	{
		if(strcmp(filename,".") != 0)
		{
			memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES));
			strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN);
			strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1);	// crop name for display
			filelist[nbfiles].length = filestat.st_size;
			filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
			nbfiles++;
		}
	}

	// close directory
	dirclose(fatdir);

	// Sort the file list
	qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);

	return nbfiles;
}
Ejemplo n.º 10
0
bool PA_Locate(char *start, char *target, bool isDir, int depth, char *result)
{
   struct stat st;
   DIR_ITER *dir = diropen(start);
   static char child[256];
   char temp[256];
   
   if (dir)
   {
      while (dirnext(dir, child, &st) == 0)
      {
         if (strlen(child) == 1 && child[0] == '.')
            continue;
                  
         if (strlen(child) == 2 && child[0] == '.' && child[1] == '.')
            continue;
         
         if (((st.st_mode & S_IFDIR) && isDir) || (!(st.st_mode & S_IFDIR) && !isDir) )
         {
            if (strcasecmp(target, child) == 0) // changed from strcmp to strcasecmp
            {
               strcpy(result, start);
               if (start[strlen(start)-1] != '/')
                  strcat(result, "/");

               strcat(result, child);
               if(isDir) // only add trailing slash if we're searching for a directory
                  strcat(result, "/");
            
               dirclose(dir);
               return true;
            }
         }
            
         if ((st.st_mode & S_IFDIR) && depth > 1)
         {
            strcpy(temp, start);
            if (start[strlen(start)-1] != '/')
               strcat(temp, "/");

            strcat(temp, child);
            strcat(temp, "/");
            
            if (PA_Locate(temp, target, isDir, depth-1, result))
            {
               dirclose(dir);
               return true;
            }
         }
      }
   }
   
   dirclose(dir);
   return false;
}
Ejemplo n.º 11
0
bool Explorer_dirRead ( void )
{
        DIR_ITER *pdir = NULL;
        int ngames = 0;
        char filename[1024];
	struct stat statbuf;
        t_fslist pnode;

	if(!WiiStatus.Dev_Fat)
		return false;

	pdir=diropen(current_path);

	if (!pdir){
	    printf ("opendir() failure; terminating\n");
		return false;
	}

        while(dirnext(pdir,filename,&statbuf) == 0){

	   if(S_ISDIR(statbuf.st_mode))
	   	continue;

	   if(strlen(current_path) + strlen(filename) >= 1024){
                continue; //path demasiado largo, saltamos
           }

           lowercase (filename, false);

           if ( memcmp((char*) &filename[(strlen(filename)-4)], ".zip", 4) != 0) 
		continue;

	   if(!_FileList_UpdateFile(filename, SU_SD))
	   {
		FileList_Init(&pnode); //cleaning node

		_nfoRead(&pnode.game, filename);
		strcpy(pnode.gfile.filename, filename);
		pnode.gfile.location = SU_SD;

		if(_FileList_InsertGame(&pnode)) // TODO: HACER FLUSH PARA EVITAR CUELGUES? 
			ngames++; //to use in debug mode

           }


	}

        dirclose(pdir);

	return true;

}
Ejemplo n.º 12
0
bool HomebrewFiles::LoadPath(const char * folderpath) {
    struct stat st;
    DIR_ITER *dir = NULL;
    char filename[1024];

    dir = diropen(folderpath);
    if (dir == NULL) {
        return false;
    }

    while (dirnext(dir,filename,&st) == 0) {
        if ((st.st_mode & S_IFDIR) != 0) {
            if (strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) {
                char currentname[200];
                snprintf(currentname, sizeof(currentname), "%s%s/", folderpath, filename);
                this->LoadPath(currentname);
            }
        } else {
            char temp[5];
            for (int i = 0; i < 5; i++) {
                temp[i] = filename[strlen(filename)-4+i];
            }

            if ((strncasecmp(temp, ".dol", 4) == 0 || strncasecmp(temp, ".elf", 4) == 0)
                    && filecount < MAXHOMEBREWS && filename[0]!='.') {

                FileInfo = (FileInfos *) realloc(FileInfo, (filecount+1)*sizeof(FileInfos));

                if (!FileInfo) {
                    free(FileInfo);
                    FileInfo = NULL;
                    filecount = 0;
                    dirclose(dir);
                    return false;
                }

                memset(&(FileInfo[filecount]), 0, sizeof(FileInfo));

                strlcpy(FileInfo[filecount].FilePath, folderpath, sizeof(FileInfo[filecount].FilePath));
                strlcpy(FileInfo[filecount].FileName, filename, sizeof(FileInfo[filecount].FileName));
                FileInfo[filecount].FileSize = st.st_size;
                filecount++;
            }
        }
    }
    dirclose(dir);

    return true;
}
Ejemplo n.º 13
0
void NDSDir::GetContent(char *mask) {

	Empty() ;
        
    
    // Read directory content

	char fullpath[81] ;
	strcpy(fullpath,((NDSFileSystem *)NDSFileSystem::GetInstance())->root_) ;
	strcat(fullpath,path_) ;

	Trace::Debug("Reading path content for %s",fullpath) ;
 
    DIR_ITER* directory = diropen (fullpath);

	if (directory == NULL) {
		Trace::Dump("Failed to open %s",fullpath) ;
		return ;
	}

    struct stat st;
    char filename[256];

	while (dirnext(directory, filename, &st) == 0) {
 		char current[128] ;
        strcpy(current,filename) ;
        char *c=current ;
		while(*c) {
            *c=tolower(*c) ;
            c++ ;
        }
        Trace::Dump("testing mask") ;
        
        if (wildcardfit (mask,current)) {
            strcpy(current,filename) ;
            Trace::Dump("Inserting %s/%s",path_,current) ;
			sprintf(fullpath,"%s/%s",path_,current) ;
			Path *path=new Path(fullpath) ;
			Insert(path) ;
		} else {
            Trace::Dump("skipping %s",current) ;
        }
	
    } ;   
	dirclose(directory);
	
};
Ejemplo n.º 14
0
bool neoSystemInit()
{
	irqSet(IRQ_IPC_SYNC, neoSystemIPCSync);

	linearHeapInit(&g_vramHHeap, (void*)0x6898000, 32*KB);

	systemWriteLine("sizeof(TNeoContext): %d", sizeof(TNeoContext));
	systemWriteLine(" -> varEnd: %d", OFFSET(TNeoContext, varEnd));

	g_romCount = 0;
	memset(g_romNames, 0, sizeof(g_romNames));

	DIR_ITER* dir;
	struct stat st;
	char szFilename[256];

	dir = diropen("/");
	if(!dir) {
		return false;
	}

	while(g_romCount < NEO_ROM_MAX && dirnext(dir, szFilename, &st) == 0) {
		if(st.st_mode & S_IFDIR) {
			continue;
		}
		const char* szExt = strchr(szFilename, '.');
		if(strcmpi(".NEO", szExt)) {
			continue;
		}
		
		g_romCount++;
		g_romNames[g_romCount - 1] = strdup(szFilename);
		ASSERT(g_romNames[g_romCount - 1]);
	}
	qsort(g_romNames, g_romCount, sizeof(const char*), stringCompare);

	dirclose(dir);

	neoResetContext();
	neoSystemSetClockDivide(2);

	return true;
}
Ejemplo n.º 15
0
bool SearchFile(const char * searchpath, const char * searched_filename, char * outfilepath)
{
    struct stat st;
    DIR_ITER *dir = NULL;
    bool result = false;

    char filename[1024];
    char pathptr[strlen(searchpath)+1];
    snprintf(pathptr, sizeof(pathptr), "%s", searchpath);

    if(pathptr[strlen(pathptr)-1] == '/')
    {
        pathptr[strlen(pathptr)-1] = '\0';
    }

    dir = diropen(pathptr);
    if(!dir)
        return false;

    while (dirnext(dir,filename,&st) == 0 && result == false)
	{
	    if(strcasecmp(filename, searched_filename) == 0)
	    {
	        if(outfilepath)
	        {
	            sprintf(outfilepath, "%s/%s", pathptr, filename);
	        }
	        result = true;
	    }
        else if((st.st_mode & S_IFDIR) != 0)
        {
            if(strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0)
            {
                char newpath[1024];
                snprintf(newpath, sizeof(newpath), "%s/%s", pathptr, filename);
                result = SearchFile(newpath, searched_filename, outfilepath);
            }
        }
	}
    dirclose(dir);

    return result;
}
Ejemplo n.º 16
0
int GetAllDirFiles(char * filespath) {
    int countfiles = 0;

    struct stat st;
    DIR_ITER* dir;
    dir = diropen (filespath);

    if (dir == NULL) //If empty
        return 0;
    while (dirnext(dir,filenames,&st) == 0) {
        if ((st.st_mode & S_IFDIR) == 0) {
            // st.st_mode & S_IFDIR indicates a directory
            snprintf(alldirfiles[countfiles], 70, "%s", filenames);
            countfiles++;
        }
    }
    dirclose(dir);
    qsort(alldirfiles, countfiles, sizeof(char[70]), filenamescmp);
    return countfiles;
}
Ejemplo n.º 17
0
/***************************************************************************
 * Browse SDCARD subdirectories 
 ***************************************************************************/ 
int parseSDdirectory() {
    int nbfiles = 0;
    DIR_ITER *sddir;
    char filename[MAXPATHLEN];
    struct stat filestat;
        char msg[128];
    
    /* initialize selection */
    selection = offset = 0;

    /* open the directory */ 
    sddir = diropen(currSDdir);
    if (sddir == NULL) {
        sprintf(currSDdir,"%s",rootSDdir);	// if we can't open the previous dir, open root dir
        sddir = diropen(currSDdir);
        WaitPrompt(msg);
        if (sddir == NULL) {
            sprintf(msg, "Error opening %s", currSDdir);
            WaitPrompt(msg);
            return 0;
        }
    }
    
  /* Move to DVD structure - this is required for the file selector */ 
    while(dirnext(sddir,filename,&filestat) == 0) {
        if(strcmp(filename,".") != 0) {
            memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES));
            strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN);
			strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1);	// crop name for display
            filelist[nbfiles].length = filestat.st_size;
            filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1;
            nbfiles++;
        }
	}
  
    /*** close directory ***/
    dirclose(sddir);
  
    return nbfiles;
}
Ejemplo n.º 18
0
bool subfolderremove(const char * fullpath, const char*fp) {
	struct stat st;
	if (stat(fullpath, &st) != 0) // fullpath not exist?
		return false;
	if(S_ISDIR(st.st_mode))
	{
		DIR_ITER *dir = NULL;
		char filename[256];
		bool cont = true;
		while(cont)
		{
			cont = false;
			dir = diropen(fullpath);
			if(dir)
			{
				char* bind = fullpath[strlen(fullpath)-1] == '/' ? "":"/";
				while (dirnext(dir,filename,&st) == 0)
				{
					if (strcmp(filename,".") != 0 && strcmp(filename,"..") != 0)
					{
						char currentname[256];
						if(S_ISDIR(st.st_mode))
							snprintf(currentname, sizeof(currentname), "%s%s%s/", fullpath, bind, filename);
						else
							snprintf(currentname, sizeof(currentname), "%s%s%s", fullpath, bind, filename);
						subfolderremove(currentname, fp);
						cont = true;
						break;
					}
				}
				dirclose(dir);
			}
		}
	}
	return unlink(fullpath) == 0;
}
Ejemplo n.º 19
0
void getFiles ()
{
        int index;
        char name[MAXPATHLEN];

        DIR_ITER *iter = diropen(bPath);
        struct stat fstat;

        if (list != NULL)
        {
                free(list);
                list = NULL;
                fCount = 0;
        }

        list = malloc(sizeof(item));

        if (iter == NULL)
        {
                return;
        }

        index = 0;

        while (dirnext(iter, name, &fstat) == 0)
        {
                list = (item *)realloc(list, sizeof(item) * (index + 1));
                memset(&(list[index]), 0, sizeof(item));
                
                sprintf(list[index].name, "%s", name);
                
                if (fstat.st_mode & S_IFDIR)
                {
                        list[index].size = 0;
                }
                else
                {
                        list[index].size = fstat.st_size;
                }
                
                if (matchStr(list[index].name, "."))
                {
                        sprintf(list[index].labl, "[Current directory]");
                }
		else if (matchStr(list[index].name, ".."))
                {
                        sprintf(list[index].labl, "[Parent directory]");
                }
                else
                {
			if (list[index].size > 0)
			{
				sprintf(list[index].labl, "%.40s", list[index].name);
			}
			else
			{
				sprintf(list[index].labl, "[%.380s]", list[index].name);
			}
                }
                
                index++;
        }

        dirclose(iter);

        fCount = index;
}
Ejemplo n.º 20
0
int* wiimenu_buildgamelist(char* root, gamelistentry* gamelist, int max, \
			   gamelistentry *gamesunk, gamelistentry *gamesfdd, gamelistentry *gameshdd)
{
	int i = 0;
	int *sizes = malloc(sizeof(int) * BASETYPE_COUNT);
	gamelistentry *games;
	memset(sizes, 0, BASETYPE_COUNT * sizeof(int));
	DIR_ITER * dirIter = NULL;
	dirIter = diropen(root);
	if(dirIter == NULL) {
#ifdef DEBUG_NP2
		printf("Couldn't open %s\n", root);
		sleep(5);
#endif //DEBUG_NP2
		return NULL;
	}
	char filename[MAXPATHLEN];
        struct stat filestat;
	int res;
	int type, basetype;
        for(i = 0; i < max; i++) {
		if(time_to_leave)
			break;
		res = dirnext(dirIter, filename, &filestat);
		
		if(res != 0)
			break;
		char *origname = strdup(filename);
		MakeLowercase(filename);
		type = GetFiletype(filename);
		basetype = GetBasetype(type);
		
		switch(basetype) {
			case BASETYPE_UNKNOWN:
				games = gamesunk;
				break;
			case BASETYPE_FDD:
				games = gamesfdd;
				break;
			case BASETYPE_HDD:
				games = gameshdd;
				break;
		}
		games[sizes[basetype]].path = calloc(strlen(filename) + 1, 1);
		strncpy(games[sizes[basetype]].path, filename, strlen(filename));
		games[sizes[basetype]].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1;
		games[sizes[basetype]].type = type;
		games[sizes[basetype]].basetype = basetype;
		
		if(games[sizes[basetype]].isdir) {
			if(strcmp(filename, "..") == 0)
				sizes[basetype]--;
			else if(strcmp(filename, ".") == 0)
				sizes[basetype]--;
			else {
				games[sizes[basetype]].name = calloc(strlen(origname) + 1, 1);
				strncpy(games[sizes[basetype]].name, origname, strlen(origname) + 1);
			}
		}else{
			games[sizes[basetype]].name = calloc(strlen(origname) + 1, 1);
			strncpy(games[sizes[basetype]].name, origname, strlen(origname) + 1);
		}
		sizes[basetype]++;
	}
	
	// Sort the file lists
        if(sizes[BASETYPE_UNKNOWN] >= 0)
		qsort(gamesunk, sizes[BASETYPE_UNKNOWN], sizeof(gamelistentry), sortgames_cb);
        if(sizes[BASETYPE_HDD] >= 0)
		qsort(gameshdd, sizes[BASETYPE_HDD], sizeof(gamelistentry), sortgames_cb);
        if(sizes[BASETYPE_FDD] >= 0)
		qsort(gamesfdd, sizes[BASETYPE_FDD], sizeof(gamelistentry), sortgames_cb);
	
	dirclose(dirIter);	// close directory
	return sizes;
}
Ejemplo n.º 21
0
//---------------------------------------------------------------------------------
void menu_scandir()
//---------------------------------------------------------------------------------
{
	char filename[MAXPATHLEN];
	char tempfilename[MAXPATHLEN];

	DIR_ITER *pdir;
	struct stat fstat;

	pdir=diropen("/files");

	if( filelist == NULL )
	{
		numfiles = 0;
		afiles = 8;
		filelist = (struct foundfile *)malloc( sizeof( struct foundfile ) * afiles );
	}

	numfiles = 0;
	idcount = 0;

	while( dirnext(pdir, filename, &fstat ) == 0 )
	{
		
		// if directory then continue
		if( fstat.st_mode & S_IFDIR ){
			continue;
		}

		if( numfiles == afiles )
		{
			afiles += 4;
			filelist = realloc(filelist, afiles * sizeof( struct foundfile ) );
		}

		filename[MAXPATHLEN-1] = 0;
		
		strncpy(tempfilename, filename, MAXPATHLEN );

		int i = strlen(tempfilename);	// get length of files
		
		if(stricmp(&tempfilename[i-4], ".dol") == 0)
		{
			filelist[numfiles].name[MAXPATHLEN-1] = 0;
			strncpy(filelist[numfiles].showname, tempfilename, 40 );
			filelist[numfiles].showname[39] = 0;
			filelist[numfiles].size = fstat.st_size;
			filelist[numfiles].type = 0;
			filelist[numfiles].id = idcount;
			idcount++;
			numfiles++;
		}

		if(stricmp(&tempfilename[i-4], ".elf") == 0)
		{
			filelist[numfiles].name[MAXPATHLEN-1] = 0;
			strncpy(filelist[numfiles].showname, tempfilename, 40 );
			filelist[numfiles].showname[39] = 0;
			filelist[numfiles].size = fstat.st_size;
			filelist[numfiles].type = 1;
			filelist[numfiles].id = idcount;
			idcount++;
			numfiles++;
		}

		if(stricmp(&tempfilename[i-4], ".wad") == 0)
		{
			filelist[numfiles].name[MAXPATHLEN-1] = 0;
			strncpy(filelist[numfiles].showname, tempfilename, 40 );
			filelist[numfiles].showname[39] = 0;
			filelist[numfiles].size = fstat.st_size;
			filelist[numfiles].type = 2;
			filelist[numfiles].id = idcount;
			idcount++;
			numfiles++;
		}

		if(stricmp(&tempfilename[i-4], ".mp3") == 0)
		{
			filelist[numfiles].name[MAXPATHLEN-1] = 0;
			strncpy(filelist[numfiles].showname, tempfilename, 40 );
			filelist[numfiles].showname[39] = 0;
			filelist[numfiles].size = fstat.st_size;
			filelist[numfiles].type = 3;
			filelist[numfiles].id = idcount;
			idcount++;
			numfiles++;
		}
	}
	dirclose( pdir );
}
Ejemplo n.º 22
0
		void frontend(void)
		{

			u32 cursor = 0;
			u32 cursor_modulus = 4;

			// option 0
			u32 missionpack_selected = 0;
			u32 missionpack_have = 1; // bitmask 1 = standard, 2 = scourge of armagon (hipnotic), 4 = dissolution of eternity (rogue)
			const char *missionpack_names[3] = {"Standard Quake", "Scourge of Armagon", "Dissolution of Eternity" };

			// option 1
			u32 mods_selected = 0;
			std::vector<std::string> mods_names;

			// option 2
			u32 network_disable = 0;

			// option 3
			u32 listen_players = 4;

			// find mods / mission packs, some code from snes9x-gx 1.51
			mods_names.push_back("None");

			DIR_ITER *fatdir;
			char filename[MAXPATHLEN];
			struct stat filestat;

			fatdir = diropen(QUAKE_WII_BASEDIR);
			if (!fatdir)
				Sys_Error("Error opening %s for read.\n", QUAKE_WII_BASEDIR);

			while (dirnext(fatdir, filename, &filestat) == 0)
			{
				if ((filestat.st_mode & _IFDIR) && strcmp(filename, ".") && strcmp(filename, "..") && strcasecmp(filename, "ID1"))
				{
					if(!strcasecmp(filename, "hipnotic"))
						missionpack_have |= 2;
					else if(!strcasecmp(filename, "rogue"))
						missionpack_have |= 4;
					else
						mods_names.push_back(filename);
				}
			}

			dirclose(fatdir);
	
			sort(mods_names.begin(), mods_names.end());

			while (1)
			{
				PAD_ScanPads();
				WPAD_ScanPads();

				u32 gcpress, wmpress;
				gcpress = PAD_ButtonsDown(0) | PAD_ButtonsDown(1) | PAD_ButtonsDown(2) | PAD_ButtonsDown(3);
				wmpress = WPAD_ButtonsDown(0) | WPAD_ButtonsDown(1) | WPAD_ButtonsDown(2) | WPAD_ButtonsDown(3);
				bool up = (gcpress & PAD_BUTTON_UP) | (wmpress & WPAD_BUTTON_UP);
				bool down = (gcpress & PAD_BUTTON_DOWN) | (wmpress & WPAD_BUTTON_DOWN);
				bool left = (gcpress & PAD_BUTTON_LEFT) | (wmpress & WPAD_BUTTON_LEFT);
				bool right = (gcpress & PAD_BUTTON_RIGHT) | (wmpress & WPAD_BUTTON_RIGHT);
				bool start = (gcpress & PAD_BUTTON_START) | (wmpress & WPAD_BUTTON_PLUS);

				printf("\x1b[2;0H");
				// ELUTODO: use CONF module to configure certain settings according to the wii's options
				printf("\n\n\n\n\n\n     If the Nunchuk isn't detected, please reconnect it to the wiimote.\n     Oh, and don't forget to put your wrist wrap! :)\n\n");

				if (up)
					cursor = (cursor - 1 + cursor_modulus) % cursor_modulus;
				if (down)
					cursor = (cursor + 1) % cursor_modulus;
				if (left)
				{
					switch (cursor)
					{
						case 0:
							missionpack_selected = (missionpack_selected - 1 + 3) % 3;
							break;
						case 1:
							mods_selected = (mods_selected - 1 + mods_names.size()) % mods_names.size();
							break;
						case 2:
							network_disable = !network_disable;
							break;
						case 3:
							listen_players--;
							if (listen_players < 4)
								listen_players = 4;
							break;
						default:
							Sys_Error("frontend: Invalid cursor position");
							break;
					}
				}
				if (right)
				{
					switch (cursor)
					{
						case 0:
							missionpack_selected = (missionpack_selected + 1) % 3;
							break;
						case 1:
							mods_selected = (mods_selected + 1) % mods_names.size();
							break;
						case 2:
							network_disable = !network_disable;
							break;
						case 3:
							listen_players++;
							if (listen_players > 16)
								listen_players = 16;
							break;
						default:
							Sys_Error("frontend: Invalid cursor position");
							break;
					}
				}


				if (start)
				{
					printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n     Starting Quake...\n\n\n\n");
					break;
				}

				printf("\n\n     Press UP, DOWN, LEFT, RIGHT to make your selections\n");
				printf("     Press START/PLUS to start the game\n\n");

				printf("     %c Mission Pack:      %s%s\n", cursor == 0 ? '>' : ' ', missionpack_names[missionpack_selected],
					(missionpack_have & (1 << missionpack_selected)) ? "                              " : " (You don't have it!)         ");

				const u32 mods_maxprintsize = 32;
				char mods_printvar[mods_maxprintsize];
				strncpy(mods_printvar, mods_names[mods_selected].c_str(), mods_maxprintsize);
				size_t mods_printsize = strlen(mods_printvar);
				u32 i;
				for (i = mods_printsize; i < mods_maxprintsize - 1; i++)
					mods_printvar[i] = ' ';
				mods_printvar[i] = '\0';

				printf("     %c Mod:               %s\n", cursor == 1 ? '>' : ' ', mods_printvar);

				printf("     %c Disable Network:   %s\n", cursor == 2 ? '>' : ' ', network_disable ? "yes" : "no ");

				printf("     %c Max Network Slots: %u   \n", cursor == 3 ? '>' : ' ', listen_players);

				printf("\n\n\n     Network is experimental, may fail randomly.\n     Please activate it to use bots.\n");

				VIDEO_WaitVSync();

			}

			// Initialise the Common module.
			add_parm("Quake");
#if CONSOLE_DEBUG
			add_parm("-condebug");
#endif
			if (missionpack_have & (1 << missionpack_selected))
			{
				switch(missionpack_selected)
				{
					case 0:
						break;
					case 1:
						add_parm("-hipnotic");
						break;
					case 2:
						add_parm("-rogue");
						break;
					default:
						Sys_Error("frontend: Invalid mission pack selected");
						break;
				}
			}

			if (mods_selected)
			{
				add_parm("-game");
				add_parm(mods_names[mods_selected].c_str()); // ELUTODO: bad thing to do?
			}

			if (network_disable)
			{
				add_parm("-noudp");
			}
			else
			{
				char temp_num[32];
				snprintf(temp_num, 32, "%u", listen_players);
				add_parm("-listen");
				add_parm(temp_num);
			}
		}
Ejemplo n.º 23
0
//Creates the random music array (fist time through) and retrieves the
// filepath of the next music file to play.
void get_random_file(char *filetype, char *path)
{
	DIR_ITER *dir = NULL;
	char filename[1024];
	int cnt = 0;
	int next = 0;
	struct stat filestat;
	
	if (fileCount==0 && !first_time) goto out;
	
	dbg_printf(gt("Music: Looking for %s files in: %s"), filetype, path);
		dbg_printf("\n");

	// Open directory
	//snprintf(dirname, sizeof(dirname), "%s", path);
	dir = diropen(path);
	if (!dir) return;

	if (first_time) {
		while (!dirnext(dir, filename, &filestat)) {
			// Ignore invalid entries
			if (match_ext(filename, filetype) && !(filestat.st_mode & S_IFDIR))
				fileCount++;
		}
		dbg_printf(gt("Music: Number of %s files found: %i"), filetype, fileCount);
		dbg_printf("\n");

		first_time = false;
		//if no files found then no need to continue
		if (fileCount==0) goto out;
		
		//allocate the random music array
		musicArray = realloc(musicArray, fileCount * sizeof(int));
		if (!musicArray) {
			fileCount = 0;
			goto out;
		}
		initializeArray(musicArray, fileCount);
		randomizeArray(musicArray, fileCount);

		//check array contents
		int i;
		dbg_printf(gt("Music: musicArray contents: "));
		for (i=0; i<fileCount; i++)
			dbg_printf("%i ", musicArray[i]);
		dbg_printf("\n");

		//reset the directory
		dirreset(dir);
	}

	if (fileCount > 0) {
		//get the next file index
		lastPlayed++;
		if (lastPlayed > fileCount-1) lastPlayed = 0;
		next = musicArray[lastPlayed];
		dbg_printf(gt("Music: Next file index to play: %i"), next);
		dbg_printf("\n");
		
		//iterate through and find our file
		while (!dirnext(dir, filename, &filestat)) {
			if (match_ext(filename, filetype) && !(filestat.st_mode & S_IFDIR)) {
				cnt++;
				if (cnt==next) {
					//save path
					snprintf(music_fname, sizeof(music_fname), "%s/%s", path, filename);
					goto out;
				}
			}
		}
	}

	out:;
	//close the directory
	dirclose(dir);	 
}
Ejemplo n.º 24
0
	/** Get the file structure at dirname
	 * @param dirname Directory to check
	 * @return Echo_file structure, with the file names of that directory
	 */
	echo_files* get_files(const char* dirname)
	{
		/// Open the directory
		DIR_ITER* dir = diropen(dirname);
		/// It exists...
		if(dir != NULL)
		{
			/// New file structure
			echo_files* ret = new(echo_files);
			
			
			/// Set fields
			ret->num_files = 0;
			ret->current_dir = const_cast<char*>(dirname);
			ret->num_dir = 0;
			
			/// Set stats
			struct stat each_ent;
			/// Buffer to save file names
			char* filename = new char[MAXPATHLEN];
			
			while(dirnext(dir, filename, &each_ent) == 0)
			{
				/// If the file is not "."
				if(strcmp(filename, "."))
				{
					/// Increment number of files (both directories and regular files)
					ret->num_files++;
					/// If it's a directory...
					if(S_ISDIR(each_ent.st_mode))
						/// ...increment the number of directories
						ret->num_dir++;
				}
			}
			/// Make a new array
			ret->file_names = new char*[ret->num_files];
			
			/// First file always ".."
			ret->file_names[0] = "..";
			/** each_dir is the directory index (1 because ".." is already filled)
			 * each_file is the regular file index
			 * each is one of them
			 */
			int each_dir = 1, each_file = ret->num_dir, each = 1;
			/// Rewind back
			dirreset(dir);
			/// For each file entry
			while(dirnext(dir, filename, &each_ent) == 0)
			{
				/// If it's not "." or ".."
				if(strcmp(filename, ".") && strcmp(filename, ".."))
				{
					/// If it's a directory...
					if(S_ISDIR(each_ent.st_mode))
					{
						/// Use the directory index
						each = each_dir;
						each_dir++;
					}
					/// Else, it's a reg. file...
					else
					{
						/// Use the reg. file index
						each = each_file;
						each_file++;
					}
					/// Copy the file name over
					ret->file_names[each] = new char[strlen(filename) + 1];
					
					memset(ret->file_names[each], 0
						, strlen(filename) + 1);
					strcpy(ret->file_names[each], filename);
				}
			}
			/// Delete the buffer
			delete[] filename;
			/// Close the directory
			dirclose(dir);
			/// Sort the directories
			qsort(ret->file_names, ret->num_dir, sizeof(char*), cmp);
			/// Sort the reg. files
			qsort(ret->file_names + ret->num_dir
				, ret->num_files - ret->num_dir, sizeof(char*), cmp);
			/// Return files
			return(ret);
		}
		return(NULL);
	}
Ejemplo n.º 25
0
int main(void) {

    // init PA_Lib
    PA_Init();
    PA_InitVBL();
	
    PA_InitText(1, 0);
    PA_InitText(0, 0);
    
    // init EFSlib & libfat
    if(EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE, NULL)) {
        PA_OutputSimpleText(1, 0, 0, "EFS init ok");
        PA_OutputText(1, 0, 1, "found NDS path: %s", efs_path);    
        
        DIR_ITER* dir;
        struct stat st;
        s8 nb;
        FILE* file;
        u8* buffer;
        int i, size;

        // open a text file and read its contents
        file = fopen("/test.txt", "rb");
        if(file != NULL) {
            // get file size using stat            
            stat("/test.txt", &st);
            size = st.st_size;
            
            buffer = (u8*)malloc(size);
            fread(buffer, 1, size, file);
            buffer[size-1] = '\0';
            PA_OutputText(1, 0, 4, "/test.txt content: '%s'", buffer);
            PA_OutputText(1, 10, 5, "size: %d bytes", size);
            free(buffer);
            fclose(file); 
        }

        // open another file, read its content
        file = fopen("/folder/test.txt", "rb");
        if(file != NULL) {
            // get file size
            fseek(file, 0, SEEK_END);
            size = ftell(file); 
            fseek(file, 0, SEEK_SET);

            buffer = (u8*)malloc(size);
            fread(buffer, 1, size, file);
            buffer[size-1] = '\0';
            PA_OutputText(1, 0, 7, "/folder/test.txt content:\n%s", buffer);
            free(buffer); 
            fclose(file);
        }
            
        // reopen the file, modify its content
        file = fopen("/folder/test.txt", "rb+");
        if(file != NULL) {
            nb = fwrite("16b Written OK!", 1, 16, file);
            PA_OutputText(1, 0, 10, "write test done! : %d bytes", nb);
            fclose(file);
        }

        // reopen another file, read its content again, 1 byte at a time
        file = fopen("/folder/dummy/.././test.txt", "rb");  // funky path to test relative path parsing
        if(file != NULL) {
            // get file size
            fseek(file, 0, SEEK_END);
            size = ftell(file); 
            fseek(file, 0, SEEK_SET);

            buffer = (u8*)malloc(size);
            
            i = 0;
            while(i < size) {
                fread(&buffer[i], 1, 1, file);
                i++;
            }
            
            buffer[size-1] = '\0';
            PA_OutputText(1, 0, 12, "/folder/test.txt new content:\n%s", buffer);
            free(buffer); 
            fclose(file);
        }

        PA_OutputSimpleText(1, 0, 15, "Press A for directory tests.");
        PA_WaitFor(Pad.Newpress.A);

        // open root directory then list its content
        PA_OutputText(0, 0, 0, "Listing '/' directory:");
        dir = diropen(".");
        
        if(dir != NULL) {
            i = 0;
            buffer = (u8*)malloc(EFS_MAXNAMELEN);

            while(!(dirnext(dir, (char*)buffer, &st))) {
                if(st.st_mode & S_IFDIR)
                    PA_OutputText(0, 0, i++, "DIR : %s", buffer);
                else
                    PA_OutputText(0, 0, i++, "FILE: %s, %d bytes", buffer, st.st_size);
            }
            
            PA_OutputSimpleText(0, 0, i++, "end of directory.");
            PA_OutputSimpleText(0, 0, i++, "directory reset, first file is:");
            
            dirreset(dir);
            dirnext(dir, (char*)buffer, &st);
            if(st.st_mode & S_IFDIR)
                PA_OutputText(0, 0, i++, "DIR : %s", buffer);
            else
                PA_OutputText(0, 0, i++, "FILE: %s, %d bytes", buffer, st.st_size);
            
            dirclose(dir);
            free(buffer);
        }

        // chdir to a directory then list its content
        PA_OutputSimpleText(0, 0, i++, "Listing '/list/' directory:");
        chdir("/list/");
        dir = diropen("./");
        
        if(dir != NULL) {
            buffer = (u8*)malloc(EFS_MAXNAMELEN);
            
            while(!(dirnext(dir, (char*)buffer, &st))) {
                if(st.st_mode & S_IFDIR)
                    PA_OutputText(0, 0, i++, "DIR : %s", buffer);
                else
                    PA_OutputText(0, 0, i++, "FILE: %s, %d bytes", buffer, st.st_size);
            }
            
            PA_OutputSimpleText(0, 0, i++, "end of directory.");
            dirclose(dir);
            free(buffer);
        }

    } else {
        PA_OutputSimpleText(1, 0, 0, "EFS init error!");
    }

    while(1) {
        PA_WaitForVBL();
    }

    return 0;
}
Ejemplo n.º 26
0
s32 __Menu_RetrieveList(char *inPath, fatFile **outbuf, u32 *outlen)
{
	fatFile  *buffer = NULL;
	DIR_ITER *dir    = NULL;

	struct stat filestat;

	//char dirpath[256], filename[768];
	u32  cnt;

	/* Generate dirpath */
	//sprintf(dirpath, "%s:" WAD_DIRECTORY, fdev->mount);

	/* Open directory */
	dir = diropen(inPath);
	if (!dir)
		return -1;

	/* Count entries */
	for (cnt = 0; !dirnext(dir, gFileName, &filestat);) {
		// if (!(filestat.st_mode & S_IFDIR)) // wiiNinja
			cnt++;
	}

	if (cnt > 0) {
		/* Allocate memory */
		buffer = malloc(sizeof(fatFile) * cnt);
		if (!buffer) {
			dirclose(dir);
			return -2;
		}

		/* Reset directory */
		dirreset(dir);

		/* Get entries */
		for (cnt = 0; !dirnext(dir, gFileName, &filestat);)
		{
			bool addFlag = false;
			
			if (filestat.st_mode & S_IFDIR)  // wiiNinja
            {
                // Add only the item ".." which is the previous directory
                // AND if we're not at the root directory
                if ((strcmp (gFileName, "..") == 0) && (gDirLevel > 1))
                    addFlag = true;
                else if (strcmp (gFileName, ".") != 0)
                    addFlag = true;
            }
            else
			{
				if(strlen(gFileName)>4)
				{
					if(!stricmp(gFileName+strlen(gFileName)-4, ".wad"))
						addFlag = true;
				}
			}

            if (addFlag == true)
            {
				fatFile *file = &buffer[cnt++];

				/* File name */
				strcpy(file->filename, gFileName);

				/* File stats */
				file->filestat = filestat;
			}
		}

		/* Sort list */
		qsort(buffer, cnt, sizeof(fatFile), __Menu_EntryCmp);
	}

	/* Close directory */
	dirclose(dir);

	/* Set values */
	*outbuf = buffer;
	*outlen = cnt;

	return 0;
}
Ejemplo n.º 27
0
 void uiOpenNotebook(AppState & state) {
   lcdMainOnTop();

   DIR_ITER* dir = diropen (MAINPATH);
   if (dir == NULL) {
     printf("Marginalia data not found\n");
     return;
   }

   printf("\x1b[2J");
   printf("Select notebook to open\n(Press Select to create NEW)");

   struct stat st;
   char filename[MAXPATHLEN];
   int i=0;

   std::vector<std::string> notebooks;

   while (dirnext(dir, filename, &st) == 0) {
     // st.st_mode & S_IFDIR indicates a directory
     // if (!(st.st_mode & S_IFDIR))
     //   continue;
     // if (strcmp(filename, "..") == 0)
     //   continue;
     // if (strcmp(filename, ".") == 0)
     //   continue;
     printf ("\x1b[%d;3H%d)   %s\n", i+3, i, filename);
     notebooks.push_back(filename);
     i++;
   }
   dirclose (dir);
   int selected = 0;
   printf ("\x1b[%d;6H*", selected+3);
   
   while (1) {
    scanKeys();
    
    if(keysHeld() & KEY_TOUCH)
      {
      }    
    if (keysDown() & KEY_X) {
    }
    if (keysDown() & KEY_Y) {
    }
    if (keysDown() & KEY_SELECT) {
      printf ("\x1b[10;1H Insert new Directory Name");
      char newName[256];

      Keyboard *kbd =  keyboardDemoInit();

      scanf("%s", newName);
      printf ("\x1b[11;1H Creating directory %s", newName);

      state.notebookName = newName;
      if (mkdir(state.notebookName.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0) {
	printf ("\x1b[12;1H directory creation failed");
	continue;
      }
      
      state.lastPage = -1;
      state.scroll_x = 0;
      state.scroll_y = 0;

      state.center_x = MY_BG_W/2;
      state.center_y = MY_BG_H/2;

      fillDisplay(RGB15(0,0,0) | BIT(15), 0, state);

      std::string fileName = state.notebookName + "/notes.txt";
      state.notebook = loadFile(fileName.c_str());
      state.currentPage = &(state.notebook.pages[0]);

      drawPage(state.currentPage, RGB15(31,31,31) | BIT(15), state);
      lcdMainOnBottom();
      return;
    }
    if (keysDown() & KEY_A) {
      printf ("\x1b[20;6H opening %s\n", notebooks[selected].c_str());
      state.lastPage = -1;
      state.scroll_x = 0;
      state.scroll_y = 0;

      state.center_x = MY_BG_W/2;
      state.center_y = MY_BG_H/2;

      state.notebookName = notebooks[selected];

      fillDisplay(RGB15(0,0,0) | BIT(15), 0, state);

      std::string fileName = state.notebookName + "/notes.txt";
      state.notebook = loadFile(fileName.c_str());
      state.currentPage = &(state.notebook.pages[0]);

      drawPage(state.currentPage, RGB15(31,31,31) | BIT(15), state);
      lcdMainOnBottom();
      return;
    }
    if (keysDown() & KEY_B) {
    }
    if (keysDown() & KEY_LEFT) {
    }
    if (keysDown() & KEY_RIGHT) {
    }
    if (keysDown() & KEY_UP) {
      printf ("\x1b[%d;6H ", selected+3);
      selected -= 1;
      printf ("\x1b[%d;6H*", selected+3);
    }
    if (keysDown() & KEY_DOWN) {
      printf ("\x1b[%d;6H ", selected+3);
      selected += 1;
      printf ("\x1b[%d;6H*", selected+3);
    }

    swiWaitForVBlank();
  }
 }