Пример #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;
}
Пример #2
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;
}
Пример #3
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;
}
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;
}
Пример #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);
  }
}
Пример #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;
}
Пример #7
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;
} 
Пример #8
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;
}
Пример #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;
}
Пример #10
0
bool FatIsMounted(PARTITION_INTERFACE partition) {
    char prefix[] = "fatX:/";
    prefix[3] = partition + '0';
    DIR_ITER *dir = diropen(prefix);
    if (dir) {
        dirclose(dir);
        return true;
    }
    return false;
}
Пример #11
0
void initialise_fat() {
	__io_wiisd.startup();
	if (!fatInitDefault())
		die("Unable to initialise FAT subsystem, exiting.\n");
	fatMountSimple("sd", &__io_wiisd);
	DIR_ITER *root = diropen("/");
	if (!root)
		die("Cannot open root dir, exiting.\n");
	dirclose(root);
	if (chdir("/"))
		die("Could not change to root directory, exiting.\n");
}
Пример #12
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;

}
Пример #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);
	
};
Пример #14
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;
}
Пример #15
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;
}
Пример #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;
}
Пример #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;
}
Пример #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;
}
Пример #19
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 );
}
Пример #20
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);
			}
		}
Пример #21
0
/****************************************************************************
 * OpenFAT
 *
 * Function to load a FAT directory and display to user.
 ****************************************************************************/ 
int FAT_Open(int type)
{
  int max = 0;
  char root[10] = "";

  /* FAT header */
#ifdef HW_RVL
  if (type == TYPE_SD) sprintf (root, "sd:");
  else if (type == TYPE_USB) sprintf (root, "usb:");
#endif

  /* if FAT device type changed, reload filelist */
  if (fat_type != type) 
  {
    fat_type = type;
    haveFATdir = 0;
  }

  /* update filelist */
  if (haveFATdir == 0)
  {
    useHistory = 0;
    if (type == TYPE_RECENT)
    {
      /* fetch history list */
      useHistory = 1;
      int i;
      for(i=0; i < NUM_HISTORY_ENTRIES; i++)
      {
        if(history.entries[i].filepath[0] > 0)
        {
          filelist[i].offset = 0;
          filelist[i].length = 0;
          filelist[i].flags = 0;
          strncpy(filelist[i].filename, history.entries[i].filename, MAXJOLIET-1);
          filelist[i].filename[MAXJOLIET-1] = '\0';
          max++;
        }
        else
        {
          /* Found the end of the list. */
          break;
        }
      }
    }
    else
    {
      /* reset root directory */
      sprintf (fatdir, "%s%s/roms/", root, DEFAULT_PATH);

      /* if directory doesn't exist, use root as default */
      DIR_ITER *dir = diropen(fatdir);
      if (dir == NULL) sprintf (fatdir, "%s/", root);
      else dirclose(dir);

      /* parse root directory */
      max = FAT_ParseDirectory ();
    }

    if (max > 0)
    {
      /* FAT is default */
      haveFATdir = 1;
      DVD_ClearDirectory();

      /* reset File selector */
      ClearSelector(max);
      return 1;
    }
    else
    {
      /* no entries found */
      if (max == 0) GUI_WaitPrompt("Error","No files found !");
      return 0;
    }
  }

  return 1;
}
Пример #22
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);	 
}
Пример #23
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);
	}
