merge changes from cebolleto

This commit is contained in:
dborth 2014-10-24 02:51:36 +00:00
parent b68a302c9f
commit 2037f6cfa1
11 changed files with 4132 additions and 4045 deletions

View File

@ -63,7 +63,7 @@ int ShutdownRequested = 0;
int ResetRequested = 0;
int ExitRequested = 0;
char appPath[1024] = { 0 };
char loadedFile[1024] = { 0 };
int frameskip = 0;
int turbomode = 0;
unsigned char * nesrom = NULL;

View File

@ -80,8 +80,10 @@ struct SGCSettings{
int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB)
int SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, USB, SMB
char LoadFolder[MAXPATHLEN]; // Path to game files
char LastFileLoaded[MAXPATHLEN]; //Last file loaded filename
char SaveFolder[MAXPATHLEN]; // Path to save files
char CheatFolder[MAXPATHLEN]; // Path to cheat files
char ScreenshotsFolder[MAXPATHLEN]; //Path to screenshots files
char smbip[80];
char smbuser[20];
@ -120,7 +122,6 @@ extern int ConfigRequested;
extern int ShutdownRequested;
extern int ExitRequested;
extern char appPath[];
extern char loadedFile[];
extern int frameskip;
extern int fskip;
extern int fskipc;

View File

