From 1e9951f586a070d30dd4e4f72bca6c2784dd37b1 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Sun, 30 May 2010 07:00:29 +0000 Subject: [PATCH] *forgot that i wanted to fix the beta updater The beta updates will work now. You will have to update to this revision manually though. --- HBC/META.XML | 4 +- gui.pnproj | 2 +- source/network/HTML_Stream.cpp | 196 +++++++++++++++++++++++++++++++++ source/network/HTML_Stream.h | 68 ++++++++++++ source/network/update.cpp | 161 +++++++++++++-------------- 5 files changed, 346 insertions(+), 85 deletions(-) create mode 100644 source/network/HTML_Stream.cpp create mode 100644 source/network/HTML_Stream.h diff --git a/HBC/META.XML b/HBC/META.XML index 7d436890..95c31036 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r933 - 201005291607 + 1.0 r934 + 201005300653 Loads games from USB-devices USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. diff --git a/gui.pnproj b/gui.pnproj index f3128446..25e6a3a5 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/network/HTML_Stream.cpp b/source/network/HTML_Stream.cpp new file mode 100644 index 00000000..c116013b --- /dev/null +++ b/source/network/HTML_Stream.cpp @@ -0,0 +1,196 @@ + /*************************************************************************** + * 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. + * + * HTML_Stream Class + * + * for WiiXplorer 2010 + ***************************************************************************/ +#include +#include +#include + +#include "HTML_Stream.h" +#include "networkops.h" +#include "http.h" + +#define htmlstringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos], (const char*) cmp, strlen((const char*) cmp)) + + +HTML_Stream::HTML_Stream() +{ + HTML_File = NULL; + position = 0; + filesize = 0; +} + +HTML_Stream::HTML_Stream(const char * url) +{ + HTML_File = NULL; + position = 0; + filesize = 0; + + LoadLink(url); +} + +HTML_Stream::~HTML_Stream() +{ + if(HTML_File) + free(HTML_File); +} + +bool HTML_Stream::LoadLink(const char * url) +{ + if (!IsNetworkInit()) + return false; + + struct block file = downloadfile(url); + + if (!file.data || !file.size) + return false; + + if(HTML_File) + free(HTML_File); + + HTML_File = (char *) file.data; + filesize = file.size; + position = 0; + + return true; +} + +const char * HTML_Stream::FindStringStart(const char * string) +{ + if (!HTML_File) + return NULL; + + while((u32) position < filesize) + { + if(htmlstringcompare(HTML_File, string, position) == 0) + break; + + position++; + } + + return &HTML_File[position]; +} + +const char * HTML_Stream::FindStringEnd(const char * string) +{ + if (!HTML_File) + return NULL; + + while((u32) position < filesize) + { + if(htmlstringcompare(HTML_File, string, position) == 0) + break; + + position++; + } + + if((u32) position >= filesize) + { + return NULL; + } + + position += strlen(string); + + return &HTML_File[position]; +} + +char * HTML_Stream::CopyString(const char * stopat) +{ + if(!stopat || !HTML_File) + return NULL; + + u32 blocksize = 1024; + u32 counter = 0; + u32 allocatedsize = 0; + + char * outtext = (char*) malloc(blocksize); + if(!outtext) + return NULL; + + allocatedsize = blocksize; + memset(outtext, 0, blocksize); + + while ((htmlstringcompare(HTML_File, stopat, position) != 0) && (position+strlen(stopat) < filesize)) + { + if(counter > blocksize) + { + blocksize += 1024; + char * tmpblock = (char*) realloc(outtext, blocksize); + if(!tmpblock) + { + free(outtext); + outtext = NULL; + free(tmpblock); + return NULL; + } + + outtext = tmpblock; + } + + outtext[counter] = HTML_File[position]; + position++; + counter++; + } + + outtext[counter] = '\0'; + outtext = (char*) realloc(outtext, counter+1); + + return outtext; +} + +int HTML_Stream::Seek(u32 pos, int origin) +{ + if(!HTML_File) + return -1; + + switch(origin) + { + case SEEK_SET: + position = pos; + break; + case SEEK_CUR: + position += pos; + break; + case SEEK_END: + position = filesize+pos; + break; + } + + return 0; +} + +void HTML_Stream::Rewind() +{ + if(!HTML_File) + return; + + position = 0; +} + +int HTML_Stream::GetPosition() +{ + return position; +} diff --git a/source/network/HTML_Stream.h b/source/network/HTML_Stream.h new file mode 100644 index 00000000..e696ce0c --- /dev/null +++ b/source/network/HTML_Stream.h @@ -0,0 +1,68 @@ + /*************************************************************************** + * 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. + * + * HTML_Stream Class + * + * for WiiXplorer 2010 + ***************************************************************************/ +#ifndef ___HTML_STREAM_H_ +#define ___HTML_STREAM_H_ + +#include + +class HTML_Stream +{ + public: + //!Constructor + HTML_Stream(); + //!\param url from where to the HTML file + HTML_Stream(const char * url); + //!Destructor + ~HTML_Stream(); + //!Load url + bool LoadLink(const char * url); + //! Find start of a string from current position in the html + //!\param string to find + const char * FindStringStart(const char * string); + //! Find end of a string from current position in the html + //!\param string to find + const char * FindStringEnd(const char * string); + //!CopyString from current position in html till stopat string + //!\param stopat string before which to stop copying (e.g. ) + //!\param outtext variable is allocated with malloc and must be set 0 before + char * CopyString(const char * stopat); + //!Seek position in file + //!\param position seeked + //!\param seek origin (SEEK_SET, SEEK_CUR, SEEK_END) + int Seek(u32 pos, int origin); + //!Rewind to the start of the html + void Rewind(); + //!Get current position + int GetPosition(); + protected: + int position; + u32 filesize; + char * HTML_File; +}; + +#endif diff --git a/source/network/update.cpp b/source/network/update.cpp index 53b1fa70..eb49758d 100644 --- a/source/network/update.cpp +++ b/source/network/update.cpp @@ -1,82 +1,79 @@ - /*************************************************************************** - * Copyright (C) 2009 - * 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. - * - * update.cpp - * - * Update operations - * for Wii-Xplorer 2009 - ***************************************************************************/ -#include -#include -#include - -#include "http.h" -#include "networkops.h" -#include "URL_List.h" - -/**************************************************************************** - * Checking if an Update is available - ***************************************************************************/ -int CheckForBetaUpdate() -{ - int revnumber = 0; - - URL_List URLs("http://code.google.com/p/usbloader-gui/downloads/list"); - - int urlcount = URLs.GetURLCount(); - - for(int i = 0; i < urlcount; i++) - { - char *tmp = URLs.GetURL(i); - if(tmp) - { - char *fileext = strrchr(tmp, '.'); - if(fileext) - { - if(strcasecmp(fileext, ".dol") == 0 || strcasecmp(fileext, ".wad") == 0) - { - char *DownloadLink = (char *) malloc(strlen(tmp)+1); - sprintf(DownloadLink, "%s", tmp); - - int rev = 0; - char revtxt[80]; - char *filename = strrchr(DownloadLink, '/')+2; - u8 n = 0; - for (n = 0; n < strlen(filename)-2; n++) - revtxt[n] = filename[n]; - revtxt[n] = 0; - rev = atoi(revtxt); - - if(rev > revnumber) { - revnumber = rev; - } - if(DownloadLink) - free(DownloadLink); - DownloadLink = NULL; - } - } - } - } - - return revnumber; -} + /*************************************************************************** + * Copyright (C) 2009 + * 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. + * + * update.cpp + * + * Update operations + * for Wii-Xplorer 2009 + ***************************************************************************/ +#include +#include +#include + +#include "http.h" +#include "networkops.h" +#include "HTML_Stream.h" + +/**************************************************************************** + * Checking if an Update is available + ***************************************************************************/ +int CheckForBetaUpdate() +{ + int revnumber = 0; + + HTML_Stream HTML("http://code.google.com/p/usbloader-gui/downloads/list"); + + const char * HTML_Pos = NULL; + + do + { + HTML_Pos = HTML.FindStringEnd("href='"); + char * tmpLink = HTML.CopyString("'\""); + if(tmpLink) + { + char *fileext = strrchr(tmpLink, '.'); + if(fileext) + { + if(strcasecmp(fileext, ".dol") == 0) + { + char revtxt[80]; + char *filename = strrchr(tmpLink, '/')+2; + u8 n = 0; + for (n = 0; n < strlen(filename)-2; n++) + revtxt[n] = filename[n]; + revtxt[n] = 0; + int fileRev = atoi(revtxt); + + if(fileRev > revnumber) + { + revnumber = fileRev; + } + } + } + free(tmpLink); + } + } + while(HTML_Pos != NULL); + + return revnumber; +}