From 71d537c1a715d084a8be6c495715e8c677030897 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Sun, 24 Oct 2010 19:08:03 +0000 Subject: [PATCH] *Compile warnings fixed for devkitPPC R22 *Changed usb fat partition mount/unmount a bit *Added wifi printf for quick debugging purpose only (not used currently). --- gui.pnproj | 2 +- source/FileOperations/DirList.cpp | 2 +- source/FileOperations/fileops.cpp | 2 +- source/ZipFile.cpp | 2 +- source/bannersound.cpp | 2 +- source/fatmounter.c | 29 +++++-- source/homebrewboot/HomebrewFiles.cpp | 2 +- source/homebrewboot/HomebrewXML.cpp | 67 +++++++++------ source/homebrewboot/HomebrewXML.h | 12 +-- source/libwiigui/gui_optionbrowser.cpp | 4 +- source/themes/Resources.cpp | 2 +- source/usbloader/partition_usbloader.c | 2 +- source/utils/wifi_gecko.c | 113 +++++++++++++++++++++++++ source/utils/wifi_gecko.h | 42 +++++++++ 14 files changed, 234 insertions(+), 49 deletions(-) create mode 100644 source/utils/wifi_gecko.c create mode 100644 source/utils/wifi_gecko.h diff --git a/gui.pnproj b/gui.pnproj index b609974e..523efa8f 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/FileOperations/DirList.cpp b/source/FileOperations/DirList.cpp index 0f58b5f3..779d3f15 100644 --- a/source/FileOperations/DirList.cpp +++ b/source/FileOperations/DirList.cpp @@ -185,7 +185,7 @@ char *DirList::GetFilepath(int ind) unsigned int DirList::GetFilesize(int ind) { if (ind >= filecount || !filecount || !FileInfo) - return NULL; + return 0; else return FileInfo[ind].FileSize; } diff --git a/source/FileOperations/fileops.cpp b/source/FileOperations/fileops.cpp index 57fcf0d6..1b135c04 100644 --- a/source/FileOperations/fileops.cpp +++ b/source/FileOperations/fileops.cpp @@ -888,7 +888,7 @@ extern "C" void GetFolderSize(const char * folderpath, u64 * foldersize, u32 * f } else { - if(filecount) *filecount++; + if(filecount) *filecount += 1; if(foldersize) *foldersize += st.st_size; } } diff --git a/source/ZipFile.cpp b/source/ZipFile.cpp index 0e512417..efebc3d0 100644 --- a/source/ZipFile.cpp +++ b/source/ZipFile.cpp @@ -76,7 +76,7 @@ bool ZipFile::ExtractAll(const char *dest) while (!Stop) { - if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, NULL, NULL, NULL) != UNZ_OK) Stop + if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK) Stop = true; if (!Stop && filename[strlen(filename) - 1] != '/') diff --git a/source/bannersound.cpp b/source/bannersound.cpp index 58b96fe7..6186da4f 100644 --- a/source/bannersound.cpp +++ b/source/bannersound.cpp @@ -181,7 +181,7 @@ const u8 *LoadBannerSound(const u8 *discid, u32 *size) if (*((u32*) soundChunk) == 0x4C5A3737 /*"LZ77"*/) { - u32 uncSize = NULL; + u32 uncSize = 0; u8 * uncompressed_data = uncompressLZ77(soundChunk, soundChunkSize, uncSize); if (!uncompressed_data) { diff --git a/source/fatmounter.c b/source/fatmounter.c index 7afabe60..b134ef77 100644 --- a/source/fatmounter.c +++ b/source/fatmounter.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -50,25 +51,37 @@ int USBDevice_Init() USBDevice_deInit(); //right now mounts first FAT-partition - if (!fatMount("USB", &__io_usbstorage2, 0, CACHE, SECTORS)) - return -1; + //usbstorage.startup is actually not needed since it's done in libfat + //let's still do it before mount and wait a bit for slow ass hdds before reading from them + __io_usbstorage2.startup(); + usleep(200000); - if(!fatMount("USB", &__io_usbstorage, 0, CACHE, SECTORS)) - return -1; + if (fatMount("USB", &__io_usbstorage2, 0, CACHE, SECTORS)) + { + fat_usb_sec = _FAT_startSector; + return (fat_usb_mount = 1); + } + __io_usbstorage.startup(); + usleep(200000); - fat_usb_mount = 1; - fat_usb_sec = _FAT_startSector; + if(fatMount("USB", &__io_usbstorage, 0, CACHE, SECTORS)) + { + fat_usb_sec = _FAT_startSector; + return (fat_usb_mount = 1); + } - return 1; + __io_usbstorage.shutdown(); + + return -1; } void USBDevice_deInit() { //closing all open Files write back the cache and then shutdown em! fatUnmount("USB:/"); + //only shutdown libogc usb and not the cios one __io_usbstorage.shutdown(); - __io_usbstorage2.shutdown(); fat_usb_mount = 0; fat_usb_sec = 0; diff --git a/source/homebrewboot/HomebrewFiles.cpp b/source/homebrewboot/HomebrewFiles.cpp index 3ccee886..cdf36bfd 100644 --- a/source/homebrewboot/HomebrewFiles.cpp +++ b/source/homebrewboot/HomebrewFiles.cpp @@ -111,7 +111,7 @@ char * HomebrewFiles::GetFilepath(int ind) unsigned int HomebrewFiles::GetFilesize(int ind) { if (ind > filecount || !filecount || !FileInfo) - return NULL; + return 0; else return FileInfo[ind].FileSize; } diff --git a/source/homebrewboot/HomebrewXML.cpp b/source/homebrewboot/HomebrewXML.cpp index d4187913..f5a2e25e 100644 --- a/source/homebrewboot/HomebrewXML.cpp +++ b/source/homebrewboot/HomebrewXML.cpp @@ -2,9 +2,11 @@ * HomebrewXML Class * for USB Loader GX ***************************************************************************/ +#include #include #include #include +#include "FileOperations/fileops.h" #include "xml/xml.h" #include "HomebrewXML.h" @@ -24,40 +26,54 @@ HomebrewXML::~HomebrewXML() /* qparam filename Filepath of the XML file */ int HomebrewXML::LoadHomebrewXMLData(const char* filename) { - mxml_node_t *nodedataHB = NULL; - mxml_node_t *nodetreeHB = NULL; + Name.clear(); + Coder.clear(); + Version.clear(); + ShortDescription.clear(); + LongDescription.clear(); + Releasedate.clear(); /* Load XML file */ - FILE *filexml; - filexml = fopen(filename, "rb"); - if (!filexml) return -1; + u8 * xmlbuffer = NULL; + u64 size = 0; + LoadFileToMem(filename, &xmlbuffer, &size); - nodetreeHB = mxmlLoadFile(NULL, filexml, MXML_OPAQUE_CALLBACK); - fclose(filexml); + if(!xmlbuffer) + return -1; - if (nodetreeHB == NULL) return -2; + mxml_node_t * nodetree = mxmlLoadString(NULL, (const char *) xmlbuffer, MXML_OPAQUE_CALLBACK); - nodedataHB = mxmlFindElement(nodetreeHB, nodetreeHB, "app", NULL, NULL, MXML_DESCEND); - if (nodedataHB == NULL) return -5; + if (!nodetree) + return -2; + + mxml_node_t * node = mxmlFindElement(nodetree, nodetree, "app", NULL, NULL, MXML_DESCEND_FIRST); + if (!node) + return -5; char * Entrie = new char[ENTRIE_SIZE]; - GetTextFromNode(nodedataHB, nodedataHB, (char*) "name", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); + Entrie[0] = '\0'; + GetTextFromNode(node, nodetree, (char*) "name", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); Name = Entrie; - GetTextFromNode(nodedataHB, nodedataHB, (char*) "coder", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); + Entrie[0] = '\0'; + GetTextFromNode(node, nodetree, (char*) "coder", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); Coder = Entrie; - GetTextFromNode(nodedataHB, nodedataHB, (char*) "version", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); + Entrie[0] = '\0'; + GetTextFromNode(node, nodetree, (char*) "version", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); Version = Entrie; - GetTextFromNode(nodedataHB, nodedataHB, (char*) "short_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); + Entrie[0] = '\0'; + GetTextFromNode(node, nodetree, (char*) "short_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); ShortDescription = Entrie; - GetTextFromNode(nodedataHB, nodedataHB, (char*) "long_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); + Entrie[0] = '\0'; + GetTextFromNode(node, nodetree, (char*) "long_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); LongDescription = Entrie; - GetTextFromNode(nodedataHB, nodedataHB, (char*) "release_date", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); + Entrie[0] = '\0'; + GetTextFromNode(node, nodetree, (char*) "release_date", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); int len = (strlen(Entrie) - 6); //length of the date string without the 200000 at the end if (len == 8) @@ -69,16 +85,17 @@ int HomebrewXML::LoadHomebrewXMLData(const char* filename) Releasedate = Entrie; - free(nodedataHB); - free(nodetreeHB); - delete[] Entrie; + mxmlDelete(node); + mxmlDelete(nodetree); + free(xmlbuffer); + return 1; } /* Get name */ -const char * HomebrewXML::GetName() +const char * HomebrewXML::GetName() const { return Name.c_str(); } @@ -90,31 +107,31 @@ void HomebrewXML::SetName(char * newName) } /* Get coder */ -const char * HomebrewXML::GetCoder() +const char * HomebrewXML::GetCoder() const { return Coder.c_str(); } /* Get version */ -const char * HomebrewXML::GetVersion() +const char * HomebrewXML::GetVersion() const { return Version.c_str(); } /* Get releasedate */ -const char * HomebrewXML::GetReleasedate() +const char * HomebrewXML::GetReleasedate() const { return Releasedate.c_str(); } /* Get shortdescription */ -const char * HomebrewXML::GetShortDescription() +const char * HomebrewXML::GetShortDescription() const { return ShortDescription.c_str(); } /* Get longdescription */ -const char * HomebrewXML::GetLongDescription() +const char * HomebrewXML::GetLongDescription() const { return LongDescription.c_str(); } diff --git a/source/homebrewboot/HomebrewXML.h b/source/homebrewboot/HomebrewXML.h index ccafb3ba..f890b2d5 100644 --- a/source/homebrewboot/HomebrewXML.h +++ b/source/homebrewboot/HomebrewXML.h @@ -15,13 +15,13 @@ class HomebrewXML int LoadHomebrewXMLData(const char* filename); - const char * GetName(); + const char * GetName() const; void SetName(char * newName); - const char * GetCoder(); - const char * GetVersion(); - const char * GetReleasedate(); - const char * GetShortDescription(); - const char * GetLongDescription(); + const char * GetCoder() const; + const char * GetVersion() const; + const char * GetReleasedate() const; + const char * GetShortDescription() const; + const char * GetLongDescription() const; protected: std::string Name; diff --git a/source/libwiigui/gui_optionbrowser.cpp b/source/libwiigui/gui_optionbrowser.cpp index 2824c43f..ddc93095 100644 --- a/source/libwiigui/gui_optionbrowser.cpp +++ b/source/libwiigui/gui_optionbrowser.cpp @@ -525,7 +525,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t) } WPAD_ScanPads(); - u8 cnt, buttons = NULL; + u8 cnt, buttons = 0; /* Get pressed buttons */ for (cnt = 0; cnt < 4; cnt++) buttons |= WPAD_ButtonsHeld(cnt); @@ -563,7 +563,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t) } WPAD_ScanPads(); - u8 cnt, buttons = NULL; + u8 cnt, buttons = 0; /* Get pressed buttons */ for (cnt = 0; cnt < 4; cnt++) buttons |= WPAD_ButtonsHeld(cnt); diff --git a/source/themes/Resources.cpp b/source/themes/Resources.cpp index b3b167a6..c469761d 100644 --- a/source/themes/Resources.cpp +++ b/source/themes/Resources.cpp @@ -241,7 +241,7 @@ const u32 Resources::GetFileSize(const char * filename) } } - return NULL; + return 0; } GuiImageData * Resources::GetImageData(const char * filename) diff --git a/source/usbloader/partition_usbloader.c b/source/usbloader/partition_usbloader.c index e29cd690..33bcbc3a 100644 --- a/source/usbloader/partition_usbloader.c +++ b/source/usbloader/partition_usbloader.c @@ -289,7 +289,7 @@ int get_fs_type(u8 *buff) wbfs_head_t *head = (wbfs_head_t *) buff; if (head->magic == wbfs_htonl( WBFS_MAGIC )) return FS_TYPE_WBFS; // 55AA - if (buff[0x1FE] == 0x55 && buff[0x1FF] == 0xAA) + if(*((u16 *) (buff + 0x1FE)) == 0x55AA) { // FAT if (memcmp(buff + 0x36, "FAT", 3) == 0) return FS_TYPE_FAT16; diff --git a/source/utils/wifi_gecko.c b/source/utils/wifi_gecko.c new file mode 100644 index 00000000..a5dc92dd --- /dev/null +++ b/source/utils/wifi_gecko.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * 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. + * + * for WiiXplorer 2010 + ***************************************************************************/ +#include +#include +#include +#include +#include +#include + +#define DESTINATION_IP "192.168.178.3" +#define DESTINATION_PORT 4405 + +static int connection = -1; + +void WifiGecko_Close() +{ + if(connection >= 0) + net_close(connection); + + connection = -1; +} + +int WifiGecko_Connect() +{ + if(!(connection < 0)) + return connection; + + connection = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); + if (connection < 0) + return connection; + + struct sockaddr_in connect_addr; + memset(&connect_addr, 0, sizeof(connect_addr)); + connect_addr.sin_family = AF_INET; + connect_addr.sin_port = htons(DESTINATION_PORT); + inet_aton(DESTINATION_IP, &connect_addr.sin_addr); + + if(net_connect(connection, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) + { + WifiGecko_Close(); + return -1; + } + + return connection; +} + +int WifiGecko_Send(const char * data, int datasize) +{ + if(!WifiGecko_Connect()) + return connection; + + int ret = 0, done = 0, blocksize = 1024; + + while (done < datasize) + { + if(blocksize > datasize-done) + blocksize = datasize-done; + + ret = net_send(connection, data+done, blocksize, 0); + if (ret < 0) + { + WifiGecko_Close(); + return ret; + } + else if(ret == 0) + { + break; + } + + done += ret; + usleep (1000); + } + + return ret; +} + +void wifi_printf(const char * format, ...) +{ + char * tmp = NULL; + va_list va; + va_start(va, format); + if((vasprintf(&tmp, format, va) >= 0) && tmp) + { + WifiGecko_Send(tmp, strlen(tmp)); + } + va_end(va); + + if(tmp) + free(tmp); +} diff --git a/source/utils/wifi_gecko.h b/source/utils/wifi_gecko.h new file mode 100644 index 00000000..ef97e470 --- /dev/null +++ b/source/utils/wifi_gecko.h @@ -0,0 +1,42 @@ +/**************************************************************************** + * 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. + * + * for WiiXplorer 2010 + ***************************************************************************/ +#ifndef WIFI_GECKO_H_ +#define WIFI_GECKO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int WifiGecko_Connect(); +void WifiGecko_Close(); +int WifiGecko_Send(const char * data, int datasize); +void wifi_printf(const char * format, ...); + +#ifdef __cplusplus +} +#endif + +#endif