CODE
#include
int file_handle;
strcpy(path,"d:\\mydata.dat"); //"d:\\" is an alias for "./"
//reading size of file
ret=XCreateFile(&file_handle,path,
GENERIC_READ,FILE_SHARE_READ,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL);
if (ret!=0)
{
debugPrint("File not found\n"); return -1;
}
XGetFileSize(file_handle,(int *)&data_len);
XCloseHandle(file_handle);
//reading from file
ret=XCreateFile(&file_handle,path,
GENERIC_READ,FILE_SHARE_READ,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL);
if (ret!=0)
{
debugPrint("File not found\n"); return -1;
}
if (!XReadFile(file_handle,data_buf,max_buf_size,(int *)&actuallyread))
{
debugPrint("read error\n"); return -2;
}
XCloseHandle(file_handle);
//writing to file
ret=XCreateFile(&file_handle,path,
GENERIC_WRITE,FILE_SHARE_WRITE,
CREATE_NEW,FILE_ATTRIBUTE_NORMAL);
if (ret!=0)
{
debugPrint("Can't create file\n"); return -1;
}
if (!XWriteFile(file_handle,data_buf,data_size,(int *)&actuallywritten))
{
debugPrint("write error\n"); return -3;
}
XCloseHandle(file_handle);
Note that it's the same mess with ps2dev, mainly because you access memory cards, usb keyboard, etc...
Can't really use standard file i/o with open dev kits...
CODE
if (ret!=0)
{
debugPrint("...\n"); return -1;
}
you SHOULDN'T write this (like you did):
CODE
if (ret!=0) debutPrint("...\n"); return -1;
Because "return -1" now executes systematically and is no longer conditionned by the if.
Try this code by just copying/pasting it (don't change a single character) :
(have blah.txt copied in same directory as the .xbe binary you launch, too)
CODE
#include
#include
#include
//#include "comingSoon.h"
#include
#include
#include
#include
#include
#include
char path[256];
int filesizex(char *fn)
{
int f;
int data_len,ret;
//reading size of file
strcpy(path,fn);
ret=XCreateFile(&f,path,
GENERIC_READ,FILE_SHARE_READ,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL);
if (ret!=0)
{
debugPrint("File not found\n");
return -1;
}
XGetFileSize(f,(int *)&data_len);
XCloseHandle(f);
return data_len;
}
void XBoxStartup()
{
FILE *fp;
int read, written, newLocation;
char buffer[20];
int handle,ret;
int actuallyread,filelength;
int id;
unsigned char id1,id2,id3,id4;
char buf2[4];
int *frame_buffer = (int*)XVideoGetFB();
XKEYBOARD_STROKE xk;
int i;
int running = 1;
debugPrint("Initialising...");
XInput_Init();
filelength=filesizex("d:\\blah.txt");
debugPrint("filesize: %d\n",filelength);
//reading from file
strcpy(path,"d:\\blah.txt");
ret=XCreateFile(&handle,path,
GENERIC_READ,FILE_SHARE_READ,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL);
if (ret!=0) debugPrint("File not found\n"); //return -1;
if (!XReadFile(handle,buffer,filelength,(int *)&actuallyread))
{
debugPrint("read error\n"); //return -2;
}
XCloseHandle(handle);
debugPrint("- display buffer:\n");
for (i=0;i);
debugPrint("\n");
//XSleep(10000); //let's use joypad please
debugPrint("Press A\n");
while(1)
{
XInput_GetEvents();
if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_A]) break;
}
XInput_Quit();
//XLaunchXBE("c:\\evoxdash.xbe"); //useless, reboot will launch dashboard anyway
XReboot();
}