From 3f03d92295f7b2b51d5d3255bfbbbb0b8fbefb53 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Sat, 18 Dec 2010 13:20:45 +0000 Subject: [PATCH] *Reworked all update functions *Fixed endless loop when disc button was selected *Fixed crash on exit *Fixed discart download to not download custom/originals if set so in the settings *Hopefully fixed discart download problem *Reworked DirList class --- data/app_booter.dol | Bin 105856 -> 106048 bytes source/FileOperations/DirList.cpp | 213 +++---- source/FileOperations/DirList.h | 62 +- source/gecko.c | 2 +- source/language/UpdateLanguage.cpp | 146 +++-- source/language/UpdateLanguage.h | 3 +- source/menu.cpp | 4 - source/menu/GameBrowseMenu.cpp | 137 +++-- source/menu/GameBrowseMenu.hpp | 7 +- source/network/CoverDownload.cpp | 36 +- source/network/FileDownloader.cpp | 9 + source/network/networkops.cpp | 30 +- source/network/update.cpp | 179 ++++++ source/network/update.h | 1 + source/prompts/PromptWindows.cpp | 707 ----------------------- source/prompts/PromptWindows.h | 1 - source/settings/SettingsPrompts.cpp | 54 +- source/settings/menus/GlobalSettings.cpp | 3 +- source/sys.cpp | 9 +- source/utils/StringTools.c | 28 +- source/utils/StringTools.h | 1 + 21 files changed, 583 insertions(+), 1049 deletions(-) diff --git a/data/app_booter.dol b/data/app_booter.dol index a2a2e52d2cd7143a732f43ac961555a083a4d5d6..62c156fe91698e4e5ec274cceade27c4206e24e6 100644 GIT binary patch delta 7871 zcmbVReOQ#$w%_aJqv7+6p3z1eaR$-&mK60J24Pgv(Lp6eK~tH46vB@&4M&@C-T^X9 zw84$OS_6`zhjWgnsL=x^5}r6+z0nPe3d>|VS!r2~VdXiI?_GNsyWQtG|J=*-tXX^S z-`Z=hz4qE`@BJd24esg)c1CmC^kQ8F#MK$1p`z~7@pY+T94m~idnt))P}f~qzUb=q z3=<)yVnX5q2+>!Pj0_Xin2HINWav@FY)8gSRQ2dzTuoHT9RUw*=b|UMOuBQf5_`w>+^jAd zV?Q_A?8t1qraLD|_TAU@d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`PO#}8MaSlABPjrg;CevP` zbcNO@@};Xts!w-{W^ALr@@0?ND=^PHT(u(xd3Ru#eAVCuGc+m`^PSde^6!3n=e)@8UIcf9sx5JU$m z90!x_Ja9S0p>{`bki9&?g1-EAwp3dJ$r1cpk`Cc4A#}zC@0k*KEhxG<6bFm{P6`Uf zJ`?+Vzj>gvV-<{scchk8@F`rA>TECt%#zOrBSJH{eM|50#gh6d7!sNusAfyTQ!ql8 zf!_c!(AoJnXLaBpfTj0Xd7tIuVmo4pM6=7~wsyYAs|!*f9gQW$A7FM#^6YNioOthlUVU-)LojcrZ5b z(|z=&RJ#sl4aV*6#TobgVZiC)0SA{Q%F?@IjHE6DjRGHgHtC%TuzC-d!5@Q)9$-3q z4pJTxK1c1dkqVKPBH56fNZXMlq`gS5BE62}Wjg%!rd!{}bQ^XfHDkFKdBVN!u{;gQ zR;|-${x{aA>&@SYQDLA}?!D;_P#yB6NTo;)NmUL{WZPsp%`MBRJ$;;)IgLDxZQ6ft zyNBK5sdlNc9OlM5{)xjfG3{l1eYcnLAu{dfN~Zm+fN3wCL0ZcHBWjYCZi2_gw8`?q z8%V84*hjGfN!3>`Zo)EeLz#b3BQJaJZo+dspiY)oHOul-vB=TJs-sAUrAZ=8?3Z|N zW%|0m=HgxEdpkwETf^$|35mHN_qt6|K_yI>hX2XZ{r~A+PfR;IPr6bG&qKPmbTdrr z7q+XD>2?<&ovzj;pfiXL?hIw#Cw755$SE+L#K{yOGjdMo7=A)UiIX)zOObOzNAZ&# zIVUkdTaj~e1*i@=r-lF>Le8nNkK&{zEO2TG&}rnHS~(qm0jxp0_u@GzFO{@=@#d^B yOIdqi&|t!Jd(f^Mxu4L!=nl{UsdO*Q45_)xbTxOSGkal4q|;6)Au|5)h5B!^S?JvW diff --git a/source/FileOperations/DirList.cpp b/source/FileOperations/DirList.cpp index 779d3f15..d18bbd00 100644 --- a/source/FileOperations/DirList.cpp +++ b/source/FileOperations/DirList.cpp @@ -27,17 +27,16 @@ #include #include #include +#include +#include #include #include "utils/StringTools.h" #include "DirList.h" -DirList::DirList(const char * path, const char *filter) +DirList::DirList(const char * path, const char *filter, u32 flags) { - filecount = 0; - FileInfo = NULL; - - this->LoadPath(path, filter); + this->LoadPath(path, filter, flags); this->SortList(); } @@ -46,185 +45,145 @@ DirList::~DirList() ClearList(); } -bool DirList::LoadPath(const char * folder, const char *filter) +bool DirList::LoadPath(const char * folder, const char *filter, u32 flags) { + if(!folder) + return false; + struct stat st; DIR_ITER *dir = NULL; - char filename[1024]; + std::string folderpath = folder; - char folderpath[strlen(folder)+2]; - sprintf(folderpath, "%s", folder); + if(folderpath[folderpath.size()-1] == '/') + folderpath[folderpath.size()-1] = '\0'; - if(folderpath[strlen(folderpath)-1] == '/') - folderpath[strlen(folderpath)-1] = '\0'; - - char * notRoot = strrchr(folderpath, '/'); + const char * notRoot = strrchr(folderpath.c_str(), '/'); if(!notRoot) - { - strcat(folderpath, "/"); - } + folderpath += '/'; - dir = diropen(folderpath); + dir = diropen(folderpath.c_str()); if (dir == NULL) return false; + char * filename = new (std::nothrow) char[1024]; + if(!filename) + { + dirclose(dir); + return false; + } + while (dirnext(dir,filename,&st) == 0) { - if (strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) + if(st.st_mode & S_IFDIR) { - if(filter) + if(!(flags & Dirs)) + continue; + + if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) + continue; + + if(flags & CheckSubfolders) { - char * fileext = strrchr(filename, '.'); - if(fileext) - { - if(strtokcmp(fileext, filter, ",") == 0) - { - bool result = AddEntrie(folderpath, filename, st.st_size, (st.st_mode & S_IFDIR) ? true : false); - if(!result) - { - dirclose(dir); - return false; - } - } - } - } - else - { - bool result = AddEntrie(folderpath, filename, st.st_size, (st.st_mode & S_IFDIR) ? true : false); - if(!result) - { - dirclose(dir); - return false; - } + std::string newFolder = folderpath; + if(notRoot) newFolder += '/'; + newFolder += filename; + LoadPath(newFolder.c_str(), filter, flags); } } + else + { + if(!(flags & Files)) + continue; + } + + if(filter) + { + char * fileext = strrchr(filename, '.'); + if(!fileext) + continue; + + if(strtokcmp(fileext, filter, ",") == 0) + AddEntrie(folderpath.c_str(), filename, st.st_size, (st.st_mode & S_IFDIR) ? true : false); + } + else + { + AddEntrie(folderpath.c_str(), filename, st.st_size, (st.st_mode & S_IFDIR) ? true : false); + } } dirclose(dir); + delete [] filename; return true; } -bool DirList::AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir) +void DirList::AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir) { - if(!FileInfo) - { - FileInfo = (FileInfos *) malloc(sizeof(FileInfos)); - if (!FileInfo) - return false; - } + if(!folderpath || !filename) + return; - FileInfos *TempFileInfo = (FileInfos *) realloc(FileInfo, (filecount+1)*sizeof(FileInfos)); + int pos = FileInfo.size(); - if (!TempFileInfo) - { - ClearList(); - filecount = 0; - return false; - } + FileInfo.resize(pos+1); - FileInfo = TempFileInfo; - - memset(&(FileInfo[filecount]), 0, sizeof(FileInfo)); - - FileInfo[filecount].FilePath = strdup(folderpath); - FileInfo[filecount].FileName = strdup(filename); - FileInfo[filecount].FileSize = filesize; - FileInfo[filecount].isDir = isDir; - - if (!FileInfo[filecount].FilePath || !FileInfo[filecount].FileName) - { - ClearList(); - filecount = 0; - return false; - } - - filecount++; - - return true; + FileInfo[pos].FilePath = new (std::nothrow) char[strlen(folderpath)+strlen(filename)+1]; + if(FileInfo[pos].FilePath) + sprintf(FileInfo[pos].FilePath, "%s/%s", folderpath, filename); + FileInfo[pos].FileSize = filesize; + FileInfo[pos].isDir = isDir; } void DirList::ClearList() { - for(int i = 0; i < filecount; i++) + for(u32 i = 0; i < FileInfo.size(); ++i) { if(FileInfo[i].FilePath) - { - free(FileInfo[i].FilePath); - FileInfo[i].FilePath = NULL; - } - if(FileInfo[i].FileName) - { - free(FileInfo[i].FileName); - FileInfo[i].FileName = NULL; - } + delete [] FileInfo[i].FilePath; } - if (FileInfo) - { - free(FileInfo); - FileInfo = NULL; - } + FileInfo.clear(); + std::vector().swap(FileInfo); } -char *DirList::GetFilename(int ind) +const char * DirList::GetFilename(int ind) { - if (ind >= filecount || ind < 0) + if (!valid(ind)) return NULL; - else - return FileInfo[ind].FileName; + + return FullpathToFilename(FileInfo[ind].FilePath); } -char *DirList::GetFilepath(int ind) +static bool SortCallback(const FileInfos & f1, const FileInfos & f2) { - if (ind >= filecount || ind < 0) - return NULL; - else - return FileInfo[ind].FilePath; -} + if(f1.isDir && !(f2.isDir)) return true; + if(!(f1.isDir) && f2.isDir) return false; -unsigned int DirList::GetFilesize(int ind) -{ - if (ind >= filecount || !filecount || !FileInfo) - return 0; - else - return FileInfo[ind].FileSize; -} + const char * Filename1 = FullpathToFilename(f1.FilePath); + const char * Filename2 = FullpathToFilename(f2.FilePath); -bool DirList::IsDir(int ind) -{ - if (ind >= filecount || !filecount || !FileInfo) + if(Filename1 && !Filename2) return true; + if(!Filename1 && Filename2) return false; + + if(strcasecmp(Filename1, Filename2) > 0) return false; - else - return FileInfo[ind].isDir; -} -static int ListCompare(const void *a, const void *b) -{ - FileInfos *ab = (FileInfos*) a; - FileInfos *bb = (FileInfos*) b; - - return stricmp((char *) ab->FileName, (char *) bb->FileName); + return true; } void DirList::SortList() { - if(!FileInfo) - return; - - qsort(FileInfo, filecount, sizeof(FileInfos), ListCompare); + std::sort(FileInfo.begin(), FileInfo.end(), SortCallback); } int DirList::GetFileIndex(const char *filename) { - if(!filename || !FileInfo) + if(!filename) return -1; - for (int i = 0; i < filecount; i++) + for (u32 i = 0; i < FileInfo.size(); ++i) { - if (strcasecmp(FileInfo[i].FileName, filename) == 0) - { + if (strcasecmp(GetFilename(i), filename) == 0) return i; - } } + return -1; } diff --git a/source/FileOperations/DirList.h b/source/FileOperations/DirList.h index e388c487..5d2c6d08 100644 --- a/source/FileOperations/DirList.h +++ b/source/FileOperations/DirList.h @@ -1,18 +1,40 @@ /**************************************************************************** + * Copyright (C) 2010 + * by Dimok + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any + * purpose, including commercial applications, and to alter it and + * redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you + * must not claim that you wrote the original software. If you use + * this software in a product, an acknowledgment in the product + * documentation would be appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and + * must not be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. + * * DirList Class - * for WiiXplorer + * for WiiXplorer 2010 ***************************************************************************/ #ifndef ___DIRLIST_H_ #define ___DIRLIST_H_ +#include #include typedef struct { - char *FileName; - char *FilePath; - u64 FileSize; - bool isDir; + char * FilePath; + u64 FileSize; + bool isDir; } FileInfos; class DirList @@ -21,38 +43,46 @@ class DirList //!Constructor //!\param path Path from where to load the filelist of all files //!\param filter A fileext that needs to be filtered - DirList(const char * path, const char *filter = NULL); + //!\param flags search/filter flags from the enum + DirList(const char * path, const char *filter = NULL, u32 flags = Files | Dirs); //!Destructor ~DirList(); //! Load all the files from a directory - //!\param path Path where to check for homebrew files - bool LoadPath(const char * path, const char *filter = NULL); + bool LoadPath(const char * path, const char *filter = NULL, u32 flags = Files | Dirs); //! Get a filename of the list //!\param list index - char * GetFilename(int index); + const char * GetFilename(int index); //! Get the a filepath of the list //!\param list index - char * GetFilepath(int index); + const char * GetFilepath(int index) { if(!valid(index)) return NULL; return FileInfo[index].FilePath; }; //! Get the a filesize of the list //!\param list index - unsigned int GetFilesize(int index); + u64 GetFilesize(int index) { if(!valid(index)) return 0; return FileInfo[index].FileSize; }; //! Is index a dir or a file //!\param list index - bool IsDir(int index); + bool IsDir(int index) { if(!valid(index)) return 0; return FileInfo[index].isDir; }; //! Get the filecount of the whole list - int GetFilecount() { return filecount; }; + int GetFilecount() { return FileInfo.size(); }; //! Sort list by filepath void SortList(); //! Get the index of the specified filename int GetFileIndex(const char *filename); + //! Enum for search/filter flags + enum + { + Files = 0x01, + Dirs = 0x02, + CheckSubfolders = 0x08, + }; protected: //!Add a list entrie - bool AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir); + void AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir); //! Clear the list void ClearList(); + //! Check if valid pos is requested + inline bool valid(int pos) { return (pos >= 0 && pos < (int) FileInfo.size()); }; - int filecount; - FileInfos *FileInfo; + std::vector FileInfo; }; #endif diff --git a/source/gecko.c b/source/gecko.c index 06a1e15a..21bbf356 100644 --- a/source/gecko.c +++ b/source/gecko.c @@ -21,7 +21,7 @@ void gprintf(const char *format, ...) if((vasprintf(&tmp, format, va) >= 0) && tmp) { u32 level = IRQ_Disable(); - usb_sendbuffer_safe(1, tmp, strlen(tmp)); + usb_sendbuffer(1, tmp, strlen(tmp)); IRQ_Restore(level); } va_end(va); diff --git a/source/language/UpdateLanguage.cpp b/source/language/UpdateLanguage.cpp index 97fefb69..289bc563 100644 --- a/source/language/UpdateLanguage.cpp +++ b/source/language/UpdateLanguage.cpp @@ -8,69 +8,131 @@ #include #include "UpdateLanguage.h" +#include "gettext.h" #include "FileOperations/fileops.h" #include "FileOperations/DirList.h" #include "menu.h" #include "network/networkops.h" #include "network/http.h" +#include "network/URL_List.h" +#include "prompts/ProgressWindow.h" +#include "utils/ShowError.h" +#include "gecko.h" -int updateLanguageFiles() +static const char * LanguageFilesURL = "http://usbloader-gui.googlecode.com/svn/trunk/Languages/"; + +int DownloadAllLanguageFiles() { - char languageFiles[50][MAXLANGUAGEFILES]; + if(!CreateSubfolder(Settings.languagefiles_path)) + { + ShowError(tr("Could not create path: %s"), Settings.languagefiles_path); + return -1; + } - DirList Dir(Settings.languagefiles_path); + if(!IsNetworkInit()) + { + ShowError(tr("Network is not initiated.")); + return -2; + } + char fullURL[300]; + + URL_List LinkList(LanguageFilesURL); + int listsize = LinkList.GetURLCount(); + int files_downloaded = 0; + + ShowProgress(tr("Updating Language Files:"), 0, 0, 0, listsize, false, true); + + for (int i = 0; i < listsize; i++) + { + const char * filename = strrchr(LinkList.GetURL(i), '/'); + if(filename) filename++; + else filename = LinkList.GetURL(i); + + if(!filename) + continue; + + const char * FileExt = strrchr(filename, '.'); + if (!FileExt || strcasecmp(FileExt, ".lang") != 0) + continue; + + gprintf("%s\n", filename); + + ShowProgress(tr("Updating Language Files:"), 0, filename, i, listsize, false, true); + + snprintf(fullURL, sizeof(fullURL), "%s%s", LanguageFilesURL, filename); + + struct block file = downloadfile(fullURL); + if (file.data) + { + char filepath[300]; + snprintf(filepath, sizeof(filepath), "%s/%s", Settings.languagefiles_path, filename); + FILE * pfile = fopen(filepath, "wb"); + if(pfile) + { + fwrite(file.data, 1, file.size, pfile); + fclose(pfile); + files_downloaded++; + } + free(file.data); + } + } + + ProgressStop(); + + return files_downloaded; +} + +int UpdateLanguageFiles() +{ + if(!CreateSubfolder(Settings.languagefiles_path)) + { + ShowError(tr("Could not create path: %s"), Settings.languagefiles_path); + return -1; + } + + if(!IsNetworkInit()) + { + ShowError(tr("Network is not initiated.")); + return -2; + } + + DirList Dir(Settings.languagefiles_path, ".lang"); //give up now if we didn't find any if (Dir.GetFilecount() == 0) return -2; - //now from the files we got, get only the .lang files - for (int cnt = 0; cnt < Dir.GetFilecount(); cnt++) - { - char filename[64]; - strlcpy(filename, Dir.GetFilename(cnt), sizeof(filename)); - if (strcasestr(filename, ".lang")) - { - strcpy(languageFiles[cnt], filename); - } - } - - CreateSubfolder(Settings.languagefiles_path); + char savepath[150]; + char codeurl[200]; //we assume that the network will already be init by another function // ( that has gui eletents in it because this one doesn't) - int done = 0, j = 0; - if (IsNetworkInit()) + int done = 0; + + //build the URL, save path, and download each file and save it + for(int i = 0; i < Dir.GetFilecount(); ++i) { - //build the URL, save path, and download each file and save it - while (j < Dir.GetFilecount()) + snprintf(codeurl, sizeof(codeurl), "%s%s", LanguageFilesURL, Dir.GetFilename(i)); + snprintf(savepath, sizeof(savepath), "%s/%s", Settings.languagefiles_path, Dir.GetFilename(i)); + + struct block file = downloadfile(codeurl); + + ShowProgress(tr("Updating Language Files:"), 0, Dir.GetFilename(i), i, Dir.GetFilecount(), false, true); + + if (file.data != NULL) { - char savepath[150]; - char codeurl[200]; - snprintf(codeurl, sizeof(codeurl), "http://usbloader-gui.googlecode.com/svn/trunk/Languages/%s", - languageFiles[j]); - snprintf(savepath, sizeof(savepath), "%s/%s", Settings.languagefiles_path, languageFiles[j]); - - struct block file = downloadfile(codeurl); - - if (file.data != NULL) + FILE * pfile; + pfile = fopen(savepath, "wb"); + if (pfile != NULL) { - FILE * pfile; - pfile = fopen(savepath, "wb"); - if (pfile != NULL) - { - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - free(file.data); - done++; - } + fwrite(file.data, 1, file.size, pfile); + fclose(pfile); + done++; } - - j++; + free(file.data); } - } - //if there was no network init - else return -1; + + ProgressStop(); // return the number of files we updated return done; diff --git a/source/language/UpdateLanguage.h b/source/language/UpdateLanguage.h index cef09ef3..6e80e34a 100644 --- a/source/language/UpdateLanguage.h +++ b/source/language/UpdateLanguage.h @@ -13,6 +13,7 @@ //! returns the number of files successfully updated //! returns -2 if it can't find any .lang files in the path //! return -1 if there is no network connection -int updateLanguageFiles(); +int UpdateLanguageFiles(); +int DownloadAllLanguageFiles(); #endif diff --git a/source/menu.cpp b/source/menu.cpp index 470c0b22..42544ba2 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -54,10 +54,6 @@ char game_partition[6]; int load_from_fs; /*** Variables used only in the menus ***/ -GuiText * GameIDTxt = NULL; -GuiText * GameRegionTxt = NULL; -GuiImage * coverImg = NULL; -GuiImageData * cover = NULL; bool altdoldefault = true; static lwp_t guithread = LWP_THREAD_NULL; diff --git a/source/menu/GameBrowseMenu.cpp b/source/menu/GameBrowseMenu.cpp index d961dfef..23c34d20 100644 --- a/source/menu/GameBrowseMenu.cpp +++ b/source/menu/GameBrowseMenu.cpp @@ -9,6 +9,7 @@ #include "usbloader/wdvd.h" #include "usbloader/GameList.h" #include "network/networkops.h" +#include "network/update.h" #include "network/CoverDownload.h" #include "FileOperations/fileops.h" #include "settings/Settings.h" @@ -39,7 +40,9 @@ GameBrowseMenu::GameBrowseMenu() : GuiWindow(screenwidth, screenheight) { float freespace = 0.0, used = 0.0; + returnMenu = MENU_NONE; gameSelectedOld = -1; + lastrawtime = 0; show_searchwindow = false; gameBrowser = NULL; gameGrid = NULL; @@ -50,7 +53,6 @@ GameBrowseMenu::GameBrowseMenu() GameIDTxt = NULL; GameRegionTxt = NULL; ScreensaverTimer = 0; - memset(theTime, 0, sizeof(theTime)); WDVD_GetCoverStatus(&DiscDriveCoverOld); wString oldFilter(gameList.GetCurrentFilter()); gameList.FilterList(oldFilter.c_str()); @@ -265,7 +267,7 @@ GameBrowseMenu::GameBrowseMenu() dvdBtnTT->SetAlpha(Theme.tooltipAlpha); dvdBtnImg = new GuiImage(imgdvd); dvdBtnImg->SetWidescreen(Settings.widescreen); - dvdBtnImg_g = new GuiImage(dvdBtnImg); + dvdBtnImg_g = new GuiImage(imgdvd_gray); dvdBtnImg_g->SetWidescreen(Settings.widescreen); dvdBtn = new GuiButton(dvdBtnImg_g, dvdBtnImg_g, ALIGN_LEFT, ALIGN_TOP, Theme.gamelist_dvd_x, Theme.gamelist_dvd_y, trigA, btnSoundOver, btnSoundClick2, 1, dvdBtnTT, 15, 52, 1, 3); @@ -299,7 +301,7 @@ GameBrowseMenu::GameBrowseMenu() clockTimeBack->SetPosition(Theme.clock_x, Theme.clock_y); clockTimeBack->SetFont(clock_ttf, clock_ttf_size); - clockTime = new GuiText(theTime, 40, Theme.clock); + clockTime = new GuiText("", 40, Theme.clock); clockTime->SetAlignment(Theme.clock_align, ALIGN_TOP); clockTime->SetPosition(Theme.clock_x, Theme.clock_y); clockTime->SetFont(clock_ttf, clock_ttf_size); @@ -488,6 +490,11 @@ void GameBrowseMenu::ReloadBrowser() sortBtnTT->SetText(sortTTText); sortBtnImg->SetImage(sortImgData); + if(DiscDriveCoverOld & 0x02) + dvdBtn->SetImage(dvdBtnImg); + else + dvdBtn->SetImage(dvdBtnImg_g); + if (Settings.GameSort & SORT_FAVORITE) { favoriteBtn->SetImage(favoriteBtnImg); @@ -707,39 +714,14 @@ int GameBrowseMenu::Show() int GameBrowseMenu::MainLoop() { - WDVD_GetCoverStatus(&DiscDriveCover);//for detecting if i disc has been inserted - - //CLOCK - if (Settings.hddinfo == CLOCK_HR12 || Settings.hddinfo == CLOCK_HR24) - { - time_t rawtime = time(0); - if(rawtime != lastrawtime) - { - lastrawtime = rawtime; - struct tm * timeinfo = localtime(&rawtime); - if (Settings.hddinfo == CLOCK_HR12) - { - if (rawtime & 1) - strftime(theTime, sizeof(theTime), "%I:%M", timeinfo); - else - strftime(theTime, sizeof(theTime), "%I %M", timeinfo); - } - if (Settings.hddinfo == CLOCK_HR24) - { - if (rawtime & 1) - strftime(theTime, sizeof(theTime), "%H:%M", timeinfo); - else - strftime(theTime, sizeof(theTime), "%H %M", timeinfo); - } - clockTime->SetText(theTime); - } - } + UpdateClock(); + CheckDiscSlotUpdate(); if (updateavailable == true) { gprintf("\tUpdate Available\n"); SetState(STATE_DISABLED); - ProgressUpdateWindow(); + UpdateApp(); updateavailable = false; SetState(STATE_DEFAULT); } @@ -791,16 +773,6 @@ int GameBrowseMenu::MainLoop() installBtn->ResetState(); } - else if ((DiscDriveCover & 0x02) && (DiscDriveCover != DiscDriveCoverOld)) - { - gprintf("\tNew Disc Detected\n"); - int choice = WindowPrompt(tr( "New Disc Detected" ), 0, tr( "Install" ), tr( "Mount DVD drive" ), tr( "Cancel" )); - if (choice == 1) - return MENU_INSTALL; - else if (choice == 2) - dvdBtn->SetState(STATE_CLICKED); - } - else if (sdcardBtn->GetState() == STATE_CLICKED) { gprintf("\tsdCardBtn Clicked\n"); @@ -1013,16 +985,6 @@ int GameBrowseMenu::MainLoop() WindowPrompt(tr( "Parental Control" ), tr( "Invalid PIN code" ), tr( "OK" )); } } - else if (dvdBtn->GetState() == STATE_CLICKED) - { - gprintf("\tdvdBtn Clicked\n"); - if(!dvdheader) - dvdheader = new struct discHdr; - mountMethod = DiscMount(dvdheader); - dvdBtn->ResetState(); - - rockout(GetSelectedGame()); - } else if (Settings.gameDisplay == LIST_MODE && idBtn->GetState() == STATE_CLICKED) { @@ -1043,7 +1005,7 @@ int GameBrowseMenu::MainLoop() idBtn->ResetState(); } - if (Settings.gameDisplay == LIST_MODE && GetSelectedGame() != gameSelectedOld) + else if (Settings.gameDisplay == LIST_MODE && GetSelectedGame() != gameSelectedOld) { gameSelectedOld = GetSelectedGame(); int gameSelected = gameSelectedOld; @@ -1072,9 +1034,74 @@ int GameBrowseMenu::MainLoop() else ScreensaverTimer = 0; - DiscDriveCoverOld = DiscDriveCover; + return returnMenu; +} - return MENU_NONE; +void GameBrowseMenu::CheckDiscSlotUpdate() +{ + u32 DiscDriveCover; + WDVD_GetCoverStatus(&DiscDriveCover);//for detecting if i disc has been inserted + + if ((DiscDriveCover & 0x02) && (DiscDriveCover != DiscDriveCoverOld)) + { + gprintf("\tNew Disc Detected\n"); + int choice = WindowPrompt(tr( "New Disc Detected" ), 0, tr( "Install" ), tr( "Mount DVD drive" ), tr( "Cancel" )); + if (choice == 1) + returnMenu = MENU_INSTALL; + else if (choice == 2) + dvdBtn->SetState(STATE_CLICKED); + } + else if (dvdBtn->GetState() == STATE_CLICKED) + { + gprintf("\tdvdBtn Clicked\n"); + if(!dvdheader) + dvdheader = new struct discHdr; + mountMethod = DiscMount(dvdheader); + dvdBtn->ResetState(); + + rockout(GetSelectedGame()); + } + + if(DiscDriveCoverOld != DiscDriveCover) + { + if(DiscDriveCover & 0x02) + dvdBtn->SetImage(dvdBtnImg); + else + dvdBtn->SetImage(dvdBtnImg_g); + + DiscDriveCoverOld = DiscDriveCover; + } +} + +void GameBrowseMenu::UpdateClock() +{ + if(Settings.hddinfo != CLOCK_HR12 && Settings.hddinfo != CLOCK_HR24) + return; + + time_t rawtime = time(0); + if(rawtime == lastrawtime) //! Only update every 1 second + return; + + char theTime[50]; + theTime[0] = 0; + + lastrawtime = rawtime; + struct tm * timeinfo = localtime(&rawtime); + if (Settings.hddinfo == CLOCK_HR12) + { + if (rawtime & 1) + strftime(theTime, sizeof(theTime), "%I:%M", timeinfo); + else + strftime(theTime, sizeof(theTime), "%I %M", timeinfo); + } + if (Settings.hddinfo == CLOCK_HR24) + { + if (rawtime & 1) + strftime(theTime, sizeof(theTime), "%H:%M", timeinfo); + else + strftime(theTime, sizeof(theTime), "%H %M", timeinfo); + } + clockTime->SetText(theTime); } int GameBrowseMenu::GetSelectedGame() @@ -1263,6 +1290,8 @@ int GameBrowseMenu::OpenClickedGame() returnHere = true; } + mountMethod = 0; + if (searchBar) { HaltGui(); diff --git a/source/menu/GameBrowseMenu.hpp b/source/menu/GameBrowseMenu.hpp index f40e0b9d..c1539138 100644 --- a/source/menu/GameBrowseMenu.hpp +++ b/source/menu/GameBrowseMenu.hpp @@ -23,6 +23,8 @@ class GameBrowseMenu : public GuiWindow void LoadCover(struct discHdr *header); void CheckAlternativeDOL(const char * IDfull); void CheckOcarina(const char * IDfull); + void CheckDiscSlotUpdate(); + void UpdateClock(); static void UpdateCallback(void * e); GuiImageData * btnInstall; @@ -98,6 +100,8 @@ class GameBrowseMenu : public GuiWindow GuiText * gamecntTxt; GuiText * clockTimeBack; GuiText * clockTime; + GuiText * GameRegionTxt; + GuiText * GameIDTxt; GuiButton * gamecntBtn; GuiButton * installBtn; @@ -139,9 +143,8 @@ class GameBrowseMenu : public GuiWindow GuiGameGrid * gameGrid; GuiGameCarousel * gameCarousel; GuiSearchBar * searchBar; - char theTime[50]; - u32 DiscDriveCover; u32 DiscDriveCoverOld; + int returnMenu; int gameSelectedOld; int gameClicked; time_t lastrawtime; diff --git a/source/network/CoverDownload.cpp b/source/network/CoverDownload.cpp index 47ae8c55..9d0c0a5d 100644 --- a/source/network/CoverDownload.cpp +++ b/source/network/CoverDownload.cpp @@ -24,7 +24,7 @@ static void AbortCallback(void) AbortRequested = true; } -static int CoverDownloadWithProgress(const char * url, const char * writepath, std::vector & MissingFilesList) +static int CoverDownloadWithProgress(const char * url, const char * progressTitle, const char * writepath, std::vector & MissingFilesList) { if(!url || !writepath) return -1; @@ -38,7 +38,7 @@ static int CoverDownloadWithProgress(const char * url, const char * writepath, s char downloadURL[512]; char progressMsg[255]; int FilesSkipped = MissingFilesList.size(); - ProgressSetAbortCallback((ProgressAbortCallback) AbortCallback); + ProgressSetAbortCallback(AbortCallback); for(u32 i = 0; i < MissingFilesList.size(); ++i) { @@ -47,9 +47,9 @@ static int CoverDownloadWithProgress(const char * url, const char * writepath, s snprintf(progressMsg, sizeof(progressMsg), "http://wiitdb.com : %s.png", MissingFilesList[i].c_str()); - ShowProgress(tr("Downloading files"), fmt("%i %s", MissingFilesList.size() - i, tr( "files left" )), progressMsg, i, MissingFilesList.size()); + ShowProgress(progressTitle, fmt("%i %s", MissingFilesList.size() - i, tr( "files left" )), progressMsg, i, MissingFilesList.size()); - if(MissingFilesList[i].size() < 6) + if(MissingFilesList[i].size() < 4) continue; //Creates URL depending from which Country the game is @@ -98,7 +98,7 @@ static int CoverDownloadWithProgress(const char * url, const char * writepath, s } char imgPath[200]; - snprintf(imgPath, sizeof(imgPath), "%s%s.png", writepath, MissingFilesList[i].c_str()); + snprintf(imgPath, sizeof(imgPath), "%s/%s.png", writepath, MissingFilesList[i].c_str()); FILE *pfile = fopen(imgPath, "wb"); if (pfile != NULL) @@ -125,6 +125,13 @@ void CoverDownload() return; const char * writepath = choice == 1 ? Settings.covers_path : choice == 2 ? Settings.covers2d_path : Settings.disc_path; + const char * downloadURL = choice == 1 ? serverURL3D : choice == 2 ? serverURL2D : NULL; + const char * progressTitle = choice != 3 ? tr("Downloading covers") : NULL; + if(choice == 3) + { + downloadURL = (Settings.discart == 0 || Settings.discart == 2) ? serverURLOrigDiscs : serverURLCustomDiscs; + progressTitle = (Settings.discart == 0 || Settings.discart == 2) ? tr("Downloading original Discarts") : tr("Downloading custom Discarts"); + } std::vector MissingFilesList; GetMissingGameFiles(writepath, ".png", MissingFilesList); @@ -148,24 +155,23 @@ void CoverDownload() AbortRequested = false; - const char * downloadURL = choice == 1 ? serverURL3D : choice == 2 ? serverURL2D : NULL; + int FileSkipped = CoverDownloadWithProgress(downloadURL, progressTitle, writepath, MissingFilesList); - if(choice == 3) - { - downloadURL = (Settings.discart == 0 || Settings.discart == 2) ? serverURLOrigDiscs : serverURLCustomDiscs; - } - - int FileSkipped = CoverDownloadWithProgress(downloadURL, writepath, MissingFilesList); - - if(choice == 3 && FileSkipped > 0) + if(choice == 3 && FileSkipped > 0 && Settings.discart > 1) { if(downloadURL == serverURLOrigDiscs) + { + progressTitle = tr("Trying custom Discarts"); downloadURL = serverURLCustomDiscs; + } else + { + progressTitle = tr("Trying original Discarts"); downloadURL = serverURLOrigDiscs; + } GetMissingGameFiles(writepath, ".png", MissingFilesList); - FileSkipped = CoverDownloadWithProgress(downloadURL, writepath, MissingFilesList); + FileSkipped = CoverDownloadWithProgress(downloadURL, progressTitle, writepath, MissingFilesList); } if (FileSkipped == 0) diff --git a/source/network/FileDownloader.cpp b/source/network/FileDownloader.cpp index de7d52a6..5ea50f95 100644 --- a/source/network/FileDownloader.cpp +++ b/source/network/FileDownloader.cpp @@ -234,6 +234,15 @@ int DownloadFileToPath(const char *orig_url, const char *dest, bool UseFilename) strcat((char *) dest, filename); } + if(!UseFilename && strcmp(filename, "") == 0) + { + const char * ptr = strrchr(dest, '/'); + if(ptr) ptr++; + else ptr = dest; + + snprintf(filename, sizeof(filename), "%s", ptr); + } + FILE *file = fopen(dest, "wb"); if(!file) { diff --git a/source/network/networkops.cpp b/source/network/networkops.cpp index 7bd93e26..fe80eb08 100644 --- a/source/network/networkops.cpp +++ b/source/network/networkops.cpp @@ -370,38 +370,28 @@ int NetworkWait() ***************************************************************************/ int CheckUpdate() { - if (!networkinitialized) return -1; + if (!networkinitialized) + return -1; int revnumber = 0; int currentrev = atoi(GetRev()); - if (Settings.beta_upgrades) - { - revnumber = CheckForBetaUpdate(); - } - else - { #ifdef FULLCHANNEL - struct block file = downloadfile( "http://www.techjawa.com/usbloadergx/wadrev.txt" ); + struct block file = downloadfile( "http://www.techjawa.com/usbloadergx/wadrev.txt" ); #else - struct block file = downloadfile("http://www.techjawa.com/usbloadergx/rev.txt"); + struct block file = downloadfile("http://www.techjawa.com/usbloadergx/rev.txt"); #endif - char revtxt[10]; - u8 i; - if (file.data != NULL) - { - for (i = 0; i < 9 || i < file.size; i++) - revtxt[i] = file.data[i]; - revtxt[i] = 0; - revnumber = atoi(revtxt); - free(file.data); - } + if (file.data != NULL) + { + revnumber = atoi((char *) file.data); + free(file.data); } if (revnumber > currentrev) return revnumber; - else return -1; + + return -1; } /**************************************************************************** diff --git a/source/network/update.cpp b/source/network/update.cpp index 35a4869b..1f2042b6 100644 --- a/source/network/update.cpp +++ b/source/network/update.cpp @@ -39,6 +39,13 @@ #include "FileDownloader.h" #include "settings/CSettings.h" #include "settings/GameTitles.h" +#include "language/gettext.h" +#include "language/UpdateLanguage.h" +#include "homebrewboot/BootHomebrew.h" +#include "utils/StringTools.h" +#include "utils/ShowError.h" +#include "prompts/PromptWindows.h" +#include "FileOperations/fileops.h" #include "xml/WiiTDB.hpp" static const char * WiiTDB_URL = "http://wiitdb.com/wiitdb.zip"; @@ -154,3 +161,175 @@ int UpdateWiiTDB() return (result ? filesize : -1); } + +static void UpdateIconPng() +{ + char iconpath[200]; + struct block file = downloadfile("http://www.techjawa.com/usbloadergx/icon.png"); + if (file.data != NULL) + { + snprintf(iconpath, sizeof(iconpath), "%sicon.png", Settings.update_path); + FILE * pfile = fopen(iconpath, "wb"); + if(pfile) + { + fwrite(file.data, 1, file.size, pfile); + fclose(pfile); + } + free(file.data); + } +} + +static void UpdateMetaXml() +{ + char xmlpath[200]; + struct block file = downloadfile("http://www.techjawa.com/usbloadergx/meta.file"); + if (file.data != NULL) + { + snprintf(xmlpath, sizeof(xmlpath), "%smeta.xml", Settings.update_path); + FILE *pfile = fopen(xmlpath, "wb"); + if(pfile) + { + fwrite(file.data, 1, file.size, pfile); + fclose(pfile); + } + free(file.data); + } +} + +static int ApplicationDownload(int newrev) +{ + bool update_error = false; + char tmppath[250]; + + #ifdef FULLCHANNEL + const char * DownloadURL = "http://www.techjawa.com/usbloadergx/ULNR.wad"; + snprintf(tmppath, sizeof(tmppath), "%s/ULNR.wad", Settings.BootDevice); + #else + char realpath[250]; + snprintf(realpath, sizeof(realpath), "%sboot.dol", Settings.update_path); + const char * DownloadURL = "http://www.techjawa.com/usbloadergx/boot.dol"; + snprintf(tmppath, sizeof(tmppath), "%sboot.tmp", Settings.update_path); + #endif + + int update_choice = WindowPrompt(fmt("Rev%i %s.", newrev, tr( "available" )), tr( "How do you want to update?" ), tr( "Update DOL" ), tr( "Update All" ), tr( "Cancel" )); + if (update_choice == 0) + return 0; + + int ret = DownloadFileToPath(DownloadURL, tmppath, false); + if(ret < 1024*1024) + { + remove(tmppath); + WindowPrompt(tr("Failed updating"), tr("Error while downloding file"), tr( "OK" )); + if(update_choice == 1) + return -1; + + update_error = true; + } + else + { + #ifdef FULLCHANNEL + FILE * wadFile = fopen(realpath, "rb"); + if(!wadFile) + { + update_error = true; + WindowPrompt(tr("Failed updating"), tr("Error opening downloaded file"), tr( "OK" )); + return -1; + } + + int error = Wad_Install( wadFile ); + if(error) + { + update_error = true; + ShowError(tr( "The wad installation failed with error %i" ), error); + } + else + WindowPrompt(tr( "Success" ), tr( "The wad file was installed" ), tr( "OK" )); + + RemoveFile(realpath); + #else + gprintf("%s\n%s\n", realpath, tmppath); + RemoveFile(realpath); + if(!RenameFile(tmppath, realpath)) + update_error = true; + #endif + } + + if (update_choice == 2) + { + UpdateIconPng(); + UpdateMetaXml(); + UpdateWiiTDB(); + DownloadAllLanguageFiles(); + } + + if(update_error) + { + ShowError(tr( "Error while updating USB Loader GX." )); + return -1; + } + + if (update_choice > 0) + { + WindowPrompt(tr( "Restarting..." ), tr( "Successfully Updated thanks to www.techjawa.com" ), 0, 0, 0, 0, 150); + #ifdef FULLCHANNEL + ExitApp(); + WII_Initialize(); + WII_LaunchTitle(TITLE_ID( 0x00010001, 0x554c4e52 )); + #else + BootHomebrew(realpath); + #endif + } + + return 0; +} + +int UpdateApp() +{ + if (!IsNetworkInit() && !NetworkInitPrompt()) + { + WindowPrompt(tr("Error !"), tr("Could not initialize network!"), tr("OK")); + return -1; + } + + if (!CreateSubfolder(Settings.update_path)) + { + WindowPrompt(tr("Error !"), tr("Can't create directory"), tr("OK")); + return -1; + } + + int choice = WindowPrompt(tr( "What do you want to update?" ), 0, "USB Loader GX", tr( "WiiTDB Files" ), tr( "Language File" ), tr( "Cancel" )); + if(choice == 0) + return -1; + + if(choice == 1) + { + int newrev = CheckUpdate(); + if (newrev < 0) + { + WindowPrompt(tr( "No new updates." ), 0, tr( "OK" )); + return 0; + } + + return ApplicationDownload(newrev); + } + else if (choice == 2) + { + if(UpdateWiiTDB() < 0) + { + WindowPrompt(fmt("%s", tr( "WiiTDB is up to date." )), 0, tr("OK")); + return 1; + } + else + { + WindowPrompt(tr( "Successfully Updated" ), 0, tr( "OK" )); + return 1; + } + } + else if (choice == 3) + { + if(UpdateLanguageFiles() > 0) + WindowPrompt(tr( "Successfully Updated" ), 0, tr( "OK" )); + } + + return 1; +} diff --git a/source/network/update.h b/source/network/update.h index 482f4e79..9caec60a 100644 --- a/source/network/update.h +++ b/source/network/update.h @@ -31,5 +31,6 @@ int CheckForBetaUpdate(); int UpdateWiiTDB(); +int UpdateApp(); #endif diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp index 4f36a545..824a81b7 100644 --- a/source/prompts/PromptWindows.cpp +++ b/source/prompts/PromptWindows.cpp @@ -1013,10 +1013,7 @@ int WindowExitPrompt() { ret = WindowPrompt(tr( "Are you sure?" ), 0, tr( "Yes" ), tr( "No" )); if (ret == 1) - { - choice = 2; - } HaltGui(); mainWindow->SetState(STATE_DISABLED); promptWindow.SetState(STATE_DEFAULT); @@ -1028,9 +1025,7 @@ int WindowExitPrompt() { ret = WindowPrompt(tr( "Are you sure?" ), 0, tr( "Yes" ), tr( "No" )); if (ret == 1) - { choice = 3; - } HaltGui(); mainWindow->SetState(STATE_DISABLED); promptWindow.SetState(STATE_DEFAULT); @@ -2047,708 +2042,6 @@ bool NetworkInitPrompt() return success; } -/**************************************************************************** - * 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. - ***************************************************************************/ -#define BLOCKSIZE 1024 -/*bool unzipArchive(char * zipfilepath, char * unzipfolderpath) - { - unzFile uf = unzOpen(zipfilepath); - if (uf==NULL) - { - // printf("Cannot open %s, aborting\n",zipfilepath); - return false; - } - //printf("%s opened\n",zipfilepath); - if(chdir(unzipfolderpath)) // can't access dir - { - makedir(unzipfolderpath); // attempt to make dir - if(chdir(unzipfolderpath)) // still can't access dir - { - //printf("Error changing into %s, aborting\n", unzipfolderpath); - return false; - } - } - extractZip(uf,0,1,0); - unzCloseCurrentFile(uf); - return true - } - */ - -#ifdef FULLCHANNEL ///////////////////this is only used if the dol is being compiled for a full channel -int ProgressUpdateWindow() -{ - int ret = 0, failed = 0; - - gprintf( "\nProgressUpdateWindow(full channel)" ); - GuiWindow promptWindow( 472, 320 ); - promptWindow.SetAlignment( ALIGN_CENTRE, ALIGN_MIDDLE ); - promptWindow.SetPosition( 0, -10 ); - - char imgPath[100]; - snprintf( imgPath, sizeof( imgPath ), "%sbutton_dialogue_box.png", Settings.theme_path ); - GuiImageData btnOutline( imgPath, button_dialogue_box_png ); - snprintf( imgPath, sizeof( imgPath ), "%sdialogue_box.png", Settings.theme_path ); - GuiImageData dialogBox( imgPath, dialogue_box_png ); - GuiTrigger trigA; - trigA.SetSimpleTrigger( -1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A ); - - GuiImage dialogBoxImg( &dialogBox ); - if ( Settings.wsprompt ) - { - dialogBoxImg.SetWidescreen( Settings.widescreen ); - } - - snprintf( imgPath, sizeof( imgPath ), "%sprogressbar_outline.png", Settings.theme_path ); - GuiImageData progressbarOutline( imgPath, progressbar_outline_png ); - GuiImage progressbarOutlineImg( &progressbarOutline ); - if ( Settings.wsprompt ) - { - progressbarOutlineImg.SetWidescreen( Settings.widescreen ); - } - progressbarOutlineImg.SetAlignment( ALIGN_LEFT, ALIGN_MIDDLE ); - progressbarOutlineImg.SetPosition( 25, 7 ); - - snprintf( imgPath, sizeof( imgPath ), "%sprogressbar_empty.png", Settings.theme_path ); - GuiImageData progressbarEmpty( imgPath, progressbar_empty_png ); - GuiImage progressbarEmptyImg( &progressbarEmpty ); - progressbarEmptyImg.SetAlignment( ALIGN_LEFT, ALIGN_MIDDLE ); - progressbarEmptyImg.SetPosition( 25, 7 ); - progressbarEmptyImg.SetTile( 100 ); - - snprintf( imgPath, sizeof( imgPath ), "%sprogressbar.png", Settings.theme_path ); - GuiImageData progressbar( imgPath, progressbar_png ); - GuiImage progressbarImg( &progressbar ); - progressbarImg.SetAlignment( ALIGN_LEFT, ALIGN_MIDDLE ); - progressbarImg.SetPosition( 25, 7 ); - - char title[50]; - sprintf( title, "%s", tr( "Checking for Updates" ) ); - GuiText titleTxt( title, 26, Theme.prompttext ); - titleTxt.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - titleTxt.SetPosition( 0, 50 ); - char msg[50]; - sprintf( msg, "%s", tr( "Initializing Network" ) ); - GuiText msgTxt( msg, 26, Theme.prompttext ); - msgTxt.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - msgTxt.SetPosition( 0, 140 ); - char msg2[50] = " "; - GuiText msg2Txt( msg2, 26, Theme.prompttext ); - msg2Txt.SetAlignment( ALIGN_CENTRE, ALIGN_MIDDLE ); - msg2Txt.SetPosition( 0, 50 ); - - GuiText prTxt( NULL, 26, Theme.prompttext ); - prTxt.SetAlignment( ALIGN_CENTRE, ALIGN_MIDDLE ); - prTxt.SetPosition( 0, 7 ); - - GuiText btn1Txt( tr( "Cancel" ), 22, Theme.prompttext ); - GuiImage btn1Img( &btnOutline ); - if ( Settings.wsprompt ) - { - btn1Txt.SetWidescreen( Settings.widescreen ); - btn1Img.SetWidescreen( Settings.widescreen ); - } - GuiButton btn1( &btn1Img, &btn1Img, 2, 4, 0, -40, &trigA, btnSoundOver, btnSoundClick2, 1 ); - btn1.SetLabel( &btn1Txt ); - btn1.SetState( STATE_SELECTED ); - - if ( ( Settings.wsprompt ) && ( Settings.widescreen ) ) /////////////adjust for widescreen - - { - progressbarOutlineImg.SetAlignment( ALIGN_CENTRE, ALIGN_MIDDLE ); - progressbarOutlineImg.SetPosition( 0, 7 ); - progressbarEmptyImg.SetPosition( 80, 7 ); - progressbarEmptyImg.SetTile( 78 ); - progressbarImg.SetPosition( 80, 7 ); - } - - promptWindow.Append( &dialogBoxImg ); - promptWindow.Append( &titleTxt ); - promptWindow.Append( &msgTxt ); - promptWindow.Append( &msg2Txt ); - promptWindow.Append( &btn1 ); - - promptWindow.SetEffect( EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50 ); - - HaltGui(); - mainWindow->SetState( STATE_DISABLED ); - mainWindow->Append( &promptWindow ); - mainWindow->ChangeFocus( &promptWindow ); - ResumeGui(); - - struct stat st; - if ( stat( Settings.update_path, &st ) != 0 ) - { - if ( subfoldercreate( Settings.covers_path ) != 1 ) - { - WindowPrompt( tr( "Error !" ), tr( "Can't create directory" ), tr( "OK" ) ); - ret = -1; - failed = -1; - } - } - - if ( stat( Settings.titlestxt_path, &st ) != 0 ) - { - if ( subfoldercreate( Settings.titlestxt_path ) != 1 ) - { - WindowPrompt( tr( "Error !" ), tr( "Can't create directory" ), tr( "OK" ) ); - ret = -1; - failed = -1; - } - } - - char dolpath[150]; - // char dolpathsuccess[150];//use coverspath as a folder for the update wad so we dont make a new folder and have to delete it - snprintf( dolpath, sizeof( dolpath ), "%sULNR.wad", Settings.covers_path ); - //snprintf(dolpathsuccess, sizeof(dolpathsuccess), "%sUNEO.wad", Settings.covers_path); - Initialize_Network(); - while ( !IsNetworkInit() ) - { - - VIDEO_WaitVSync(); - - Initialize_Network(); - - if ( IsNetworkInit() ) - { - msgTxt.SetText( GetNetworkIP() ); - } - else - { - msgTxt.SetText( tr( "Could not initialize network!" ) ); - } - - if ( btn1.GetState() == STATE_CLICKED ) - { - ret = -1; - failed = -1; - btn1.ResetState(); - break; - } - } - - if ( IsNetworkInit() && ret >= 0 ) - { - - int newrev = CheckUpdate(); - - if ( newrev > 0 ) - { - FILE * pfile; - sprintf( msg, "Rev%i %s.", newrev, tr( "available" ) ); - int choice = WindowPrompt( msg, 0, tr( "Update" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - titleTxt.SetTextf( "%s USB Loader GX", tr( "Updating" ) ); - msgTxt.SetPosition( 0, 100 ); - msgTxt.SetTextf( "%s", tr( "Updating WiiTDB.zip" ) ); - UpdateWiiTDB(); - msgTxt.SetTextf( "%s", tr( "Updating Language Files:" ) ); - updateLanguageFiles(); - promptWindow.Append( &progressbarEmptyImg ); - promptWindow.Append( &progressbarImg ); - promptWindow.Append( &progressbarOutlineImg ); - promptWindow.Append( &prTxt ); - msgTxt.SetTextf( "%s Rev%i wad.", tr( "Downloading" ), newrev ); - s32 filesize; - if ( Settings.beta_upgrades ) - { - char url[255]; - memset( &url, 0, 255 ); - sprintf( ( char * ) &url, "http://usbloader-gui.googlecode.com/files/r%d.wad", newrev ); - filesize = download_request( ( char * ) & url ); - } - else - { - filesize = download_request( "http://www.techjawa.com/usbloadergx/ULNR.file" );//for some reason it didn't download completely when saved as a wad. - } - - if ( filesize > 0 ) - { - - pfile = fopen( dolpath, "wb" );//here we save the txt as a wad - u8 * blockbuffer = new unsigned char[BLOCKSIZE]; - for ( s32 i = 0; i < filesize; i += BLOCKSIZE ) - { - usleep( 100 ); - prTxt.SetTextf( "%i%%", ( 100*i / filesize ) + 1 ); - if ( ( Settings.wsprompt ) && ( Settings.widescreen ) ) - { - progressbarImg.SetTile( 80*i / filesize ); - } - else - { - progressbarImg.SetTile( 100*i / filesize ); - } - msg2Txt.SetTextf( "%iKB/%iKB", i / 1024, filesize / 1024 ); - - if ( btn1.GetState() == STATE_CLICKED ) - { - fclose( pfile ); - remove( dolpath ); - failed = -1; - btn1.ResetState(); - break; - } - - u32 blksize; - blksize = ( u32 )( filesize - i ); - if ( blksize > BLOCKSIZE ) - blksize = BLOCKSIZE; - - ret = network_read( blockbuffer, blksize ); - if ( ret != ( s32 ) blksize ) - { - failed = -1; - ret = -1; - fclose( pfile ); - remove( dolpath ); - break; - } - fwrite( blockbuffer, 1, blksize, pfile ); - } - fclose( pfile ); - delete blockbuffer; - if ( !failed ) - { - } - } - else - { - failed = -1; - } - } - else - { - ret = -1; - } - - } - else - { - WindowPrompt( tr( "No new updates." ), 0, tr( "OK" ) ); - ret = -1; - } - - } - promptWindow.SetEffect( EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50 ); - while ( promptWindow.GetEffect() > 0 ) usleep( 50 ); - - HaltGui(); - mainWindow->Remove( &promptWindow ); - //mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - CloseConnection(); - sleep( 1 );//sleep 1 because it froze without this for some reason - - if ( !failed && ret >= 0 ) - { - - FILE *wadFile = NULL; - s32 error = 1; - int diarhea = 0; - char nipple[100]; - wadFile = fopen ( dolpath , "rb" ); - if ( wadFile == NULL ) //we can't open the file wad we just downloaded - - { - sprintf( nipple, tr( "Unable to open the wad that was just downloaded (%s)." ), dolpath ); - WindowPrompt( tr( "Error !" ), nipple, tr( "OK" ) ); - failed = -1; - } - else - { - //sprintf(nipple, tr("The update wad has been saved as %s. Now let's try to install it."),dolpath); - //WindowPrompt(0,nipple, tr("OK")); - gprintf( "\n\tinstall wad" ); - error = Wad_Install( wadFile ); - fclose( wadFile ); - if ( error == 0 ) - { - diarhea = remove( dolpath ); - if ( diarhea ) - WindowPrompt( tr( "Success" ), tr( "The wad file was installed. But It could not be deleted from the SD card." ), tr( "OK" ) ); - } - else - { - gprintf( " -> failed" ); - sprintf( nipple, tr( "The wad installation failed with error %ld" ), error ); - WindowPrompt( tr( "Error" ), nipple, tr( "OK" ) ); - } - } - - if ( error ) - WindowPrompt( tr( "ERROR" ) , tr( "An Error occured" ), tr( "OK" ) ); - else - { - WindowPrompt( tr( "Restarting..." ), tr( "Successfully Updated thanks to www.techjawa.com" ) , 0, 0, 0, 0, 150 ); - } - CloseXMLDatabase(); - ExitGUIThreads(); - ShutdownAudio(); - StopGX(); - gprintf( "\nRebooting" ); - WII_Initialize(); - WII_LaunchTitle( TITLE_ID( 0x00010001, 0x554c4e52 ) ); - } - - // promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - //while(promptWindow.GetEffect() > 0) usleep(100); - - HaltGui(); - //mainWindow->Remove(&promptWindow); - mainWindow->SetState( STATE_DEFAULT ); - ResumeGui(); - - if ( failed != 0 ) - return failed; - - return 1; -} -#else -int ProgressUpdateWindow() -{ - - gprintf("\nProgressUpdateWindow(not full channel)"); - int ret = 0, failed = 0, updatemode = -1; - - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiImageData progressbarOutline(Resources::GetFile("progressbar_outline.png"), Resources::GetFileSize("progressbar_outline.png")); - GuiImage progressbarOutlineImg(&progressbarOutline); - if (Settings.wsprompt) - { - progressbarOutlineImg.SetWidescreen(Settings.widescreen); - } - progressbarOutlineImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarOutlineImg.SetPosition(25, 7); - - GuiImageData progressbarEmpty(Resources::GetFile("progressbar_empty.png"), Resources::GetFileSize("progressbar_empty.png")); - GuiImage progressbarEmptyImg(&progressbarEmpty); - progressbarEmptyImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarEmptyImg.SetPosition(25, 7); - progressbarEmptyImg.SetTile(100); - - GuiImageData progressbar(Resources::GetFile("progressbar.png"), Resources::GetFileSize("progressbar.png")); - GuiImage progressbarImg(&progressbar); - progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarImg.SetPosition(25, 7); - - char title[50]; - sprintf(title, "%s", tr( "Checking for Updates" )); - GuiText titleTxt(title, 26, Theme.prompttext); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 50); - char msg[50]; - sprintf(msg, "%s", tr( "Initializing Network" )); - GuiText msgTxt(msg, 26, Theme.prompttext); - msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - msgTxt.SetPosition(0, 140); - char msg2[50] = " "; - GuiText msg2Txt(msg2, 26, Theme.prompttext); - msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - msg2Txt.SetPosition(0, 50); - - GuiText prTxt((char*) NULL, 26, Theme.prompttext); - prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - prTxt.SetPosition(0, 7); - - GuiText btn1Txt(tr( "Cancel" ), 22, Theme.prompttext); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -40, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust for widescreen - { - progressbarOutlineImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - progressbarOutlineImg.SetPosition(0, 7); - progressbarEmptyImg.SetPosition(80, 7); - progressbarEmptyImg.SetTile(78); - progressbarImg.SetPosition(80, 7); - } - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msgTxt); - promptWindow.Append(&msg2Txt); - promptWindow.Append(&btn1); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - struct stat st; - if (stat(Settings.update_path, &st) != 0) - { - if (!CreateSubfolder(Settings.update_path)) - { - WindowPrompt(tr( "Error !" ), tr( "Can't create directory" ), tr( "OK" )); - ret = -1; - failed = -1; - } - } - - char dolpath[150]; - char dolpathsuccess[150]; - snprintf(dolpath, sizeof(dolpath), "%sbootnew.dol", Settings.update_path); - snprintf(dolpathsuccess, sizeof(dolpathsuccess), "%sboot.dol", Settings.update_path); - - while (!IsNetworkInit()) - { - - VIDEO_WaitVSync(); - - Initialize_Network(); - - if (IsNetworkInit()) - { - msgTxt.SetText(GetNetworkIP()); - } - else - { - msgTxt.SetText(tr( "Could not initialize network!" )); - } - - if (btn1.GetState() == STATE_CLICKED) - { - ret = -1; - failed = -1; - btn1.ResetState(); - break; - } - } - - //make the URL to get XML based on our games - //std::string allocates the memory and does not depend on stack - std::string XMLurl; - XMLurl.resize(4096); - build_XML_URL(&XMLurl[0], XMLurl.size()); - - if (IsNetworkInit() && ret >= 0) - { - - updatemode = WindowPrompt(tr( "What do you want to update?" ), 0, "USB Loader GX", tr( "WiiTDB Files" ), tr( "Language File" ), tr( "Cancel" )); - mainWindow->SetState(STATE_DISABLED); - promptWindow.SetState(STATE_DEFAULT); - mainWindow->ChangeFocus(&promptWindow); - - if (updatemode == 1) - { - - int newrev = CheckUpdate(); - if (newrev > 0) - { - - sprintf(msg, "Rev%i %s.", newrev, tr( "available" )); - int choice = WindowPrompt(msg, tr( "How do you want to update?" ), tr( "Update DOL" ), - tr( "Update All" ), tr( "Cancel" )); - mainWindow->SetState(STATE_DISABLED); - promptWindow.SetState(STATE_DEFAULT); - mainWindow->ChangeFocus(&promptWindow); - if (choice == 1 || choice == 2) - { - titleTxt.SetTextf("%s USB Loader GX", tr( "Updating" )); - msgTxt.SetPosition(0, 100); - promptWindow.Append(&progressbarEmptyImg); - promptWindow.Append(&progressbarImg); - promptWindow.Append(&progressbarOutlineImg); - promptWindow.Append(&prTxt); - msgTxt.SetTextf("%s Rev%i", tr( "Update to" ), newrev); - - s32 filesize; - if (Settings.beta_upgrades) - { - char url[255]; - memset(&url, 0, 255); - sprintf((char *) &url, "http://usbloader-gui.googlecode.com/files/r%d.dol", newrev); - filesize = download_request((char *) &url); - } - else - { - filesize = download_request("http://www.techjawa.com/usbloadergx/boot.dol"); - } - if (filesize > 0) - { - FILE * pfile; - pfile = fopen(dolpath, "wb"); - u8 * blockbuffer = new unsigned char[BLOCKSIZE]; - for (s32 i = 0; i < filesize; i += BLOCKSIZE) - { - usleep(100); - prTxt.SetTextf("%i%%", (100 * i / filesize) + 1); - if ((Settings.wsprompt) && (Settings.widescreen)) - { - progressbarImg.SetTile(80 * i / filesize); - } - else - { - progressbarImg.SetTile(100 * i / filesize); - } - msg2Txt.SetTextf("%iKB/%iKB", i / 1024, filesize / 1024); - - if (btn1.GetState() == STATE_CLICKED) - { - fclose(pfile); - remove(dolpath); - failed = -1; - btn1.ResetState(); - break; - } - - u32 blksize; - blksize = (u32) (filesize - i); - if (blksize > BLOCKSIZE) blksize = BLOCKSIZE; - - ret = network_read(connection, blockbuffer, blksize); - if (ret != (s32) blksize) - { - failed = -1; - ret = -1; - fclose(pfile); - remove(dolpath); - break; - } - fwrite(blockbuffer, 1, blksize, pfile); - } - fclose(pfile); - delete blockbuffer; - if (!failed) - { - //remove old - if (CheckFile(dolpathsuccess)) - { - remove(dolpathsuccess); - } - //rename new to old - rename(dolpath, dolpathsuccess); - - if (choice == 2) - { - //get the icon.png and the meta.xml - char xmliconpath[150]; - struct block file = downloadfile("http://www.techjawa.com/usbloadergx/meta.file"); - if (file.data != NULL) - { - sprintf(xmliconpath, "%smeta.xml", Settings.update_path); - pfile = fopen(xmliconpath, "wb"); - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - free(file.data); - } - file = downloadfile("http://www.techjawa.com/usbloadergx/icon.png"); - if (file.data != NULL) - { - sprintf(xmliconpath, "%sicon.png", Settings.update_path); - pfile = fopen(xmliconpath, "wb"); - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - free(file.data); - } - msgTxt.SetTextf("%s", tr( "Updating WiiTDB.zip" )); - UpdateWiiTDB(); - msgTxt.SetTextf("%s", tr( "Updating Language Files:" )); - updateLanguageFiles(); - } - } - } - else - { - failed = -1; - } - } - else - { - ret = -1; - } - } - else - { - WindowPrompt(tr( "No new updates." ), 0, tr( "OK" )); - ret = -1; - } - - } - else if (updatemode == 2) - { - msgTxt.SetTextf("%s", tr( "Updating WiiTDB.zip" )); - if(UpdateWiiTDB() < 0) - { - msgTxt.SetTextf("%s", tr( "WiiTDB is up to date." )); - sleep(3); - } - ret = 1; - } - else if (updatemode == 3) - { - - msgTxt.SetTextf("%s", tr( "Updating Language Files..." )); - updateLanguageFiles(); - ret = 1; - } - else - { - ret = -1; - } - } - - CloseConnection(); - - if (!failed && ret >= 0 && updatemode == 1) - { - WindowPrompt(tr( "Restarting..." ), tr( "Successfully Updated thanks to www.techjawa.com" ), 0, 0, 0, 0, 150); - - loadStub(); - Set_Stub_Split(0x00010001, "UNEO"); - Sys_BackToLoader(); - } - else if (updatemode > 0 && ret > 0) - { - WindowPrompt(tr( "Successfully Updated" ), 0, tr( "OK" )); - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - if (failed != 0) return failed; - - return 1; -} - -#endif - int CodeDownload(const char *id) { int ret = 0; diff --git a/source/prompts/PromptWindows.h b/source/prompts/PromptWindows.h index 8f48f585..4e8984bb 100644 --- a/source/prompts/PromptWindows.h +++ b/source/prompts/PromptWindows.h @@ -21,7 +21,6 @@ int WindowExitPrompt(); int GameWindowPrompt(int & gameSelected); int DiscWait(const char *title, const char *msg, const char *btn1Label, const char *btn2Label, int IsDeviceWait); int FormatingPartition(const char *title, partitionEntry *entry); -int ProgressUpdateWindow(); bool NetworkInitPrompt(); int WindowScreensaver(); int CodeDownload(const char *id); diff --git a/source/settings/SettingsPrompts.cpp b/source/settings/SettingsPrompts.cpp index 49f7e569..24a9c6a8 100644 --- a/source/settings/SettingsPrompts.cpp +++ b/source/settings/SettingsPrompts.cpp @@ -3,6 +3,7 @@ #include #include "language/gettext.h" +#include "language/UpdateLanguage.h" #include "prompts/PromptWindows.h" #include "prompts/ProgressWindow.h" #include "libwiigui/gui.h" @@ -100,7 +101,7 @@ int MenuLanguageSelect() trigB.SetButtonOnlyTrigger( -1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B ); char fullpath[100]; - DirList Dir( Settings.languagefiles_path ); + DirList Dir(Settings.languagefiles_path, ".lang"); if ( !strcmp( "", Settings.language_path ) ) { @@ -254,51 +255,10 @@ int MenuLanguageSelect() choice = WindowPrompt( tr( "Update all Language Files" ), tr( "Do you wish to update/download all language files?" ), tr( "OK" ), tr( "Cancel" ) ); if ( choice == 1 ) { - - bool network = true; - if ( !IsNetworkInit() ) + if (IsNetworkInit() || NetworkInitPrompt()) { - network = NetworkInitPrompt(); - } - - if ( network ) - { - const char URL[60] = "http://usbloader-gui.googlecode.com/svn/trunk/Languages/"; - char fullURL[300]; - FILE *pfile; - - URL_List LinkList( URL ); - int listsize = LinkList.GetURLCount(); - - CreateSubfolder( Settings.languagefiles_path ); - - for ( int i = 0; i < listsize; i++ ) - { - - ShowProgress( tr( "Updating Language Files:" ), 0, LinkList.GetURL( i ), i, listsize - 1 ); - - if ( strcasecmp( ".lang", strrchr( LinkList.GetURL( i ), '.' ) ) == 0 ) - { - - snprintf( fullURL, sizeof( fullURL ), "%s%s", URL, LinkList.GetURL( i ) ); - - struct block file = downloadfile( fullURL ); - - if ( file.data && file.size ) - { - char filepath[300]; - - snprintf( filepath, sizeof( filepath ), "%s%s", Settings.languagefiles_path, LinkList.GetURL( i ) ); - pfile = fopen( filepath, "wb" ); - fwrite( file.data, 1, file.size, pfile ); - fclose( pfile ); - - } - - free( file.data ); - } - } - ProgressStop(); + if(DownloadAllLanguageFiles() > 0) + WindowPrompt(tr("Update successfull"), 0, tr("OK")); returnhere = 1; break; } @@ -354,7 +314,9 @@ int MenuLanguageSelect() { char newLangPath[150]; snprintf( Settings.languagefiles_path, sizeof( Settings.languagefiles_path ), "%s", Dir.GetFilepath(ret)); - snprintf( newLangPath, sizeof( newLangPath ), "%s/%s", Dir.GetFilepath(ret), Dir.GetFilename( ret ) ); + char * ptr = strrchr(Settings.languagefiles_path, '/'); + if(ptr) ptr[1] = 0; + snprintf( newLangPath, sizeof( newLangPath ), "%s", Dir.GetFilepath(ret)); if ( !CheckFile( newLangPath ) ) { WindowPrompt( tr( "File not found." ), tr( "Loading standard language." ), tr( "OK" ) ); diff --git a/source/settings/menus/GlobalSettings.cpp b/source/settings/menus/GlobalSettings.cpp index 3fa5278d..e2810450 100644 --- a/source/settings/menus/GlobalSettings.cpp +++ b/source/settings/menus/GlobalSettings.cpp @@ -24,6 +24,7 @@ #include "GlobalSettings.hpp" #include "themes/CTheme.h" #include "prompts/PromptWindows.h" +#include "network/update.h" #include "language/gettext.h" #include "GUISettingsMenu.hpp" #include "GameLoadSM.hpp" @@ -122,7 +123,7 @@ void GlobalSettings::CreateSettingsMenu(int menuNr) HideMenu(); Remove(backBtn); ResumeGui(); - int ret = ProgressUpdateWindow(); + int ret = UpdateApp(); if (ret < 0) WindowPrompt(tr( "Update failed" ), 0, tr( "OK" )); Append(backBtn); diff --git a/source/sys.cpp b/source/sys.cpp index 6567a8c3..98a13ca5 100644 --- a/source/sys.cpp +++ b/source/sys.cpp @@ -73,10 +73,7 @@ void AppCleanUp(void) delete mainWindow; for (int i = 0; i < 4; i++) delete pointer[i]; - delete GameRegionTxt; - delete GameIDTxt; - delete cover; - delete coverImg; + gettextCleanUp(); CloseXMLDatabase(); ClearFontData(); @@ -160,12 +157,10 @@ void Sys_LoadMenu(void) void Sys_BackToLoader(void) { + ExitApp(); if (hbcStubAvailable()) - { - ExitApp(); exit(0); - } // Channel Version Sys_LoadMenu(); } diff --git a/source/utils/StringTools.c b/source/utils/StringTools.c index 39f4d487..1f19dcd9 100644 --- a/source/utils/StringTools.c +++ b/source/utils/StringTools.c @@ -33,7 +33,7 @@ const char * fmt(const char * format, ...) { static char strChar[512]; - memset(strChar, 0, sizeof(strChar)); + strChar[0] = 0; char * tmp = NULL; va_list va; @@ -59,10 +59,10 @@ const wchar_t * wfmt(const char * format, ...) strWChar[0] = 0; if(!format) - return (const wchar_t *) &strWChar; + return (const wchar_t *) strWChar; if(strcmp(format, "") == 0) - return (const wchar_t *) &strWChar; + return (const wchar_t *) strWChar; char * tmp = NULL; @@ -79,7 +79,7 @@ const wchar_t * wfmt(const char * format, ...) if(bt > 0) { strWChar[bt] = 0; - return (const wchar_t *) &strWChar; + return (const wchar_t *) strWChar; } } va_end(va); @@ -98,7 +98,7 @@ bool char2wchar_t(const char * strChar, wchar_t * dest) int bt; bt = mbstowcs(dest, strChar, strlen(strChar)); if (bt > 0) { - dest[bt] = (wchar_t) '\0'; + dest[bt] = 0; return true; } @@ -126,3 +126,21 @@ int strtokcmp(const char * string, const char * compare, const char * separator) return -1; } + +inline const char * FullpathToFilename(const char *path) +{ + if(!path) return path; + + const char * ptr = path; + const char * Filename = ptr; + + while(*ptr != '\0') + { + if(*ptr == '/' && ptr[1] != '\0') + Filename = ptr+1; + + ++ptr; + } + + return Filename; +} diff --git a/source/utils/StringTools.h b/source/utils/StringTools.h index 73bdecbb..d9c0a856 100644 --- a/source/utils/StringTools.h +++ b/source/utils/StringTools.h @@ -36,6 +36,7 @@ const char * fmt(const char * format, ...); const wchar_t * wfmt(const char * format, ...); bool char2wchar_t(const char * src, wchar_t * dest); int strtokcmp(const char * string, const char * compare, const char * separator); +const char * FullpathToFilename(const char *path); #ifdef __cplusplus }