Skip to content
Browse files

- Implemented PKG list sorting by filename.

- Directory scanning will use upper-case name as top priority (Ex. /dev_*/PKG)
- Other code improvements / changes
  • Loading branch information...
1 parent bd6647c commit eadd1d1ac0a177d1ddcc2e3d2f901b3015d8a511 @CaptainCPS committed Jan 9, 2013
Showing with 213 additions and 232 deletions.
  1. +40 −31 README.md
  2. +5 −18 include/gamePKG.h
  3. +3 −0 include/main.h
  4. +4 −1 include/misc.h
  5. BIN msvc/gamePKG/gamePKG.suo
  6. BIN release/PS3_GAME/USRDIR/EBOOT.BIN
  7. +87 −125 src/gamePKG.cpp
  8. +74 −57 src/misc.cpp
View
71 README.md
@@ -1,4 +1,4 @@
-gamePKG [by CaptainCPS-X, 2012]
+gamePKG [by CaptainCPS-X, 2012-2013]
----------------------------------------------
Information:
@@ -20,34 +20,42 @@ Tested on: Rogero CFW 4.30 (v2.03) @ 1080p resolution [HDMI]
Should work on 3.40+ CFW
The application will scan the following directories
-for PKG files:
-
-- /dev_hdd0/pkg/
-- /dev_hdd0/package/
-- /dev_usb000/
-- /dev_usb000/pkg/
-- /dev_usb000/package/
-- /dev_usb001/
-- /dev_usb001/pkg/
-- /dev_usb001/package/
-- /dev_usb002/
-- /dev_usb002/pkg/
-- /dev_usb002/package/
-- /dev_usb003/
-- /dev_usb003/pkg/
-- /dev_usb003/package/
-- /dev_cf/
-- /dev_cf/pkg
-- /dev_cf/package
-- /dev_cf/packages
-- /dev_sd/
-- /dev_sd/pkg
-- /dev_sd/package
-- /dev_sd/packages
-- /dev_ms/
-- /dev_ms/pkg
-- /dev_ms/package
-- /dev_ms/packages
+for files with .PKG/.pkg extension :
+
+- /dev_*/
+- /dev_*/PKG
+- /dev_*/PACKAGE
+- /dev_*/PACKAGES
+
+Devices scanned are:
+
+- dev_hdd0 (PS3 Internal HDD)
+- dev_usb000 (External USB)
+- dev_usb001 (External USB)
+- dev_usb002 (External USB)
+- dev_usb003 (External USB)
+- dev_cf (Compact Flash)
+- dev_sd (SD Card)
+- dev_ms (Memory Stick)
+
+PKG SCAN NOTE:
+
+The PS3 system does not have case-sensitive directory
+name restrictions or duplication restrictions as Windows OS,
+so if for some reason you have duplicate directories as
+for example:
+
+- /dev_*/PKG/
+- /dev_*/pkg/
+- /dev_*/Pkg/
+
+The PS3 system will scan the upper-case contents only
+as top priority. So, it is recommended not to have
+duplicate directories.
+
+I tried to modify the code the most I could, but its just
+something that is not implemented in the standard
+C libraries.
NOTES:
-----------------------------------------------
@@ -71,8 +79,9 @@ Usage:
Changelog:
----------------------------------------------
-1.1
+1.1 (20130109)
+- Implemented PKG list sorting by filename.
- Added feature to remove previously queued PKG by pressing ([ ]) square.
- Added scan of PKG files on root of USB devices as well (from "/dev_usb000/" to "/dev_usb003/")
- Added scan of PKG files on "/dev_cf/..." (compact flash), "/dev_sd/..." (sd card), "/dev_ms/..." (memory stick)
@@ -81,7 +90,7 @@ Changelog:
- Re-wrote module to write the PDB & Icon files from scratch.
- Other source code improvements.
-1.0
+1.0 (20121220)
- Initial "Test" Release
View
23 include/gamePKG.h
@@ -1,26 +1,14 @@
// ---------------------------------------------------------------------
// CaptainCPS-X's gamePKG Tool
// ---------------------------------------------------------------------
-class c_pkglist
+struct c_pkglist
{
-public:
-
- char path[1024]; // full pkg path
- char title[64]; // pkg filename
+ char path[256]; // full pkg path
+ char title[256]; // pkg filename
bool bInternal; // HDD / USB PKG
bool bQueued; // Queued status
uint64_t nSize; // size in bytes
- int nPKGID;
-
- c_pkglist()
- {
- bInternal = false;
- bQueued = false;
- nSize = 0;
- nPKGID = 0;
- }
-
- ~c_pkglist() { }
+ int nPKGID; // Ex. 80000000
};
#define STATUS_NORMAL 0
@@ -30,7 +18,6 @@ class c_pkglist
#define STATUS_RM_QUEUE_START 4
#define STATUS_RM_QUEUE_OK 5
-
class c_gamePKG
{
public:
@@ -45,7 +32,7 @@ class c_gamePKG
int nStatus;
- c_pkglist* pkglst[9000];
+ c_pkglist *pkglst;
int QueuePKG();
void RemoveFromQueue();
View
3 include/main.h
@@ -11,11 +11,14 @@
#include <sys/ppu_thread.h>
#include <stdio.h>
#include <stdlib.h>
+#include <ctype.h>
#include <math.h>
#include <sysutil/sysutil_msgdialog.h>
#include <cell/sysmodule.h>
#include <sys/memory.h>
+#include <dirent.h>
+
#include "psgl/FWGLApplication.h"
#include "psgl/FWGLGrid.h"
#include "FWInput.h"
View
5 include/misc.h
@@ -2,7 +2,10 @@
// CaptainCPS-X's gamePKG Tool
// ---------------------------------------------------------------------
+int _FcCompareStruct(const void *pStructA, const void *pStructB);
+int _FcCompareStr(const void *pStrA, const void *pStrB);
char* GetNumWithCommas(int64_t nNumber);
-char* toLowerCase(char* str);
+char* toLowerCase(char* pszStr, size_t nLen);
+char* toUpperCase(char* pszStr, size_t nLen);
double GetByteUnit(int64_t nSize);
const char* GetByteUnitStr(int64_t nSize);
View
BIN msvc/gamePKG/gamePKG.suo
Binary file not shown.
View
BIN release/PS3_GAME/USRDIR/EBOOT.BIN
Binary file not shown.
View
212 src/gamePKG.cpp
@@ -1,5 +1,5 @@
// ---------------------------------------------------------------------
-// CaptainCPS-X's gamePKG Tool
+// CaptainCPS-X's gamePKG Tool (2012-2013)
// ---------------------------------------------------------------------
/*
@@ -9,11 +9,11 @@
2 - Store each found entry info to "gamePKG->pkglst[x]"
3 - When (X) is pressed:
- A) Create directory at "/dev_hdd0/vsh/game_pkg/" named as "gamePKG->pkglst[gamePKG->nSelectedPKG]->nPKGID"
+ A) Create directory at "/dev_hdd0/vsh/game_pkg/" named as "gamePKG->pkglst[nSelectedPKG].nPKGID"
Ex. "/dev_hdd0/vsh/game_pkg/80000000"
- B) Copy PKG file "gamePKG->pkglst[gamePKG->nSelectedPKG]->path" to "/dev_hdd0/vsh/game_pkg/800000.."
+ B) Copy PKG file "gamePKG->pkglst[nSelectedPKG].path" to "/dev_hdd0/vsh/game_pkg/800000.."
C) Write structured data file to "/dev_hdd0/vsh/game_pkg/800000..":
"d0.pdb"
@@ -30,8 +30,6 @@ Tested on:
* - implement easy thread creation class
- put delete operations into separate thread
- - implement 'qsort' module to sort PKG list
-
- support re-scaning devices for new PKG files
WIP - verify HDD for previously queued files
- display a Progress bar
@@ -91,7 +89,7 @@ void c_gamePKG::DisplayFrame()
::cellDbgFontPuts(xPos, yPos, nFontSize, 0xffffffff, "----------------------------------------------------------------------" );
yPos += yPosDiff;
- ::cellDbgFontPuts(xPos, yPos, nFontSize, 0xffffffff, " gamePKG Tool v1.1 - by CaptainCPS-X [2012]");
+ ::cellDbgFontPuts(xPos, yPos, nFontSize, 0xffffffff, " gamePKG Tool v1.1 - by CaptainCPS-X [2012-2013]");
yPos += yPosDiff;
::cellDbgFontPuts(xPos, yPos, nFontSize, 0xffffffff, "----------------------------------------------------------------------" );
yPos += yPosDiff;
@@ -173,7 +171,7 @@ void c_gamePKG::DisplayFrame()
nFontSize = 0.6f;
// PKG QUEUED
- if(pkglst[nPKG]->bQueued)
+ if(pkglst[nPKG].bQueued)
{
nColor = 0xff00ff00; // green
}
@@ -184,18 +182,18 @@ void c_gamePKG::DisplayFrame()
nColor = 0xff00ccff; // yellow
nFontSize = 0.8f;
- if(pkglst[nPKG]->bQueued)
+ if(pkglst[nPKG].bQueued)
{
nColor = 0xff0000ff; // red
}
}
::cellDbgFontPrintf(xPos, yPos, nFontSize, nColor, "[%d] %s [%.2f %s] %s %s",
nPKG+1,
- pkglst[nPKG]->title,
- GetByteUnit(pkglst[nPKG]->nSize), GetByteUnitStr(pkglst[nPKG]->nSize),
- pkglst[nPKG]->bInternal ? "[HDD]" : "[USB]",
- pkglst[nPKG]->bQueued ? "[Queued]" : " "
+ pkglst[nPKG].title,
+ GetByteUnit(pkglst[nPKG].nSize), GetByteUnitStr(pkglst[nPKG].nSize),
+ pkglst[nPKG].bInternal ? "[HDD]" : "[USB]",
+ pkglst[nPKG].bQueued ? "[Queued]" : " "
);
yPos += yPosDiff;
@@ -271,7 +269,7 @@ void c_gamePKG::InputFrame()
if ( !app.mIsCrossPressed && app.crossPressedNow )
{
- if(pkglst[nSelectedPKG]->bQueued)
+ if(pkglst[nTotalPKG].bQueued)
{
// already queued...
::cellMsgDialogOpen2(
@@ -292,8 +290,6 @@ void c_gamePKG::InputFrame()
app.onShutdown();
exit(0);
}
-
-
}
void c_gamePKG::DlgDisplayFrame()
@@ -305,8 +301,8 @@ void c_gamePKG::DlgDisplayFrame()
sprintf(
szMsg,
"Processing \"%s\" [%.2f %s]...\n\nPlease wait, this could take a while depending on the size of the PKG. Do not turn off the system.",
- pkglst[nSelectedPKG]->path,
- GetByteUnit(pkglst[nSelectedPKG]->nSize), GetByteUnitStr(pkglst[nSelectedPKG]->nSize)
+ pkglst[nTotalPKG].path,
+ GetByteUnit(pkglst[nTotalPKG].nSize), GetByteUnitStr(pkglst[nTotalPKG].nSize)
);
::cellMsgDialogOpen2(
@@ -322,15 +318,15 @@ void c_gamePKG::DlgDisplayFrame()
cellMsgDialogAbort();
char szMsg[256] = "";
- sprintf(szMsg, "Successfully added \"%s\" to queue.", pkglst[nSelectedPKG]->path);
+ sprintf(szMsg, "Successfully added \"%s\" to queue.", pkglst[nTotalPKG].path);
::cellMsgDialogOpen2(
CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_ON,
szMsg,
DlgCallbackFunction, NULL, NULL
);
- pkglst[nSelectedPKG]->bQueued = true;
+ pkglst[nTotalPKG].bQueued = true;
}
// COPY [ERROR]
@@ -339,18 +335,18 @@ void c_gamePKG::DlgDisplayFrame()
cellMsgDialogAbort();
char szMsg[256] = "";
- sprintf(szMsg, "Error while processing \"%s\".", pkglst[nSelectedPKG]->path);
+ sprintf(szMsg, "Error while processing \"%s\".", pkglst[nTotalPKG].path);
::cellMsgDialogOpen2(
CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_OFF,
szMsg,
DlgCallbackFunction, NULL, NULL
);
- pkglst[nSelectedPKG]->bQueued = false;
+ pkglst[nTotalPKG].bQueued = false;
- DeletePDBFiles(pkglst[nSelectedPKG]->nPKGID);
- RemovePKGDir(pkglst[nSelectedPKG]->nPKGID);
+ DeletePDBFiles(pkglst[nTotalPKG].nPKGID);
+ RemovePKGDir(pkglst[nTotalPKG].nPKGID);
}
if(nStatus == STATUS_RM_QUEUE_START)
@@ -367,7 +363,7 @@ void c_gamePKG::DlgDisplayFrame()
cellMsgDialogAbort();
char szMsg[256] = "";
- sprintf(szMsg, "Successfully removed \"%s\" from queue.", pkglst[nSelectedPKG]->title);
+ sprintf(szMsg, "Successfully removed \"%s\" from queue.", pkglst[nTotalPKG].title);
::cellMsgDialogOpen2(
CELL_MSGDIALOG_DIALOG_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_ON,
@@ -400,44 +396,41 @@ int c_gamePKG::GetPKGDirId()
int c_gamePKG::ParsePKGList(char* szDirectory)
{
- int fd;
- CellFsDirent dirEntry;
-
- CellFsErrno res = cellFsOpendir(szDirectory, &fd);
-
- if (res == CELL_FS_SUCCEEDED)
+ DIR *d = NULL;
+
+ d = opendir(szDirectory);
+
+ if(d != NULL)
{
- uint64_t nread;
+ dirent *dirEntry;
- while(cellFsReaddir(fd, &dirEntry, &nread) == CELL_FS_SUCCEEDED)
+ while((dirEntry = readdir(d)) != NULL)
{
- if(nread == 0) break;
-
- if (dirEntry.d_type == CELL_FS_TYPE_DIRECTORY)
+ if (dirEntry->d_type == DT_DIR)
{
// DIRECTORY
} else {
- if(dirEntry.d_type != CELL_FS_TYPE_REGULAR) break;
-
+ if(dirEntry->d_type != DT_REG) break;
+
// FILE
- int nNameLen = strlen(dirEntry.d_name);
+ int nNameLen = strlen(dirEntry->d_name);
if (nNameLen < 5) continue;
-
+
// PKG
char* pszFilename = NULL;
- pszFilename = (char*)malloc(sizeof(char) * nNameLen);
- memcpy(pszFilename, dirEntry.d_name, nNameLen);
+ pszFilename = (char*)malloc(nNameLen+1);
+ memcpy(pszFilename, dirEntry->d_name, nNameLen);
+ pszFilename[nNameLen] = 0;
- if(strstr(toLowerCase(pszFilename), ".pkg"))
+ if(NULL != strstr(toLowerCase(pszFilename, strlen(pszFilename)), ".pkg"))
{
// Add entry values to game list
- pkglst[nTotalPKG] = new c_pkglist();
-
- if(strstr(szDirectory, "/dev_hdd0"))
+
+ if(NULL != strstr(szDirectory, "/dev_hdd0"))
{
- pkglst[nTotalPKG]->bInternal = true;
+ pkglst[nTotalPKG].bInternal = true;
}
// PKG Path
@@ -446,90 +439,54 @@ int c_gamePKG::ParsePKGList(char* szDirectory)
szDirectory[strlen(szDirectory)-1] = 0;
}
- sprintf(pkglst[nTotalPKG]->path, "%s/%s", szDirectory, dirEntry.d_name);
+ sprintf(pkglst[nTotalPKG].path, "%s/%s", szDirectory, dirEntry->d_name);
// PKG Filename
- sprintf(pkglst[nTotalPKG]->title, "%s", dirEntry.d_name);
+ sprintf(pkglst[nTotalPKG].title, "%s", dirEntry->d_name);
// PKG directory ID (ex. 80000000)
- while(pkglst[nTotalPKG]->nPKGID == 0)
+ while(pkglst[nTotalPKG].nPKGID == 0)
{
- pkglst[nTotalPKG]->nPKGID = GetPKGDirId();
+ pkglst[nTotalPKG].nPKGID = GetPKGDirId();
}
// PKG Size in bytes
- pkglst[nTotalPKG]->nSize = GetPKGSize(pkglst[nTotalPKG]->path);
+ pkglst[nTotalPKG].nSize = GetPKGSize(pkglst[nTotalPKG].path);
nTotalPKG++;
nPKGID++;
}
+
+ if(pszFilename) {
+ free(pszFilename);
+ pszFilename = NULL;
+ }
}
}
- cellFsClosedir(fd);
-
- } else {
-
- // DEBUG
-/*
- const char *msg = NULL;
- switch(res)
- {
- case CELL_FS_ENOTMOUNTED: // File system corresponding to path is not mounted
- msg = "CELL_FS_ENOTMOUNTED";
- break;
- case CELL_FS_ENOENT: // The specified directory does not exist
- msg = "CELL_FS_ENOENT";
- break;
- case CELL_FS_ENOTDIR: // The specified path is not a directory, Components in path contain something other than a directory
- msg = "CELL_FS_ENOTDIR";
- break;
- case CELL_FS_EMFILE: // The number of file descriptors that can be opened at the same time has reached the maximum
- msg = "CELL_FS_EMFILE";
- break;
- case CELL_FS_EIO: // I/O error has occurred
- msg = "CELL_FS_EIO";
- break;
- case CELL_FS_ENOMEM: // Memory is insufficient, File specified by path does not exist
- msg = "CELL_FS_ENOMEM";
- break;
- case CELL_FS_ENAMETOOLONG: // path or components in path exceed the maximum length
- msg = "CELL_FS_EFAULT";
- break;
- case CELL_FS_EFSSPECIFIC: // File system specific internal error has occurred
- msg = "CELL_FS_EFSSPECIFIC";
- break;
- case CELL_FS_EPERM: // Permission is invalid
- msg = "CELL_FS_EPERM";
- break;
- case CELL_FS_EFAULT: // path or fd is NULL
- msg = "CELL_FS_EFAULT";
- break;
- }
- ::cellMsgDialogOpen2(CELL_MSGDIALOG_DIALOG_TYPE_NORMAL, msg, DlgCallbackFunction, NULL, NULL);
-*/
- return 0;
+ closedir(d);
}
return 1;
}
void c_gamePKG::RefreshPKGList()
{
- if(nTotalPKG > 0)
+ if(nTotalPKG > 0)
{
- for(int nPKG = 0; nPKG < nTotalPKG; nPKG++)
- {
- if(pkglst[nPKG])
- {
- delete [] pkglst[nPKG];
- pkglst[nPKG] = NULL;
- }
+ if(pkglst) {
+ free(pkglst);
+ pkglst = NULL;
}
nTotalPKG = 0;
}
+ pkglst = (struct c_pkglist*)malloc(sizeof(struct c_pkglist) * 1000);
+
char szDir[][256] = {
- "", "pkg", "package", "packages"
+ "",
+ "PKG",
+ "PACKAGE",
+ "PACKAGES"
};
char szDevice[][256] = {
@@ -548,7 +505,9 @@ void c_gamePKG::RefreshPKGList()
sprintf(szPath, "%s/%s", szDevice[nDev], szDir[nDir]);
ParsePKGList(szPath);
}
- }
+ }
+
+ qsort(pkglst, nTotalPKG, sizeof(struct c_pkglist), _FcCompareStruct);
}
int c_gamePKG::RemovePKGDir(int nId)
@@ -645,7 +604,7 @@ void c_gamePKG::RemovePKG(int nId)
bDeleting = true;
char szPKG[256] = "";
- sprintf(szPKG, "/dev_hdd0/vsh/game_pkg/%d/%s", nId, pkglst[nSelectedPKG]->title);
+ sprintf(szPKG, "/dev_hdd0/vsh/game_pkg/%d/%s", nId, pkglst[nSelectedPKG].title);
FILE *fpPKG;
@@ -661,17 +620,17 @@ void c_gamePKG::RemovePKG(int nId)
void c_gamePKG::RemoveFromQueue()
{
- if(bDeleting || !pkglst[nSelectedPKG]->bQueued) return; // nothing to do here...
+ if(bDeleting || !pkglst[nSelectedPKG].bQueued) return; // nothing to do here...
nStatus = STATUS_RM_QUEUE_START;
- pkglst[nSelectedPKG]->bQueued = false;
+ pkglst[nSelectedPKG].bQueued = false;
char szDir[256] = "";
- sprintf(szDir, "/dev_hdd0/vsh/game_pkg/%d", pkglst[nSelectedPKG]->nPKGID);
+ sprintf(szDir, "/dev_hdd0/vsh/game_pkg/%d", pkglst[nSelectedPKG].nPKGID);
RemoveAllDirFiles(szDir);
- RemovePKGDir(pkglst[nSelectedPKG]->nPKGID);
+ RemovePKGDir(pkglst[nSelectedPKG].nPKGID);
// todo: add error checking here...
@@ -700,8 +659,8 @@ int c_gamePKG::CreatePDBFiles()
// Create files
char szPDBFile[256] = "";
char szIconFile[256] = "";
- sprintf(szPDBFile, "/dev_hdd0/vsh/game_pkg/%d/d0.pdb", pkglst[nSelectedPKG]->nPKGID);
- sprintf(szIconFile, "/dev_hdd0/vsh/game_pkg/%d/ICON_FILE", pkglst[nSelectedPKG]->nPKGID);
+ sprintf(szPDBFile, "/dev_hdd0/vsh/game_pkg/%d/d0.pdb", pkglst[nSelectedPKG].nPKGID);
+ sprintf(szIconFile, "/dev_hdd0/vsh/game_pkg/%d/ICON_FILE", pkglst[nSelectedPKG].nPKGID);
FILE *fpPDB, *fpIcon;
fpPDB = fopen(szPDBFile, "wb");
@@ -757,7 +716,7 @@ int c_gamePKG::CreatePDBFiles()
0x00, 0x00, 0x00, 0x08
};
fwrite(dl_progress, 12, 1, fpPDB);
- fwrite((char*) &pkglst[nSelectedPKG]->nSize, 8, 1, fpPDB);
+ fwrite((char*) &pkglst[nSelectedPKG].nSize, 8, 1, fpPDB);
// 000000CE - Download expected size (in bytes)
char dl_size[12] = {
@@ -766,7 +725,7 @@ int c_gamePKG::CreatePDBFiles()
0x00, 0x00, 0x00, 0x08
};
fwrite(dl_size, 12, 1, fpPDB);
- fwrite((char*) &pkglst[nSelectedPKG]->nSize, 8, 1, fpPDB);
+ fwrite((char*) &pkglst[nSelectedPKG].nSize, 8, 1, fpPDB);
// 00000069 - Display title
char title[4] = {
@@ -775,7 +734,7 @@ int c_gamePKG::CreatePDBFiles()
fwrite(title, 4, 1, fpPDB);
char title_str[256] = "";
- sprintf(title_str, "\xE2\x98\x85 Install \x22%s\x22", pkglst[nSelectedPKG]->title);
+ sprintf(title_str, "\xE2\x98\x85 Install \x22%s\x22", pkglst[nSelectedPKG].title);
unsigned int title_len = strlen(title_str) + 1;
fwrite((char*) &title_len, 4, 1, fpPDB);
@@ -788,10 +747,10 @@ int c_gamePKG::CreatePDBFiles()
};
fwrite(filename, 4, 1, fpPDB);
- unsigned int filename_len = strlen(pkglst[nSelectedPKG]->title) + 1;
+ unsigned int filename_len = strlen(pkglst[gamePKG->nSelectedPKG].title) + 1;
fwrite((char*) &filename_len, 4, 1, fpPDB);
fwrite((char*) &filename_len, 4, 1, fpPDB);
- fwrite(pkglst[nSelectedPKG]->title, filename_len, 1, fpPDB);
+ fwrite(pkglst[gamePKG->nSelectedPKG].title, filename_len, 1, fpPDB);
// 0000006A - Icon location / path (PNG w/o extension)
char iconpath[4] ={
@@ -827,16 +786,16 @@ void thread_FileCopy(uint64_t /*arg*/)
int numr, numw;
char *buffer;
- buffer = (char*)malloc(sizeof(char) * BUFF_SIZE);
+ buffer = (char*)malloc(BUFF_SIZE);
- filer = fopen(gamePKG->pkglst[gamePKG->nSelectedPKG]->path,"rb");
+ filer = fopen(gamePKG->pkglst[gamePKG->nSelectedPKG].path,"rb");
char szFileOut[256] ="";
sprintf(
szFileOut,
"/dev_hdd0/vsh/game_pkg/%d/%s",
- gamePKG->pkglst[gamePKG->nSelectedPKG]->nPKGID,
- gamePKG->pkglst[gamePKG->nSelectedPKG]->title
+ gamePKG->pkglst[gamePKG->nSelectedPKG].nPKGID,
+ gamePKG->pkglst[gamePKG->nSelectedPKG].title
);
filew = fopen(szFileOut, "wb");
@@ -894,8 +853,11 @@ void thread_FileCopy(uint64_t /*arg*/)
return;
}
- if(buffer) free(buffer);
- buffer = NULL;
+ if(buffer)
+ {
+ free(buffer);
+ buffer = NULL;
+ }
gamePKG->nStatus = STATUS_COPY_OK;
sys_ppu_thread_exit(0);
@@ -904,7 +866,7 @@ void thread_FileCopy(uint64_t /*arg*/)
int c_gamePKG::QueuePKG()
{
char pszPKGDir[256] ="";
- sprintf(pszPKGDir, "/dev_hdd0/vsh/game_pkg/%d", pkglst[nSelectedPKG]->nPKGID);
+ sprintf(pszPKGDir, "/dev_hdd0/vsh/game_pkg/%d", pkglst[nSelectedPKG].nPKGID);
CellFsErrno ret;
ret = cellFsMkdir("/dev_hdd0/vsh/game_pkg", CELL_FS_S_IFDIR | 0777);
@@ -917,7 +879,7 @@ int c_gamePKG::QueuePKG()
"[Error] Could not create the required directory on HDD.",
DlgCallbackFunction, NULL, NULL
);
- pkglst[nSelectedPKG]->bQueued = false;
+ pkglst[nSelectedPKG].bQueued = false;
return 0;
}
@@ -928,7 +890,7 @@ int c_gamePKG::QueuePKG()
"[Error] Could not create / write needed files to HDD.",
DlgCallbackFunction, NULL, NULL
);
- pkglst[nSelectedPKG]->bQueued = false;
+ pkglst[nSelectedPKG].bQueued = false;
return 0;
}
View
131 src/misc.cpp
@@ -3,27 +3,43 @@
// ---------------------------------------------------------------------
// Misc utility modules
#include "main.h"
+#include "gamePKG.h"
#include "misc.h"
+// Struct compare function for QSORT
+int _FcCompareStruct(const void *a, const void *b)
+{
+ struct c_pkglist *ia = (struct c_pkglist *)a;
+ struct c_pkglist *ib = (struct c_pkglist *)b;
+
+ return strcmp(toLowerCase(ia->title, 256), toLowerCase(ib->title, 256));
+}
+
+// String compare function for QSORT
+int _FcCompareStr(const void *pStrA, const void *pStrB)
+{
+ const bool bAscending = true; // Always ascending [left as reference]
+ return bAscending ?
+ strcmp(*(char**)pStrA, *(char**)pStrB): // Ascending [Ex. A,B,C]
+ strcmp(*(char**)pStrB, *(char**)pStrA); // Descending [Ex. C,B,A]
+}
+
#define addch(str, ch) \
str[strlen(str)] = ch; \
str[strlen(str)+1] = '\0';
char* GetNumWithCommas(int64_t nNumber)
{
bool bIsNegative = false;
- char szNumber[256] = "\0";
- char szFlippedNumber[256] = "\0";
- char szCommaFlippedNumber[256] = "\0";
+ char szNumber[256] = "";
+ char szFlippedNumber[256] = "";
+ char szCommaFlippedNumber[256] = "";
// Check negative number
if(nNumber < 0) {
bIsNegative = true;
}
- // Avoid memory issues
- char* szCommaNumber = (char*)malloc(256 * sizeof(char));
-
// Convert integer to string
sprintf(szNumber, "%lld", nNumber);
@@ -34,14 +50,14 @@ char* GetNumWithCommas(int64_t nNumber)
}
// Flip number string
- for(int nDigit = 0; nDigit < (int)strlen(szNumber); nDigit++) {
+ for(unsigned int nDigit = 0; nDigit < strlen(szNumber); nDigit++) {
addch(szFlippedNumber, szNumber[strlen(szNumber)-(nDigit+1)]);
}
// Add commas each 3 digits
- int nDigit = 0, nCount = 0;
+ unsigned int nDigit = 0, nCount = 0;
- while(nDigit < (int)strlen(szFlippedNumber))
+ while(nDigit < strlen(szFlippedNumber))
{
if(nCount == 3) {
addch(szCommaFlippedNumber, ',');
@@ -53,36 +69,52 @@ char* GetNumWithCommas(int64_t nNumber)
nCount++;
}
+ // Avoid memory issues
+ char* szCommaNumber = (char*)malloc(strlen(szCommaFlippedNumber)+2); // +2 for the '-' and '\0'
+
// Flip the new formatted number
- for(nDigit = 0; nDigit < (int)strlen(szCommaFlippedNumber); nDigit++) {
+ for(nDigit = 0; nDigit < strlen(szCommaFlippedNumber); nDigit++) {
addch(szCommaNumber, szCommaFlippedNumber[strlen(szCommaFlippedNumber)-(nDigit+1)]);
}
// Add negative sign if needed
if(bIsNegative) {
- char szNegative[256] = "\0";
+ char szNegative[256] = "";
sprintf(szNegative, "-%s", szCommaNumber);
strcpy(szCommaNumber, szNegative);
}
return szCommaNumber;
}
-char* toLowerCase(char* str)
+// Simple function to convert a string to lower case
+char* toLowerCase(char* pszStr, size_t nLen)
{
- int differ = 'A'-'a';
- char ch;
- int ii = strlen(str);
- for (int i=0; i <ii;i++)
- {
- strncpy(&ch, str+i, 1);
- if (ch>='A' && ch<='Z')
- {
- ch = ch-differ;
- memcpy(str+i,&ch,1);
- }
+ char* pszNewStr = NULL;
+ pszNewStr = (char*)malloc(sizeof(char) * nLen+1);
+ memcpy(pszNewStr, pszStr, nLen);
+ pszNewStr[nLen] = 0; // null-terminated string
+
+ for(int ch = 0; pszNewStr[ch]; ch++) {
+ pszNewStr[ch] = tolower(pszNewStr[ch]);
}
- return str;
+
+ return pszNewStr;
+}
+
+// Simple function to convert a string to upper case
+char* toUpperCase(char* pszStr, size_t nLen)
+{
+ char* pszNewStr = NULL;
+ pszNewStr = (char*)malloc(sizeof(char) * nLen+1);
+ memcpy(pszNewStr, pszStr, nLen);
+ pszNewStr[nLen] = 0; // null-terminated string
+
+ for(int ch = 0; pszNewStr[ch]; ch++) {
+ pszNewStr[ch] = toupper(pszNewStr[ch]);
+ }
+
+ return pszNewStr;
}
// lpByteSize / 1,024
@@ -96,46 +128,31 @@ char* toLowerCase(char* str)
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-double GetByteUnit(int64_t nSize)
+int64_t _ex(int64_t nNum, int64_t nEx)
{
- // TB
- if(nSize >= (1024LL * 1024LL * 1024LL * 1024LL)) {
- return CALCTERABYTE(nSize);
- }
- // GB
- if(nSize >= (1024LL * 1024LL * 1024LL)) {
- return CALCGIGABYTE(nSize);
- }
- // MB
- if(nSize >= (1024LL * 1024LL)) {
- return CALCMEGABYTE(nSize);
- }
- // KB
- if(nSize >= 1024LL) {
- return CALCKILOBYTE(nSize);
+ int64_t nFinalNum = nNum;
+ for(int64_t m = 0; m < nEx-1; m++) {
+ nFinalNum = nFinalNum * nNum;
}
+ return nFinalNum;
+}
+
+double GetByteUnit(int64_t nSize)
+{
+ if(nSize >= _ex(1024, 4)) return CALCTERABYTE(nSize);
+ if(nSize >= _ex(1024, 3)) return CALCGIGABYTE(nSize);
+ if(nSize >= _ex(1024, 2)) return CALCMEGABYTE(nSize);
+ if(nSize >= _ex(1024, 1)) return CALCKILOBYTE(nSize);
return (double)nSize;
}
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
const char* GetByteUnitStr(int64_t nSize)
-{
- // TB
- if(nSize >= (1024LL * 1024LL * 1024LL * 1024LL)) {
- return "TB";
- }
- // GB
- if(nSize >= (1024LL * 1024LL * 1024LL)) {
- return "GB";
- }
- // MB
- if(nSize >= (1024LL * 1024LL)) {
- return "MB";
- }
- // KB
- if(nSize >= 1024LL) {
- return "KB";
- }
+{
+ if(nSize >= _ex(1024, 4)) return "TB";
+ if(nSize >= _ex(1024, 3)) return "GB";
+ if(nSize >= _ex(1024, 2)) return "MB";
+ if(nSize >= _ex(1024, 1)) return "KB";
return "Bytes";
}

0 comments on commit eadd1d1

Please sign in to comment.
Something went wrong with that request. Please try again.