*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
This commit is contained in:
dimok321 2010-12-18 13:20:45 +00:00
parent f7c1e9958d
commit 3f03d92295
21 changed files with 583 additions and 1049 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 104 KiB

View File

@ -27,17 +27,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <sys/dir.h>
#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<FileInfos>().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;
}

View File

@ -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 <vector>
#include <gctypes.h>
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<FileInfos> FileInfo;
};
#endif

View File

@ -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);

View File

@ -8,69 +8,131 @@
#include <sys/dir.h>
#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;

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -24,7 +24,7 @@ static void AbortCallback(void)
AbortRequested = true;
}
static int CoverDownloadWithProgress(const char * url, const char * writepath, std::vector<std::string> & MissingFilesList)
static int CoverDownloadWithProgress(const char * url, const char * progressTitle, const char * writepath, std::vector<std::string> & 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<std::string> 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)

View File

@ -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)
{

View File

@ -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;
}
/****************************************************************************

View File

@ -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;
}

View File

@ -31,5 +31,6 @@
int CheckForBetaUpdate();
int UpdateWiiTDB();
int UpdateApp();
#endif

View File

@ -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;

View File

@ -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);

View File

@ -3,6 +3,7 @@
#include <string.h>
#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" ) );

View File

@ -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);

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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
}