@ -36,7 +36,8 @@ BROWSERINFO browser;
BROWSERENTRY * browserList = NULL; // list of files/folders in browser
static char szpath[MAXPATHLEN];
static bool inSz = false;
char szname[MAXPATHLEN];
bool inSz = false;
char romFilename[256];
bool loadingFile = false;
@ -211,6 +212,8 @@ int UpdateDirName()
/* remove last subdirectory name */
size = strlen(browser.dir) - size - 1;
strncpy(GCSettings.LastFileLoaded, &browser.dir[size], strlen(browser.dir) - size - 1); //set as loaded file the previous dir
GCSettings.LastFileLoaded[strlen(browser.dir) - size - 1] = 0;
browser.dir[size] = 0;
}
@ -429,12 +432,11 @@ void StripExt(char* returnstring, char * inputstring)
***************************************************************************/
int BrowserLoadSz()
{
char filepath[MAXPATHLEN];
memset(filepath, 0, MAXPATHLEN);
memset(szpath, 0, MAXPATHLEN);
strncpy(szpath, browser.dir, strlen(browser.dir) - 1);
// we'll store the 7z filepath for extraction later
if(!MakeFilePath(szpath, FILE_ROM))
return 0;
strncpy(szname, strrchr(szpath, '/') + 1, strrchr(szpath, '.') - strrchr(szpath, '/'));
*strrchr(szname, '.') = '\0';
int szfiles = SzParse(szpath);
if(szfiles)
@ -500,7 +502,7 @@ int BrowserLoadFile()
{
// store the filename (w/o ext) - used for ram/state naming
StripExt(romFilename, browserList[browser.selIndex].filename);
strcpy(loadedFile, browserList[browser.selIndex].filename);
snprintf(GCSettings.LastFileLoaded, MAXPATHLEN, "%s", browserList[browser.selIndex].filename);
// load UPS/IPS/PPF patch
filesize = LoadPatch(filesize);
@ -543,12 +545,22 @@ int BrowserChangeFolder()
if(!UpdateDirName())
return -1;
HaltParseThread(); // halt parsing
HaltParseThread();
CleanupPath(browser.dir);
ResetBrowser(); // reset browser
ResetBrowser();
if(browser.dir[0] != 0)
ParseDirectory();
{
if(strstr(browser.dir, ".7z"))
{
BrowserLoadSz();
}
else
{
ParseDirectory(true, true);
}
FindAndSelectLastLoadedFile();
}
if(browser.numEntries == 0)
{

View File

@ -55,6 +55,8 @@ enum
extern char romFilename[];
extern bool loadingFile;
extern char szname[MAXPATHLEN];
extern bool inSz;
bool MakeFilePath(char filepath[], int type, char * filename = NULL, int filenum = -2);
int UpdateDirName();

View File

@ -55,7 +55,7 @@ bool isMounted[7] = { false, false, false, false, false, false, false };
// folder parsing thread
static lwp_t parsethread = LWP_THREAD_NULL;
static DIR * dir = NULL;
static DIR *dir = NULL;
static bool parseHalt = true;
static bool parseFilter = true;
static bool ParseDirEntries();
@ -492,6 +492,40 @@ bool GetFileSize(int i)
return true;
}
void FindAndSelectLastLoadedFile ()
{
int indexFound = -1;
for(int j=1; j < browser.numEntries; j++)
{
if(strcmp(browserList[j].filename, GCSettings.LastFileLoaded) == 0)
{
indexFound = j;
break;
}
}
// move to this file
if(indexFound > 0)
{
if(indexFound >= FILE_PAGESIZE)
{
int newIndex = (floor(indexFound/(float)FILE_PAGESIZE)) * FILE_PAGESIZE;
if(newIndex + FILE_PAGESIZE > browser.numEntries)
newIndex = browser.numEntries - FILE_PAGESIZE;
if(newIndex < 0)
newIndex = 0;
browser.pageIndex = newIndex;
}
browser.selIndex = indexFound;
}
selectLoadedFile = 2; // selecting done
}
static bool ParseDirEntries()
{
if(!dir)
@ -578,39 +612,6 @@ static bool ParseDirEntries()
closedir(dir); // close directory
dir = NULL;
// try to find and select the last loaded file
if(selectLoadedFile == 1 && !parseHalt && loadedFile[0] != 0 && browser.dir[0] != 0)
{
int indexFound = -1;
for(int j=1; j < browser.numEntries; j++)
{
if(strcmp(browserList[j].filename, loadedFile) == 0)
{
indexFound = j;
break;
}
}
// move to this file
if(indexFound > 0)
{
if(indexFound >= FILE_PAGESIZE)
{
int newIndex = (floor(indexFound/(float)FILE_PAGESIZE)) * FILE_PAGESIZE;
if(newIndex + FILE_PAGESIZE > browser.numEntries)
newIndex = browser.numEntries - FILE_PAGESIZE;
if(newIndex < 0)
newIndex = 0;
browser.pageIndex = newIndex;
}
browser.selIndex = indexFound;
}
selectLoadedFile = 2; // selecting done
}
return false; // no more entries
}
return true; // more entries

View File

@ -30,6 +30,7 @@ bool ChangeInterface(int device, bool silent);
bool ChangeInterface(char * filepath, bool silent);
void CreateAppPath(char * origpath);
bool GetFileSize(int i);
void FindAndSelectLastLoadedFile();
int ParseDirectory(bool waitParse = false, bool filter = true);
void AllocSaveBuffer();
void FreeSaveBuffer();

View File

@ -368,14 +368,15 @@ int SzParse(char * filepath)
int device;
if(!FindDevice(browser.dir, &device) || !GetFileSize(browser.selIndex))
struct stat filestat;
if(stat(filepath, &filestat) < 0)
return 0;
unsigned int filelen = filestat.st_size;
if(!FindDevice(filepath, &device) || !filelen)
return 0;
int nbfiles = 0;
// save the length/offset of this file
unsigned int filelen = browserList[browser.selIndex].length;
// setup archive stream
SzArchiveStream.offset = 0;
SzArchiveStream.len = filelen;
@ -424,7 +425,7 @@ int SzParse(char * filepath)
// add '..' folder in case the user wants exit the 7z
AddBrowserEntry();
sprintf(browserList[0].filename, "..");
sprintf(browserList[0].displayname, "Up One Level");
browserList[0].isdir = 1;
browserList[0].length = filelen;
@ -453,6 +454,12 @@ int SzParse(char * filepath)
// parse information about this file to the file list structure
snprintf(browserList[SzJ].filename, MAXJOLIET, "%s", SzF->Name);
StripExt(browserList[SzJ].displayname, browserList[SzJ].filename);
char* strPos = strstr(browserList[SzJ].displayname, szname);
if(strPos)
{
snprintf(browserList[SzJ].displayname, MAXJOLIET, "%s", strPos + strlen(szname));
}
browserList[SzJ].length = SzF->Size; // filesize
browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags)
browserList[SzJ].filenum = SzI; // the extraction function identifies the file with this number

View File

@ -240,7 +240,7 @@ class GuiElement
//!Constructor
GuiElement();
//!Destructor
~GuiElement();
virtual ~GuiElement();
//!Set the element's parent
//!\param e Pointer to parent element
void SetParent(GuiElement * e);

View File

@ -47,6 +47,11 @@
static GuiImageData * pointer[4];
#endif
#define MEM_ALLOC(A) (u8*)memalign(32, A)
#define MEM_DEALLOC(A) free(A)
static GuiTrigger * trigA = NULL;
static GuiTrigger * trig2 = NULL;
@ -315,7 +320,7 @@ UpdateGUI (void *arg)
for(i = 0; i <= 255; i += 15)
{
mainWindow->Draw();
Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0, 0, 0, i},1);
Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0, 0, 0, (u8)i},1);
Menu_Render();
}
ExitApp();
@ -969,15 +974,23 @@ static int MenuGameSelection()
buttonWindow.Append(&exitBtn);
GuiFileBrowser gameBrowser(424, 268);
gameBrowser.SetPosition(50, 98);
gameBrowser.SetPosition(10, 98);
ResetBrowser();
GuiImage preview;
preview.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
preview.SetPosition(-10, 0);
u8* imgBuffer = MEM_ALLOC(512 * 512 * 4);
int previousBrowserIndex = -1;
char screenshotPath[MAXJOLIET + 1];
HaltGui();
btnLogo->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
btnLogo->SetPosition(-50, 24);
mainWindow->Append(&titleTxt);
mainWindow->Append(&gameBrowser);
mainWindow->Append(&buttonWindow);
mainWindow->Append(&preview);
ResumeGui();
#ifdef HW_RVL
@ -991,6 +1004,7 @@ static int MenuGameSelection()
gameBrowser.ResetState();
gameBrowser.fileList[0]->SetState(STATE_SELECTED);
gameBrowser.TriggerUpdate();
titleTxt.SetText(inSz ? szname : "Choose Game");
while(menu == MENU_NONE)
{
@ -1010,25 +1024,29 @@ static int MenuGameSelection()
if(gameBrowser.fileList[i]->GetState() == STATE_CLICKED)
{
gameBrowser.fileList[i]->ResetState();
// check corresponding browser entry
if(browserList[browser.selIndex].isdir || IsSz())
{
if(IsSz())
res = BrowserLoadSz();
else
HaltGui();
res = BrowserChangeFolder();
if(res)
{
gameBrowser.ResetState();
gameBrowser.fileList[0]->SetState(STATE_SELECTED);
gameBrowser.TriggerUpdate();
previousBrowserIndex = -1;
}
else
{
menu = MENU_GAMESELECTION;
break;
}
titleTxt.SetText(inSz ? szname : "Choose Game");
ResumeGui();
}
else
{
@ -1036,6 +1054,7 @@ static int MenuGameSelection()
ShutoffRumble();
#endif
mainWindow->SetState(STATE_DISABLED);
SavePrefs(SILENT);
if(BrowserLoadFile())
menu = MENU_EXIT;
else
@ -1044,6 +1063,33 @@ static int MenuGameSelection()
}
}
//update game screenshot
if(previousBrowserIndex != browser.selIndex)
{
previousBrowserIndex = browser.selIndex;
snprintf(screenshotPath, MAXJOLIET, "%s%s/%s.png", pathPrefix[GCSettings.LoadMethod], GCSettings.ScreenshotsFolder, browserList[browser.selIndex].displayname);
AllocSaveBuffer();
int width, height;
if(LoadFile(screenshotPath, SILENT))
{
if(DecodePNG(savebuffer, &width, &height, imgBuffer, 512, 512))
{
preview.SetImage(imgBuffer, width, height);
preview.SetScale(180.0f / width);
}
else
{
preview.SetImage(NULL, 0, 0);
}
}
else
{
preview.SetImage(NULL, 0, 0);
}
FreeSaveBuffer();
}
if(settingsBtn.GetState() == STATE_CLICKED)
menu = MENU_SETTINGS;
else if(exitBtn.GetState() == STATE_CLICKED)
@ -1056,6 +1102,8 @@ static int MenuGameSelection()
mainWindow->Remove(&titleTxt);
mainWindow->Remove(&buttonWindow);
mainWindow->Remove(&gameBrowser);
mainWindow->Remove(&preview);
MEM_DEALLOC(imgBuffer);
return menu;
}
@ -3317,6 +3365,7 @@ static int MenuSettingsFile()
sprintf(options.name[i++], "Load Folder");
sprintf(options.name[i++], "Save Folder");
sprintf(options.name[i++], "Cheats Folder");
sprintf(options.name[i++], "Screenshots Folder");
sprintf(options.name[i++], "Auto Load");
sprintf(options.name[i++], "Auto Save");
options.length = i;
@ -3390,12 +3439,16 @@ static int MenuSettingsFile()
break;
case 5:
OnScreenKeyboard(GCSettings.ScreenshotsFolder, MAXPATHLEN);
break;
case 6:
GCSettings.AutoLoad++;
if (GCSettings.AutoLoad > 2)
GCSettings.AutoLoad = 0;
break;
case 6:
case 7:
GCSettings.AutoSave++;
if (GCSettings.AutoSave > 3)
GCSettings.AutoSave = 0;
@ -3461,15 +3514,16 @@ static int MenuSettingsFile()
snprintf (options.value[2], 35, "%s", GCSettings.LoadFolder);
snprintf (options.value[3], 35, "%s", GCSettings.SaveFolder);
snprintf (options.value[4], 35, "%s", GCSettings.CheatFolder);
snprintf (options.value[5], 35, "%s", GCSettings.ScreenshotsFolder);
if (GCSettings.AutoLoad == 0) sprintf (options.value[5],"Off");
else if (GCSettings.AutoLoad == 1) sprintf (options.value[5],"RAM");
else if (GCSettings.AutoLoad == 2) sprintf (options.value[5],"State");
if (GCSettings.AutoLoad == 0) sprintf (options.value[6],"Off");
else if (GCSettings.AutoLoad == 1) sprintf (options.value[6],"RAM");
else if (GCSettings.AutoLoad == 2) sprintf (options.value[6],"State");
if (GCSettings.AutoSave == 0) sprintf (options.value[6],"Off");
else if (GCSettings.AutoSave == 1) sprintf (options.value[6],"RAM");
else if (GCSettings.AutoSave == 2) sprintf (options.value[6],"State");
else if (GCSettings.AutoSave == 3) sprintf (options.value[6],"Both");
if (GCSettings.AutoSave == 0) sprintf (options.value[7],"Off");
else if (GCSettings.AutoSave == 1) sprintf (options.value[7],"RAM");
else if (GCSettings.AutoSave == 2) sprintf (options.value[7],"State");
else if (GCSettings.AutoSave == 3) sprintf (options.value[7],"Both");
optionBrowser.TriggerUpdate();
}

