Correction Source Code

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

Moderators: cheriff, TyRaNiD

Post Reply
dark_hex
Posts: 18
Joined: Wed Dec 02, 2009 3:00 am

Correction Source Code

Post by dark_hex »

Someone can correct my source code?

Code: Select all

#include <pspkernel.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <psppower.h>
#include <pspsdk.h>

PSP_MODULE_INFO&#40;"5.50 HEX Installer",0,1,1&#41;;

#define printf			pspDebugScreenPrintf


//Sources & Destinations
#define sourcemoon		"ms0&#58;/PSP/GAME/5.50 HEX/sprx/moon.prx"
#define	destinationmoon		"flash0&#58;/kd/moon.prx"

#define sourcepops		"ms0&#58;/PSP/GAME/5.50 HEX/sprx/pops.prx"
#define	destinationpops		"flash0&#58;/kd/pops.prx"

#define sourcevshctrl		"ms0&#58;/PSP/GAME/5.50 HEX/sprx/vshctrl.prx"
#define	destinationvshctrl	"flash0&#58;/kd/vshctrl.prx"

#define sourcerecovery		"ms0&#58;/PSP/GAME/5.50 HEX/sprx/recovery.prx"
#define	destinationrecovery	"flash0&#58;/vsh/module/recovery.prx"

#define sourcesatelite		"ms0&#58;/PSP/GAME/5.50 HEX/sprx/satelite.prx"
#define	destinationsatelite	"flash0&#58;/vsh/module/satelite.prx"

#define source1327		"ms0&#58;/PSP/GAME/5.50 HEX/sprx/13-27.bmp"
#define	destination1327		"flash0&#58;/vsh/resource/13-27.bmp"


//Copy Paste flasher by Slasher

///// Globals /////
char buffer&#91;8192&#93;;


///// Functions /////

void restart&#40;&#41;
&#123;
	printf&#40;"Error...\n"&#41;;
	printf&#40;"Exiting\n"&#41;;
	sceKernelDelayThread&#40;10*1000*300&#41;;
	sceKernelExitGame&#40;&#41;;
&#125;

// Cut & Paste Function
void flash_file&#40;char *src, char *dst&#41;
&#123;
	int bytesread, totalwritten = 0;

	SceUID infd = sceIoOpen&#40;src, PSP_O_RDONLY, 0777&#41;;
	if &#40;infd < 0&#41;
	&#123;
		// !!!!!!!!!!!!!!!!!!
		//printf&#40;"Error. Please download updater again.\n"&#41;;
		// !!!!!!!!!!!!!!!!!!

		// Error
		restart&#40;&#41;;
	&#125;
	
	// Remove the destination file
    sceIoRemove&#40;dst&#41;;

	SceUID outfd = sceIoOpen&#40;dst, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
	if &#40;outfd < 0&#41;
	&#123;
		// !!!!!!!!!!!!!!!!!!
		//printf&#40;"Error. Please download updater again.\n"&#41;;
		// !!!!!!!!!!!!!!!!!!
		// Error
	&#125;

	while &#40;&#40;bytesread = sceIoRead&#40;infd, buffer, 8192&#41;&#41; > 0&#41;
	&#123;
		totalwritten += sceIoWrite&#40;outfd, buffer, bytesread&#41;;
	&#125;
	
	sceIoClose&#40;infd&#41;;
	sceIoClose&#40;outfd&#41;;

	sceIoRemove&#40;src&#41;;
&#125;

void flash&#40;&#41;
&#123;
	int uas1, as1, errorCheck = 0;
	

	uas1 = sceIoUnassign&#40;"flash0&#58;"&#41;;
    if&#40;uas1 < 0&#41;
    &#123;
		// Error
		errorCheck = 1;
    &#125; 
	else
	&#123;
        // Success
    &#125;
        
    as1  = sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", 0, IOASSIGN_RDWR, 0&#41;;
	if&#40;as1 < 0&#41;
    &#123;
		// Error
		errorCheck = 1;
    &#125;
	else
	&#123;
		// Success
    &#125;        

	// Critical moment.
	if &#40;errorCheck&#41;
	&#123;
		// Error
		restart&#40;&#41;;
	&#125;
	else
	&#123;
		// Success!
		// Flash!
		flash_file&#40; sourcemoon, destinationmoon &#41;;
		flash_file&#40; sourcepops, destinationpops &#41;;
		flash_file&#40; sourcevshctrl, destinationvshctrl &#41;;
		flash_file&#40; sourcerecovery, destinationrecovery &#41;;
		flash_file&#40; sourcesatelite, destinationsatelite &#41;;
		flash_file&#40; source1327, destination1327 &#41;;
	&#125;
	

    // Arrived here. We should have everything flashed...
