Write to file?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Write to file?

Post by Art »

Code: Select all

void read_to_ram() {
	int fd;
	int cpa = 8; //defines the position of characters of interest
	int cpb = 9; //
	int cpc = 10; //
	int cpd = 11; //

	fd = sceIoOpen("flash0:/vsh/etc/version.txt", PSP_O_RDONLY, 0777);
	sceIoRead(fd,data,256);
	sceIoClose(fd);

	printf(" PSP Unit Firmware Version Check: ");
	printf("version ");
	printf("%c",data[cpa]);
	printf("%c",data[cpb]);
	printf("%c",data[cpc]);
	printf("%c",data[cpd]);
	printf("\n");

	int fdo;
	fdo = sceIoOpen("ms0:/debug.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
	sceIoWrite(fd,"ms0:/version.txt", 256);
	sceIoClose(fdo);
}
Hello,
I'm trying to write this file back from RAM to memory stick.
THe file reads to RAM ok, and the version number is printed to screen,
but the file that gets written to ms is a small section of my program's source code.
Cheers, Art.
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

sceIoWrite(fd,"ms0:/version.txt", 256);

is trying to write 256 letters of the string "ms0:/version.txt", to the file pointed to by fd, ie flash0:/vsh/etc/version.txt. Maybe it's lucky that you opened it read only then?? :)

if you just want to copy it ts ms:/xxxx then:
sceIoWrite(fdo,data, 256);

might do the trick.
Damn, I need a decent signature!
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Thanx, that worked if I change the 256 to the actual length of the file.
I can see how that is made variable by sample software.
Gary13579
Posts: 93
Joined: Mon Aug 15, 2005 7:43 am

Re: Write to file?

Post by Gary13579 »

Art wrote:

Code: Select all

void read_to_ram() {
	int fd;
	int cpa = 8; //defines the position of characters of interest
	int cpb = 9; //
	int cpc = 10; //
	int cpd = 11; //

	fd = sceIoOpen("flash0:/vsh/etc/version.txt", PSP_O_RDONLY, 0777);
	sceIoRead(fd,data,256);
	sceIoClose(fd);

	printf(" PSP Unit Firmware Version Check: ");
	printf("version ");
	printf("%c",data[cpa]);
	printf("%c",data[cpb]);
	printf("%c",data[cpc]);
	printf("%c",data[cpd]);
	printf("\n");

	int fdo;
	fdo = sceIoOpen("ms0:/debug.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
	sceIoWrite(fd,"ms0:/version.txt", 256);
	sceIoClose(fdo);
}
Umm.. why are you using version.txt? I haven't looked at the file much, but I believe the version number is stored in the index.dat file. Also, when writing to the file ms0:/debug.txt, you may want to try this
sceIoWrite(fdo, string, strlen(string));
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

The real version number is there even when PSPset or any other program
has tricked the version.
My program makes sure it is running on 1.50 or it quits.
Post Reply