Hi there,
Recently wanted to dig myself into filedialogs ... It works perfectly well if I just Output informations gathered by GpDirEnumList as long as the memory alloc'd for GPDIRENTRY in the same function is used ... I get random output if I use the following:
Any help appreciated
Recently wanted to dig myself into filedialogs ... It works perfectly well if I just Output informations gathered by GpDirEnumList as long as the memory alloc'd for GPDIRENTRY in the same function is used ... I get random output if I use the following:
Code:
#include "defines.h"
#include <stdlib.h>
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpstdio.h"
#include "gpfont.h"
#include "gpstdio.h"
/* Converts 8bit rgb values to a GP32 palette value */
#define GP_RGB24(r,g,b) (((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|((((b>>3))&0x1f)<<1))
/* Global variables */
GPDRAWSURFACE gpDraw[2];
struct PathInfo
{
char name[16];
bool directory;
};
short PrintFileInfo (char*, PathInfo*);
/* Sets a single GP32 palette entry */
void GpSetPaletteEntry ( u8 i, u8 r, u8 g, u8 b )
{
GP_PALETTEENTRY entry = GP_RGB24(r,g,b);
GpPaletteEntryChange ( i, 1, &entry, 0 );
}
void GpMain (void * arg)
{
int * t;
GpFatInit();
/* Initialize graphics */
GpGraphicModeSet(8, t);
GpLcdSurfaceGet(&gpDraw[0], 0);
GpLcdSurfaceGet(&gpDraw[1], 1);
GpSurfaceSet(&gpDraw[0]);
GpLcdEnable();
GpSurfaceFlip(&gpDraw[0]);
GpSetPaletteEntry ( 0, 0,0,0 );
GpSetPaletteEntry ( 1, 255,0,0 );
GpSetPaletteEntry ( 2, 255,255,255 );
PathInfo* info;
short count = PrintFileInfo ("gp:\\game", info);
for (int i = 0; i < (int) count; i++)
{
GpTextOut (NULL, &gpDraw[0], 20, i * 10, info[i].name, 0);
}
}
short PrintFileInfo (char* path, PathInfo* info)
{
GpRelativePathSet(path);
ERR_CODE error;
ulong list_count = 0;
error = GpDirEnumNum ("\\", &list_count);
if (error != SM_OK)
{
return -1;
}
if (!list_count)
{
return -2;
}
GPDIRENTRY* filenames = new GPDIRENTRY[(int) list_count];
ulong count;
GpDirEnumList ("\\", 0, list_count, filenames, &count);
GPFILEATTR attr;
info = new PathInfo[(int) count];
for (int i = 0; i < (int) count; i++)
{
error = GpFileAttr (filenames[i].name, &attr);
info[i].directory = false;
if (error == SM_OK && (attr.attr & 0x10) != 0)
{
info[i].directory = true;
}
gm_strcpy (info[i].name, filenames[i].name);
}
return (short) count;
}
Any help appreciated