Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Improved handling of message dialogs

- Removed unnecessary code
- Added / Improved error handling code
- Misc Cleanup and code improvements
  • Loading branch information...
commit b35930c98f01ed3ef022688441905ae790acf31e 1 parent c17aec0
@CaptainCPS authored
View
3  include/gamePKG.h
@@ -61,7 +61,8 @@ class c_gamePKG
int QueuePKG();
int CreatePDBFiles();
- int DeletePDBFiles();
+ int DeletePDBFiles(int nId);
+ int RemovePKGDir(int nId);
void RefreshPKGList();
uint64_t GetPKGSize(char* szFilePath);
int ParsePKGList(const char* szDevice);
View
BIN  msvc/gamePKG/gamePKG.suo
Binary file not shown
View
BIN  release/PS3_GAME/USRDIR/EBOOT.BIN
Binary file not shown
View
180 src/gamePKG.cpp
@@ -179,7 +179,7 @@ int c_gamePKG::ParsePKGList(const char* szDevice)
msg = "CELL_FS_EFAULT";
break;
}
- //::cellMsgDialogOpen(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, msg, callbackfunction, NULL, NULL);
+ //::cellMsgDialogOpen2(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, msg, callbackfunction, NULL, NULL);
return 0;
}
@@ -220,47 +220,52 @@ void c_gamePKG::RefreshPKGList()
ParsePKGList("/dev_hdd0/package");
}
-//int c_gamePKG::DeletePDBFiles()
-//{
-// bDeleting = true;
-//
-// // PKG
-// int nFNLen = strlen(pkglst[nSelectedPKG]->title) + 1; // filename length
-//
-// char* pszFN = NULL;
-// pszFN = (char*)malloc(sizeof(char) * nFNLen);
-// memcpy(pszFN, pkglst[nSelectedPKG]->title, nFNLen);
-//
-// char szPKGDir[256] = "";
-// sprintf(szPKGDir, "/dev_hdd0/vsh/game_pkg/%d", pkglst[nSelectedPKG]->nPKGID);
-//
-// // delete files
-// char szFile[4][256];
-//
-// char szPDB[4][256] = {
-// "d0.pdb",
-// "d1.pdb",
-// "f0.pdb",
-// "ICON_FILE"
-// };
-//
-// for(int x = 0; x < 4; x++)
-// {
-// sprintf(szFile[x], "%s/%s", szPKGDir, szPDB[x]);
-// FILE* fp = fopen(szFile[x], "r");
-// if(fp){
-// fclose(fp);
-// fp = NULL;
-// cellFsUnlink(szFile[x]);
-// }
-// }
-//
-// pkglst[nSelectedPKG]->bQueued = false;
-//
-// bDeleting = false;
-//
-// return 1;
-//}
+int c_gamePKG::RemovePKGDir(int nId)
+{
+ char szPKGDir[256] = "";
+ sprintf(szPKGDir, "/dev_hdd0/vsh/game_pkg/%d", nId);
+
+ CellFsErrno ret = cellFsRmdir(szPKGDir);
+
+ if(ret != CELL_FS_SUCCEEDED) {
+ // couldn't delete the directory...
+ return 0;
+ }
+ return 1;
+}
+
+int c_gamePKG::DeletePDBFiles(int nId)
+{
+ bDeleting = true;
+
+ char szPKGDir[256] = "";
+ sprintf(szPKGDir, "/dev_hdd0/vsh/game_pkg/%d", nId);
+
+ // delete files
+ char szFile[4][256] = {"","","",""};
+ char szPDB[4][256] = {"d0.pdb","d1.pdb","f0.pdb","ICON_FILE"};
+
+ for(int x = 0; x < 4; x++)
+ {
+ sprintf(szFile[x], "%s/%s", szPKGDir, szPDB[x]);
+
+ FILE* fp = fopen(szFile[x], "r");
+
+ if(fp){
+ fclose(fp);
+ fp = NULL;
+ CellFsErrno ret = cellFsUnlink(szFile[x]);
+ if(ret != CELL_FS_SUCCEEDED)
+ {
+ // error deleting file
+ return 0;
+ }
+ }
+ }
+
+ bDeleting = false;
+ return 1;
+}
uint64_t c_gamePKG::GetPKGSize(char* szFilePath)
{
@@ -325,18 +330,14 @@ int c_gamePKG::CreatePDBFiles()
bytes_from_hex_string(sizeData, pkglst[nSelectedPKG]->szSize);
// PKG size 1st entry
- d0pdb_ttxt_hdr[0x70] = sizeData[0];
- d0pdb_ttxt_hdr[0x71] = sizeData[1];
- d0pdb_ttxt_hdr[0x72] = sizeData[2];
- d0pdb_ttxt_hdr[0x73] = sizeData[3];
- d0pdb_ttxt_hdr[0x74] = sizeData[4];
+ for(int x = 0; x < 5; x++) {
+ d0pdb_ttxt_hdr[0x70 + x] = sizeData[x];
+ }
// PKG size 2nd entry
- d0pdb_ttxt_hdr[0x84] = sizeData[0];
- d0pdb_ttxt_hdr[0x85] = sizeData[1];
- d0pdb_ttxt_hdr[0x86] = sizeData[2];
- d0pdb_ttxt_hdr[0x87] = sizeData[3];
- d0pdb_ttxt_hdr[0x88] = sizeData[4];
+ for(int x = 0; x < 5; x++) {
+ d0pdb_ttxt_hdr[0x84 + x] = sizeData[x];
+ }
// TITLE string length entry
d0pdb_ttxt_hdr[0x94] = nFNLen + 0x0D + 1;
@@ -459,13 +460,6 @@ void thread_FileCopy(uint64_t arg)
{
gamePKG->nCopyStatus = 1;
- int running = 0;
- sys_ppu_thread_t id;
- sys_ppu_thread_get_id(&id);
-
- sys_ppu_thread_stack_t stackinfo;
- sys_ppu_thread_get_stack_information(&stackinfo);
-
FILE *filer, *filew;
int numr, numw;
char buffer[2352]; // 1 sector as in CD-ROM
@@ -475,56 +469,46 @@ void thread_FileCopy(uint64_t arg)
if(filer != NULL && filew != NULL)
{
+ bool bCopyError = false;
+
while(feof(filer) == 0)
{
- if(gamePKG->bCancelCopy)
- {
- //fclose(filer);
- //fclose(filew);
- //cellFsUnlink(szFileOut); // delete file
- //DeletePDBFiles();
- //while(bDeleting)
- //{
- // // ...wait
- //}
- //bCancelCopy = false;
- //nCopyStatus = 10;
- //sys_ppu_thread_exit(0);
- //break;
- }
-
- sys_ppu_thread_yield();
- running++;
+ //if(gamePKG->bCancelCopy)
+ //{
+ //...
+ //}
if((numr = fread(buffer, 1, 2352, filer)) != 2352) {
if(ferror(filer) != 0)
{
- fclose(filer);
- fclose(filew);
- cellFsUnlink(gamePKG->szFileOut); // delete file
+ bCopyError = true;
break;
}
else if(feof(filer) != 0);
}
if((numw = fwrite(buffer, 1, numr, filew)) != numr)
{
- fclose(filer);
- fclose(filew);
- cellFsUnlink(gamePKG->szFileOut); // delete file
+ bCopyError = true;
break;
}
}
- fclose(filer);
- fclose(filew);
+
+ if(filer) fclose(filer);
+ if(filew) fclose(filew);
- gamePKG->nCopyStatus = 2;
+ if(bCopyError)
+ {
+ cellFsUnlink(gamePKG->szFileOut); // delete file
+ gamePKG->nCopyStatus = 10;
+ }
} else {
-
- // TODO: Add cleanup here
- // delete created files and directory
+ if(filer) fclose(filer);
+ if(filew) {
+ fclose(filew);
+ cellFsUnlink(gamePKG->szFileOut); // delete file
+ }
gamePKG->nCopyStatus = 10;
-
sys_ppu_thread_exit(0);
}
@@ -537,15 +521,27 @@ int c_gamePKG::QueuePKG()
char szPKGDir[256] = "";
sprintf(szPKGDir, "/dev_hdd0/vsh/game_pkg/%d", pkglst[nSelectedPKG]->nPKGID);
- cellFsMkdir(szPKGDir, CELL_FS_DEFAULT_CREATE_MODE_1); // perms 700
+ CellFsErrno ret = cellFsMkdir(szPKGDir, CELL_FS_DEFAULT_CREATE_MODE_1); // perms 700
+
+ if(ret != CELL_FS_SUCCEEDED)
+ {
+ ::cellMsgDialogOpen2(
+ CELL_MSGDIALOG_DIALOG_TYPE_NORMAL,
+ "[Error] Could not create the required directory on HDD.",
+ callbackfunction, NULL, NULL
+ );
+ pkglst[nSelectedPKG]->bQueued = false;
+ return 0;
+ }
if(!CreatePDBFiles())
{
- ::cellMsgDialogOpen(
+ ::cellMsgDialogOpen2(
CELL_MSGDIALOG_DIALOG_TYPE_NORMAL,
"[Error] Could not create / write needed files to HDD.",
callbackfunction, NULL, NULL
);
+ pkglst[nSelectedPKG]->bQueued = false;
return 0;
}
View
59 src/main.cpp
@@ -85,7 +85,7 @@ void CapApp::dbgFontInit(void)
if (ret != CELL_OK)
{
- cellMsgDialogOpen(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "cellDbgFontInit() failed", callbackfunction, NULL, NULL);
+ cellMsgDialogOpen2(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "cellDbgFontInit() failed", callbackfunction, NULL, NULL);
return;
}
@@ -105,7 +105,7 @@ void CapApp::dbgFontInit(void)
if (mDbgFontID[0] < 0)
{
- cellMsgDialogOpen(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "cellDbgFontConsoleOpen() failed", callbackfunction, NULL, NULL);
+ cellMsgDialogOpen2(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "cellDbgFontConsoleOpen() failed", callbackfunction, NULL, NULL);
return;
}
@@ -120,7 +120,7 @@ void CapApp::dbgFontInit(void)
if (mDbgFontID[1] < 0)
{
- cellMsgDialogOpen(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "cellDbgFontConsoleOpen() failed", callbackfunction, NULL, NULL);
+ cellMsgDialogOpen2(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "cellDbgFontConsoleOpen() failed", callbackfunction, NULL, NULL);
return;
}
}
@@ -321,9 +321,8 @@ void CapApp::Input()
if(gamePKG->pkglst[gamePKG->nSelectedPKG]->bQueued)
{
// already queued...
- ::cellMsgDialogOpen(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "Sorry, you already queued this PKG.", callbackfunction, NULL, NULL);
+ ::cellMsgDialogOpen2(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, "Sorry, you already queued this PKG.", callbackfunction, NULL, NULL);
} else {
- gamePKG->pkglst[gamePKG->nSelectedPKG]->bQueued = true;
gamePKG->QueuePKG();
}
}
@@ -339,23 +338,8 @@ bool CapApp::onUpdate()
mFrame++;
Input();
-
dbgFontPut();
- // COPY SUCCESS
- if(gamePKG->nCopyStatus == 3)
- {
- char szMsg[256] = "";
- sprintf(szMsg, "Successfully added \"%s\" to queue.", gamePKG->szFileIn);
-
- ::cellMsgDialogOpen2(
- CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_ON,
- szMsg,
- callbackfunction, NULL, NULL);
-
- gamePKG->nCopyStatus = 0;
- }
-
// COPY STARTED
if(gamePKG->nCopyStatus == 1)
{
@@ -373,38 +357,40 @@ bool CapApp::onUpdate()
gamePKG->nCopyStatus = 0; // avoid loop
}
- // COPY DONE [OK]
+ // COPY [OK]
if(gamePKG->nCopyStatus == 2)
{
- cellMsgDialogClose(500.0f);
-
- sys_timer_sleep(1);
-
- gamePKG->nCopyStatus = 3;
- }
+ cellMsgDialogAbort();
- // COPY ERROR MSG
- if(gamePKG->nCopyStatus == 11)
- {
char szMsg[256] = "";
- sprintf(szMsg, "Error while processing \"%s\".", gamePKG->szFileIn);
+ sprintf(szMsg, "Successfully added \"%s\" to queue.", gamePKG->szFileIn);
::cellMsgDialogOpen2(
- CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_OFF,
+ CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_ON,
szMsg,
callbackfunction, NULL, NULL);
+ gamePKG->pkglst[gamePKG->nSelectedPKG]->bQueued = true;
gamePKG->nCopyStatus = 0;
}
- // COPY DONE [ERROR]
+ // COPY [ERROR]
if(gamePKG->nCopyStatus == 10)
{
- cellMsgDialogClose(500.0f);
+ cellMsgDialogAbort();
- sys_timer_sleep(1);
+ char szMsg[256] = "";
+ sprintf(szMsg, "Error while processing \"%s\".", gamePKG->szFileIn);
- gamePKG->nCopyStatus = 11;
+ ::cellMsgDialogOpen2(
+ CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_OFF,
+ szMsg,
+ callbackfunction, NULL, NULL);
+
+ gamePKG->pkglst[gamePKG->nSelectedPKG]->bQueued = false;
+ gamePKG->DeletePDBFiles(gamePKG->pkglst[gamePKG->nSelectedPKG]->nPKGID);
+ gamePKG->RemovePKGDir(gamePKG->pkglst[gamePKG->nSelectedPKG]->nPKGID);
+ gamePKG->nCopyStatus = 0;
}
return FWGLApplication::onUpdate();
@@ -416,7 +402,6 @@ void CapApp::onRender()
FWGLApplication::onRender();
dbgFontDraw();
-
}
void CapApp::onShutdown()
Please sign in to comment.
Something went wrong with that request. Please try again.