&#125;

int checkFile&#40;const char *filename&#41;
&#123;
	SceUID file = sceIoOpen&#40;filename, PSP_O_RDONLY, 0&#41;;
	if &#40;file < 0&#41;
	&#123;
		sceIoClose&#40;file&#41;;
		return 0;
	&#125;
	else
	&#123;
		sceIoClose&#40;file&#41;;
		return 1;
	&#125;
&#125;

void CheckFileInPlace&#40;&#41;
&#123;
	int errorCheck = 0;

	if &#40;!checkFile&#40;source1327&#41;&#41;
	&#123;
		errorCheck = 1;
	&#125;
	
	if &#40;errorCheck&#41;
	&#123;
		printf&#40;"Please download the updater again.\n"
			   "Some files are corrupted."
			         "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;
void CheckFileInPlace&#40;&#41;
&#123;
	int errorCheck = 0;

	if &#40;!checkFile&#40;sourcemoon&#41;&#41;
	&#123;
		errorCheck = 1;
	&#125;
	
	if &#40;errorCheck&#41;
	&#123;
		printf&#40;"Please download the updater again.\n"
			   "Some files are corrupted."
			         "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;
void CheckFileInPlace&#40;&#41;
&#123;
	int errorCheck = 0;

	if &#40;!checkFile&#40;sourcepops&#41;&#41;
	&#123;
		errorCheck = 1;
	&#125;
	
	if &#40;errorCheck&#41;
	&#123;
		printf&#40;"Please download the updater again.\n"
			   "Some files are corrupted."
			         "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;
void CheckFileInPlace&#40;&#41;
&#123;
	int errorCheck = 0;

	if &#40;!checkFile&#40;sourcevshctrl&#41;&#41;
	&#123;
		errorCheck = 1;
	&#125;
	
	if &#40;errorCheck&#41;
	&#123;
		printf&#40;"Please download the updater again.\n"
			   "Some files are corrupted."
			         "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;
void CheckFileInPlace&#40;&#41;
&#123;
	int errorCheck = 0;

	if &#40;!checkFile&#40;sourcerecovery&#41;&#41;
	&#123;
		errorCheck = 1;
	&#125;
	
	if &#40;errorCheck&#41;
	&#123;
		printf&#40;"Please download the updater again.\n"
			   "Some files are corrupted."
			         "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;
void CheckFileInPlace&#40;&#41;
&#123;
	int errorCheck = 0;

	if &#40;!checkFile&#40;sourcesatelite&#41;&#41;
	&#123;
		errorCheck = 1;
	&#125;
	
	if &#40;errorCheck&#41;
	&#123;
		printf&#40;"Please download the updater again.\n"
			   "Some files are corrupted."
			         "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;

void CheckPowerOnline&#40;&#41;
&#123;
	if &#40;!scePowerIsPowerOnline&#40;&#41;&#41;
	&#123;
		printf&#40;"The AC adaptor is not connected.\n"
			   "Connect the AC adaptor and restart the updater.\n"
			   "Auto-exiting program in 5 seconds.\n"&#41;;

		sceKernelDelayThread&#40;10*1000*500&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
&#125;

///// Main /////
int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	
	CheckFileInPlace&#40;&#41;;
	CheckPowerOnline&#40;&#41;;
	
	printf&#40;"Updating...\n"&#41;;
	sceKernelDelayThread&#40;10*1000*300&#41;;

	flash&#40;&#41;;

	printf&#40;"Success!\n"&#41;;
	sceKernelDelayThread&#40;10*1000*300&#41;;

	printf&#40;"Exiting in 5 seconds...\n"&#41;;
	sceKernelDelayThread&#40;5*1000*1000&#41;;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

Draan
Posts: 48
Joined: Sat Oct 17, 2009 3:39 am

Post by Draan »

I see CheckFileInPlace() implementatnion four times. Leave one.

And post your error.
dark_hex
Posts: 18
Joined: Wed Dec 02, 2009 3:00 am

Post by dark_hex »

The files are not copied
Criptych
Posts: 64
Joined: Sat Sep 12, 2009 5:18 am

Post by Criptych »

It shouldn't even compile. As Draan said, CheckFileInPlace() occurs four times, each time with the same signature. Give each function a unique name (e.g. CheckXFileInPlace, CheckYFileInPlace...) or at least a unique signature (and compile as C++). Better yet, since each one basically does the same thing with different values, make it one function that takes a parameter.
"You hungry? I haven't eaten since later this afternoon."
Post Reply