Пример #24
0
int main (int argc, char *argv[])
{
#ifdef HW_RVL
  /* initialize DVDX */
  DI_Init();
#endif

  /* initialize hardware */
  gx_video_Init();
  gx_input_Init();
#ifdef HW_DOL
  DVD_Init ();
  dvd_drive_detect();
#endif

  /* initialize FAT devices */
  if (fatInitDefault())
  {
    /* check for default directories */
    DIR_ITER *dir = NULL;

    /* base directory */
    char pathname[MAXPATHLEN];
    sprintf (pathname, DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);

    /* SRAM & Savestate files directory */ 
    sprintf (pathname, "%s/saves",DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);

    /* Snapshot files directory */ 
    sprintf (pathname, "%s/snaps",DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);

    /* Cheat files directory */ 
    sprintf (pathname, "%s/cheats",DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);
  }

  /* initialize sound engine */
  gx_audio_Init();

  /* initialize core engine */
  legal();
  config_default();
  history_default();
  init_machine();

  /* run any injected rom */
  if (cart.romsize)
  {
    ARAMFetch((char *)cart.rom, (void *)0x8000, cart.romsize);
    reloadrom (cart.romsize,"INJECT.bin");
    gx_video_Start();
    gx_audio_Start();
    frameticker = 1;
  }
  else
  {
    /* Main Menu */
    ConfigRequested = 1;
  }

  /* initialize GUI engine */
  GUI_Initialize();

#ifdef HW_RVL
  /* Power button callback */
  SYS_SetPowerCallback(Power_Off);
#endif

  /* main emulation loop */
  while (1)
  {
    /* Main Menu request */
    if (ConfigRequested)
    {
      /* stop video & audio */
      gx_audio_Stop();
      gx_video_Stop();

      /* show menu */
      MainMenu ();
      ConfigRequested = 0;

      /* start video & audio */
      gx_audio_Start();
      gx_video_Start();
      frameticker = 1;
    }

    if (frameticker > 1)
    {
      /* skip frame */
      system_frame(1);
      --frameticker;
    }
    else
    {
      while (frameticker < 1)
        usleep(10);

      /* render frame */
      system_frame(0);
      --frameticker;

      /* update video */
      gx_video_Update();
    }

    /* update audio */
    gx_audio_Update();
  }

  return 0;
}
Пример #25
0
int
compat_closedir( compat_dir directory )
{
  return dirclose( directory );
}
Пример #26
0
//Gets the next music file to play.  If a music file was set in the 
// config, that is used.  Otherwise, fetches a random music file.
s32 get_music_file() 
{
	struct stat st;
	char dirpath[200];
	bool useDir = true;
	DIR_ITER *dir = NULL;

	//check for config set music file or path
	if (*CFG.music_file) {
	
		//if ((strstr(CFG.music_file, ".mp3") != NULL)
		//	|| (strstr(CFG.music_file, ".mod") != NULL)) {
		if (match_ext(CFG.music_file, ".mp3")
			|| match_ext(CFG.music_file, ".mod")) {
			//load a specific file
			strcpy(music_fname, CFG.music_file);
			dbg_printf(gt("Music file: %s"), music_fname);
			dbg_printf("\n");
			if (strlen(music_fname) < 5) return 0;
			if (stat(music_fname, &st) != 0) {
				dbg_printf(gt("File not found! %s"), music_fname);
				dbg_printf("\n");
				return 0;
			}
			useDir = false;
		} else {
			
			//load a specific directory
			dir = diropen(CFG.music_file);
			if (!dir) {
				//not a valid dir so try default
				strcpy(dirpath, USBLOADER_PATH);
			} else {
				dirclose(dir);
				strcpy(dirpath, CFG.music_file);
			}
		}
	} else {
		strcpy(dirpath, USBLOADER_PATH);
	}
	
	//if a directory is being used, then get a random file to play
	if (useDir) {
		// try music.mp3 or music.mod
		get_random_file(".mp3", dirpath);
		//snprintf(music_fname, sizeof(music_fname), "%s/%s", USBLOADER_PATH, "music.mp3");
		if (stat(music_fname, &st) != 0) {
			first_time = true;
			get_random_file(".mod", dirpath);
			//snprintf(music_fname, sizeof(music_fname), "%s/%s", USBLOADER_PATH, "music.mod");
			if (stat(music_fname, &st) != 0) {
				dbg_printf(gt("music.mp3 or music.mod not found!"));
				dbg_printf("\n");
				return 0;
			}
		}
		dbg_printf(gt("Music file from dir: %s"), music_fname);
		dbg_printf("\n");
	}

	music_size = st.st_size;
	dbg_printf(gt("Music file size: %d"), music_size);
	dbg_printf("\n");
	if (music_size <= 0) return 0;

	if (match_ext(music_fname, ".mp3")) {
		music_format = FORMAT_MP3;
	} else if (match_ext(music_fname, ".mod")) {
		music_format = FORMAT_MOD;
	} else {
		music_format = 0;
		return 0;
	}

	music_open();
	if (!music_f) {
		if (*CFG.music_file || CFG.debug) {
			printf(gt("Error opening: %s"), music_fname);
			printf("\n");
		   	sleep(2);
		}
		return 0;
	}
	return 1;  //success
}
Пример #27
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;
}
Пример #28
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();
  }
 }
Пример #29
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;
}
Пример #30
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;
}