From 0e1c0985f9ff70c8cd9250834c1433e6f20fa93a Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 1 Apr 2009 05:48:01 +0000 Subject: [PATCH] documenting, fixing update feature --- source/ngc/fileop.cpp | 4 +- source/ngc/http.cpp | 3 +- source/ngc/menu.cpp | 134 ++++++++++++++++++++++++++++++++------- source/ngc/networkop.cpp | 5 +- 4 files changed, 117 insertions(+), 29 deletions(-) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index c92944b..dac0b48 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -80,8 +80,8 @@ devicecallback (void *arg) } } - //InitializeNetwork(SILENT); - //UpdateCheck(); + InitializeNetwork(SILENT); + UpdateCheck(); #else if(isMounted[METHOD_SD_SLOTA]) { diff --git a/source/ngc/http.cpp b/source/ngc/http.cpp index 29a3851..4d922e7 100644 --- a/source/ngc/http.cpp +++ b/source/ngc/http.cpp @@ -14,11 +14,9 @@ #include #include #include - #include #include #include - #include #include #include @@ -417,6 +415,7 @@ bool http_request(const char *url, FILE * hfile, u8 * buffer, ShowProgress("Downloading...", (content_length - bytesLeft), content_length); } + CancelAction(); } if (!b || !res) diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index fd927d9..8288360 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -57,8 +57,11 @@ static int mapMenuCtrl = 0; static int mapMenuCtrlNES = 0; static lwp_t guithread = LWP_THREAD_NULL; -static bool guiHalt = true; static lwp_t progressthread = LWP_THREAD_NULL; +#ifdef HW_RVL +static lwp_t updatethread = LWP_THREAD_NULL; +#endif +static bool guiHalt = true; static int showProgress = 0; static char progressTitle[100]; @@ -66,6 +69,13 @@ static char progressMsg[200]; static int progressDone = 0; static int progressTotal = 0; +/**************************************************************************** + * ResumeGui + * + * Signals the GUI thread to start, and resumes the thread. This is called + * after finishing the removal/insertion of new elements, and after initial + * GUI setup. + ***************************************************************************/ static void ResumeGui() { @@ -73,6 +83,14 @@ ResumeGui() LWP_ResumeThread (guithread); } +/**************************************************************************** + * HaltGui + * + * Signals the GUI thread to stop, and waits for GUI thread to stop + * This is necessary whenever removing/inserting new elements into the GUI. + * This eliminates the possibility that the GUI is in the middle of accessing + * an element that is being changed. + ***************************************************************************/ static void HaltGui() { @@ -85,8 +103,10 @@ HaltGui() /**************************************************************************** * WindowPrompt + * + * Displays a prompt window to user, with information, an error message, or + * presenting a user with a choice ***************************************************************************/ - int WindowPrompt(const char *title, const char *msg, const char *btn1Label, const char *btn2Label) { @@ -187,8 +207,32 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, const ch return choice; } +#ifdef HW_RVL +/**************************************************************************** + * EmulatorUpdate + * + * Prompts for confirmation, and downloads/installs updates + ***************************************************************************/ +static void * +EmulatorUpdate (void *arg) +{ + sleep(5); + bool installUpdate = WindowPrompt( + "Update Available", + "An update is available!", + "Update now", + "Update later"); + if(installUpdate) + if(DownloadUpdate()) + ExitRequested = 1; + return NULL; +} +#endif + /**************************************************************************** * UpdateGUI + * + * Primary thread to allow GUI to respond to state changes, and draws GUI ***************************************************************************/ /*static u32 arena1mem = 0; @@ -234,14 +278,8 @@ UpdateGUI (void *arg) #ifdef HW_RVL if(updateFound) { - updateFound = WindowPrompt( - "Update Available", - "An update is available!", - "Update now", - "Update later"); - if(updateFound) - if(DownloadUpdate()) - ExitRequested = 1; + updateFound = false; + LWP_CreateThread (&updatethread, EmulatorUpdate, NULL, NULL, 0, 70); } #endif @@ -268,8 +306,11 @@ UpdateGUI (void *arg) /**************************************************************************** * ProgressWindow + * + * Opens a window, which displays progress to the user. Can either display a + * progress bar showing % completion, or a throbber that only shows that an + * action is in progress. ***************************************************************************/ - static void ProgressWindow(char *title, char *msg) { @@ -385,8 +426,9 @@ static void * ProgressThread (void *arg) /**************************************************************************** * InitGUIThread + * + * Startup GUI threads ***************************************************************************/ - void InitGUIThreads() { @@ -395,11 +437,12 @@ InitGUIThreads() } /**************************************************************************** - * Progress Bar + * CancelAction * - * Show the user what's happening + * Signals the GUI progress window thread to halt, and waits for it to + * finish. Prevents multiple progress window events from interfering / + * overriding each other. ***************************************************************************/ - void CancelAction() { @@ -410,6 +453,12 @@ CancelAction() usleep(50); } +/**************************************************************************** + * ShowProgress + * + * Updates the variables used by the progress window for drawing a progress + * bar. Also resumes the progress window thread if it is suspended. + ***************************************************************************/ void ShowProgress (const char *msg, int done, int total) { @@ -432,6 +481,12 @@ ShowProgress (const char *msg, int done, int total) LWP_ResumeThread (progressthread); } +/**************************************************************************** + * ShowAction + * + * Shows that an action is underway. Also resumes the progress window thread + * if it is suspended. + ***************************************************************************/ void ShowAction (const char *msg) { @@ -461,6 +516,11 @@ void InfoPrompt(const char *msg) WindowPrompt("Information", msg, "OK", NULL); } +/**************************************************************************** + * AutoSave + * + * Automatically saves RAM/state when returning from in-game to the menu + ***************************************************************************/ void AutoSave() { if (GCSettings.AutoSave == 1) @@ -482,6 +542,12 @@ void AutoSave() } } +/**************************************************************************** + * OnScreenKeyboard + * + * Opens an on-screen keyboard window, with the data entered being stored + * into the specified variable. + ***************************************************************************/ static void OnScreenKeyboard(char * var, u16 maxlen) { int save = -1; @@ -556,6 +622,12 @@ static void OnScreenKeyboard(char * var, u16 maxlen) ResumeGui(); } +/**************************************************************************** + * SettingWindow + * + * Opens a new window, with the specified window element appended. Allows + * for a customizable prompted setting. + ***************************************************************************/ static int SettingWindow(const char * title, GuiWindow * w) { @@ -642,7 +714,6 @@ SettingWindow(const char * title, GuiWindow * w) * * THIS MUST NOT BE REMOVED OR DISABLED IN ANY DERIVATIVE WORK ***************************************************************************/ - static void WindowCredits(void * ptr) { if(btnLogo->GetState() != STATE_CLICKED) @@ -774,8 +845,10 @@ static void WindowCredits(void * ptr) /**************************************************************************** * MenuGameSelection + * + * Displays a list of games on the specified load device, and allows the user + * to browse and select from this list. ***************************************************************************/ - static int MenuGameSelection() { #ifdef HW_RVL @@ -924,6 +997,11 @@ static int MenuGameSelection() return menu; } +/**************************************************************************** + * ControllerWindowUpdate + * + * Callback for controller window. Responds to clicks on window elements. + ***************************************************************************/ static void ControllerWindowUpdate(void * ptr, int dir) { GuiButton * b = (GuiButton *)ptr; @@ -941,9 +1019,19 @@ static void ControllerWindowUpdate(void * ptr, int dir) } } +/**************************************************************************** + * ControllerWindowLeftClick / ControllerWindowRightsClick + * + * Callbacks for controller window arrows. Responds arrow clicks. + ***************************************************************************/ static void ControllerWindowLeftClick(void * ptr) { ControllerWindowUpdate(ptr, -1); } static void ControllerWindowRightClick(void * ptr) { ControllerWindowUpdate(ptr, +1); } +/**************************************************************************** + * ControllerWindow + * + * Opens a window to allow the user to select the controller to be used. + ***************************************************************************/ static void ControllerWindow() { GuiWindow * w = new GuiWindow(300,250); @@ -1004,8 +1092,9 @@ static void ControllerWindow() /**************************************************************************** * MenuGame + * + * Menu displayed when returning to the menu from in-game. ***************************************************************************/ - static int MenuGame() { int menu = MENU_NONE; @@ -1349,8 +1438,9 @@ static int MenuGame() /**************************************************************************** * MenuGameSaves + * + * Allows the user to load or save progress. ***************************************************************************/ - static int MenuGameSaves(int action) { int menu = MENU_NONE; @@ -1620,6 +1710,9 @@ static int MenuGameSaves(int action) /**************************************************************************** * MenuGameCheats + * + * Displays a list of cheats available, and allows the user to enable/disable + * them. ***************************************************************************/ /* static int MenuGameCheats() @@ -1946,7 +2039,6 @@ static int MenuSettings() /**************************************************************************** * MenuSettingsMappings ***************************************************************************/ - static int MenuSettingsMappings() { int menu = MENU_NONE; @@ -2221,7 +2313,6 @@ static int MenuSettingsMappingsController() /**************************************************************************** * ButtonMappingWindow ***************************************************************************/ - static u32 ButtonMappingWindow() { @@ -2469,7 +2560,6 @@ static int MenuSettingsMappingsMap() /**************************************************************************** * MenuSettingsVideo ***************************************************************************/ - static void ScreenZoomWindowUpdate(void * ptr, float amount) { GuiButton * b = (GuiButton *)ptr; diff --git a/source/ngc/networkop.cpp b/source/ngc/networkop.cpp index b417ed3..d95341d 100644 --- a/source/ngc/networkop.cpp +++ b/source/ngc/networkop.cpp @@ -18,7 +18,6 @@ #include "unzip.h" #include "miniunz.h" - #include "fceugx.h" #include "menu.h" #include "fileop.h" @@ -83,8 +82,8 @@ void UpdateCheck() verMinor >= 0 && verMinor <= 9 && verPoint >= 0 && verPoint <= 9) && (verMajor > curMajor || - verMinor > curMinor || - verPoint > curPoint)) + (verMajor == curMajor && verMinor > curMinor) || + (verMajor == curMajor && verMinor == curMinor && verPoint > curPoint))) { item = mxmlFindElement(xml, xml, "file", NULL, NULL, MXML_DESCEND); if(item)