forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Correction Source Code

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
dark_hex



Joined: 02 Dec 2009
Posts: 18

PostPosted: Sat Dec 05, 2009 6:17 am    Post subject: Correction Source Code Reply with quote

Someone can correct my source code?

Code:
#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("5.50 HEX Installer",0,1,1);

#define printf         pspDebugScreenPrintf


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

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

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

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

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

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


//Copy Paste flasher by Slasher

///// Globals /////
char buffer[8192];


///// Functions /////

void restart()
{
   printf("Error...\n");
   printf("Exiting\n");
   sceKernelDelayThread(10*1000*300);
   sceKernelExitGame();
}

// Cut & Paste Function
void flash_file(char *src, char *dst)
{
   int bytesread, totalwritten = 0;

   SceUID infd = sceIoOpen(src, PSP_O_RDONLY, 0777);
   if (infd < 0)
   {
      // !!!!!!!!!!!!!!!!!!
      //printf("Error. Please download updater again.\n");
      // !!!!!!!!!!!!!!!!!!

      // Error
      restart();
   }
   
   // Remove the destination file
    sceIoRemove(dst);

   SceUID outfd = sceIoOpen(dst, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
   if (outfd < 0)
   {
      // !!!!!!!!!!!!!!!!!!
      //printf("Error. Please download updater again.\n");
      // !!!!!!!!!!!!!!!!!!
      // Error
   }

   while ((bytesread = sceIoRead(infd, buffer, 8192)) > 0)
   {
      totalwritten += sceIoWrite(outfd, buffer, bytesread);
   }
   
   sceIoClose(infd);
   sceIoClose(outfd);

   sceIoRemove(src);
}

void flash()
{
   int uas1, as1, errorCheck = 0;
   

   uas1 = sceIoUnassign("flash0:");
    if(uas1 < 0)
    {
      // Error
      errorCheck = 1;
    }
   else
   {
        // Success
    }
       
    as1  = sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", 0, IOASSIGN_RDWR, 0);
   if(as1 < 0)
    {
      // Error
      errorCheck = 1;
    }
   else
   {
      // Success
    }       

   // Critical moment.
   if (errorCheck)
   {
      // Error
      restart();
   }
   else
   {
      // Success!
      // Flash!
      flash_file( sourcemoon, destinationmoon );
      flash_file( sourcepops, destinationpops );
      flash_file( sourcevshctrl, destinationvshctrl );
      flash_file( sourcerecovery, destinationrecovery );
      flash_file( sourcesatelite, destinationsatelite );
      flash_file( source1327, destination1327 );
   }
   

    // Arrived here. We should have everything flashed...
}

int checkFile(const char *filename)
{
   SceUID file = sceIoOpen(filename, PSP_O_RDONLY, 0);
   if (file < 0)
   {
      sceIoClose(file);
      return 0;
   }
   else
   {
      sceIoClose(file);
      return 1;
   }
}

void CheckFileInPlace()
{
   int errorCheck = 0;

   if (!checkFile(source1327))
   {
      errorCheck = 1;
   }
   
   if (errorCheck)
   {
      printf("Please download the updater again.\n"
            "Some files are corrupted."
                  "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}
void CheckFileInPlace()
{
   int errorCheck = 0;

   if (!checkFile(sourcemoon))
   {
      errorCheck = 1;
   }
   
   if (errorCheck)
   {
      printf("Please download the updater again.\n"
            "Some files are corrupted."
                  "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}
void CheckFileInPlace()
{
   int errorCheck = 0;

   if (!checkFile(sourcepops))
   {
      errorCheck = 1;
   }
   
   if (errorCheck)
   {
      printf("Please download the updater again.\n"
            "Some files are corrupted."
                  "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}
void CheckFileInPlace()
{
   int errorCheck = 0;

   if (!checkFile(sourcevshctrl))
   {
      errorCheck = 1;
   }
   
   if (errorCheck)
   {
      printf("Please download the updater again.\n"
            "Some files are corrupted."
                  "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}
void CheckFileInPlace()
{
   int errorCheck = 0;

   if (!checkFile(sourcerecovery))
   {
      errorCheck = 1;
   }
   
   if (errorCheck)
   {
      printf("Please download the updater again.\n"
            "Some files are corrupted."
                  "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}
void CheckFileInPlace()
{
   int errorCheck = 0;

   if (!checkFile(sourcesatelite))
   {
      errorCheck = 1;
   }
   
   if (errorCheck)
   {
      printf("Please download the updater again.\n"
            "Some files are corrupted."
                  "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}

void CheckPowerOnline()
{
   if (!scePowerIsPowerOnline())
   {
      printf("The AC adaptor is not connected.\n"
            "Connect the AC adaptor and restart the updater.\n"
            "Auto-exiting program in 5 seconds.\n");

      sceKernelDelayThread(10*1000*500);
      sceKernelExitGame();
   }
}

///// Main /////
int main(int argc, char* argv[])
{
   pspDebugScreenInit();
   
   CheckFileInPlace();
   CheckPowerOnline();
   
   printf("Updating...\n");
   sceKernelDelayThread(10*1000*300);

   flash();

   printf("Success!\n");
   sceKernelDelayThread(10*1000*300);

   printf("Exiting in 5 seconds...\n");
   sceKernelDelayThread(5*1000*1000);
   sceKernelExitGame();

   return 0;
}

Back to top
View user's profile Send private message Send e-mail
Draan



Joined: 17 Oct 2009
Posts: 55

PostPosted: Sat Dec 05, 2009 7:07 am    Post subject: Reply with quote

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

And post your error.
Back to top
View user's profile Send private message
dark_hex



Joined: 02 Dec 2009
Posts: 18

PostPosted: Sat Dec 05, 2009 7:10 am    Post subject: Reply with quote

The files are not copied
Back to top
View user's profile Send private message Send e-mail
Criptych



Joined: 12 Sep 2009
Posts: 79

PostPosted: Sat Dec 05, 2009 9:58 am    Post subject: Reply with quote

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.
_________________
PSP-2000 // CFW: 5.50 GEN-D2 ...and not upgrading until OFW supports homebrew!
(But I did downgrade to 1.50 with TimeMachine...)
"I want you to tell me how the machine makes you feel."
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group