View File

@ -124,9 +124,11 @@ preparePrefsData ()
createXMLSetting("LoadMethod", "Load Method", toStr(GCSettings.LoadMethod));
createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod));
createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder);
createXMLSetting("LastFileLoaded", "Last File Loaded", GCSettings.LastFileLoaded);
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
createXMLSetting("gamegenie", "Game Genie", toStr(GCSettings.gamegenie));
createXMLSetting("ScreenshotsFolder", "Screenshots Folder", GCSettings.ScreenshotsFolder);
createXMLSection("Network", "Network Settings");
@ -296,9 +298,11 @@ decodePrefsData ()
loadXMLSetting(&GCSettings.LoadMethod, "LoadMethod");
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
loadXMLSetting(GCSettings.LastFileLoaded, "LastFileLoaded", sizeof(GCSettings.LastFileLoaded));
loadXMLSetting(GCSettings.SaveFolder, "SaveFolder", sizeof(GCSettings.SaveFolder));
loadXMLSetting(GCSettings.CheatFolder, "CheatFolder", sizeof(GCSettings.CheatFolder));
loadXMLSetting(&GCSettings.gamegenie, "gamegenie");
loadXMLSetting(GCSettings.ScreenshotsFolder, "ScreenshotsFolder", sizeof(GCSettings.ScreenshotsFolder));
// Network Settings
@ -433,6 +437,7 @@ DefaultSettings ()
sprintf (GCSettings.LoadFolder, "%s/roms", APPFOLDER); // Path to game files
sprintf (GCSettings.SaveFolder, "%s/saves", APPFOLDER); // Path to save files
sprintf (GCSettings.CheatFolder, "%s/cheats", APPFOLDER); // Path to cheat files
sprintf (GCSettings.CheatFolder, "%s/screenshots", APPFOLDER); // Path to cheat files
GCSettings.AutoLoad = 1; // Auto Load RAM
GCSettings.AutoSave = 1; // Auto Save RAM
}

View File

@ -311,7 +311,7 @@ static int pngu_decode (IMGCTX ctx, u32 width, u32 height, u32 stripAlpha)
return PNGU_INVALID_WIDTH_OR_HEIGHT;
// Check if color type is supported by PNGU
if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_PALETTE) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_UNKNOWN) )
if (ctx->prop.imgColorType == PNGU_COLOR_TYPE_UNKNOWN)
return PNGU_UNSUPPORTED_COLOR_TYPE;
// Scale 16 bit samples to 8 bit
@ -330,6 +330,10 @@ static int pngu_decode (IMGCTX ctx, u32 width, u32 height, u32 stripAlpha)
if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) )
png_set_gray_to_rgb (ctx->png_ptr);
// Transform palette images to RGB
if (ctx->prop.imgColorType == PNGU_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(ctx->png_ptr);
// Flush transformations
png_read_update_info (ctx->png_ptr, ctx->info_ptr);