-Fixed updating

-When update fails, the previously selected IOS is properly shown when returning to selection
This commit is contained in:
joostinonline 2015-10-09 00:04:26 +00:00
parent b541f5dc53
commit 216b96185c
4 changed files with 42 additions and 21 deletions

BIN
boot.elf

Binary file not shown.

View File

@ -75,11 +75,12 @@ s32 tcp_connect (char *host, const u16 port) {
struct sockaddr_in sa; struct sockaddr_in sa;
s32 s, res; s32 s, res;
s64 t; s64 t;
gprintf("tcp_connect\n");
hp = net_gethostbyname (host); hp = net_gethostbyname (host);
if (!hp || !(hp->h_addrtype == PF_INET)) return errno; if (!hp || !(hp->h_addrtype == PF_INET)) return errno;
s = tcp_socket (); s = tcp_socket ();
gprintf("tcp_socket = %i\n", s);
if (s < 0) if (s < 0)
return s; return s;
@ -295,7 +296,7 @@ bool http_request (const char *url, const u32 max_size) {
http_port = 80; http_port = 80;
else else
http_port = 443; http_port = 443;
gprintf("http_port = %u\n", http_port);
http_max_size = max_size; http_max_size = max_size;
http_status = 404; http_status = 404;
@ -303,6 +304,7 @@ bool http_request (const char *url, const u32 max_size) {
http_data = NULL; http_data = NULL;
int s = tcp_connect (http_host, http_port); int s = tcp_connect (http_host, http_port);
gprintf("tcp_connect = %i\n", s);
if (s < 0) { if (s < 0) {
result = HTTPR_ERR_CONNECT; result = HTTPR_ERR_CONNECT;
return false; return false;
@ -420,6 +422,7 @@ bool http_post (const char *url, const u32 max_size, const char *postData) {
http_data = NULL; http_data = NULL;
int s = tcp_connect (http_host, http_port); int s = tcp_connect (http_host, http_port);
gprintf("tcp_connect = %i\n", s);
if (s < 0) { if (s < 0) {
result = HTTPR_ERR_CONNECT; result = HTTPR_ERR_CONNECT;
return false; return false;
@ -465,6 +468,7 @@ bool http_post (const char *url, const u32 max_size, const char *postData) {
} }
if (linecount == 32 || !content_length) http_status = 404; if (linecount == 32 || !content_length) http_status = 404;
gprintf("http_status = %u\n", http_status);
if (http_status != 200) { if (http_status != 200) {
result = HTTPR_ERR_STATUS; result = HTTPR_ERR_STATUS;
net_close (s); net_close (s);

View File

@ -50,7 +50,7 @@ int main(int argc, char **argv)
arguments.USB = strlen(argv[0]) && (argv[0][0] == 'U' || argv[0][0] == 'u'); arguments.USB = strlen(argv[0]) && (argv[0][0] == 'U' || argv[0][0] == 'u');
InitGecko(); InitGecko();
gprintf("=============================================================================="); gprintf("\n==============================================================================\n");
if(argc>=1){ if(argc>=1){
int i; int i;
for(i=0; i<argc; i++){ for(i=0; i<argc; i++){
@ -467,6 +467,7 @@ int main(int argc, char **argv)
sysMenuInfoContent = *(u8 *)((u32)iosTMDBuffer+0x1E7); sysMenuInfoContent = *(u8 *)((u32)iosTMDBuffer+0x1E7);
sprintf(filepath, "/title/00000001/00000002/content/%08x.app", sysMenuInfoContent); sprintf(filepath, "/title/00000001/00000002/content/%08x.app", sysMenuInfoContent);
gprintf(filepath); gprintf(filepath);
gprintf("\n");
ret = read_file_from_nand(filepath, &buffer, &filesize); ret = read_file_from_nand(filepath, &buffer, &filesize);
sysInfo = (iosinfo_t *)(buffer); sysInfo = (iosinfo_t *)(buffer);
@ -565,11 +566,15 @@ int main(int argc, char **argv)
if (wpressed & WPAD_BUTTON_PLUS) { if (wpressed & WPAD_BUTTON_PLUS) {
printLoading(MSG_Update); printLoading(MSG_Update);
ret = updateApp(); ret = updateApp();
gprintf("updateApp returned %i\n", ret);
if (ret == 2) { if (ret == 2) {
printSuccess(MSG_NoUpdate); printSuccess(MSG_NoUpdate);
sleep(5); sleep(5);
starttime = time(NULL); starttime = time(NULL);
printSelectIOS(MSG_SelectIOS, MSG_Buffer); if (selectedIOS > -1)
printSelectIOS(MSG_SelectIOS, MSG_Buffer);
else
printSelectIOS(MSG_SelectIOS, MSG_All);
} else if (ret >= 0) { } else if (ret >= 0) {
printSuccess(MSG_UpdateSuccess); printSuccess(MSG_UpdateSuccess);
sleep(5); sleep(5);
@ -579,7 +584,10 @@ int main(int argc, char **argv)
printError(MSG_UpdateFail); printError(MSG_UpdateFail);
sleep(5); sleep(5);
starttime = time(NULL); starttime = time(NULL);
printSelectIOS(MSG_SelectIOS, MSG_Buffer); if (selectedIOS > -1)
printSelectIOS(MSG_SelectIOS, MSG_Buffer);
else
printSelectIOS(MSG_SelectIOS, MSG_All);
} }
} }

View File

@ -6,13 +6,17 @@
#include <network.h> #include <network.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <fat.h>
#include "update.h" #include "update.h"
#include "fatMounter.h"
#include "gecko.h" #include "gecko.h"
#include "http.h" #include "http.h"
#include "ssl.h" #include "ssl.h"
#include "tools.h" #include "tools.h"
extern http_res result;
s32 downloadSyscheckFile(const char* update_dir, const char* fileName) { s32 downloadSyscheckFile(const char* update_dir, const char* fileName) {
int ret = 0; int ret = 0;
char buf[128] = {0}; char buf[128] = {0};
@ -20,7 +24,7 @@ s32 downloadSyscheckFile(const char* update_dir, const char* fileName) {
u8* outbuf; u8* outbuf;
u32 length; u32 length;
snprintf(buf, sizeof(buf), "https://sourceforge.net/p/syscheck-hde/code/HEAD/tree/trunk/SysCheckHDE/%s?format=raw", fileName); snprintf(buf, sizeof(buf), "http://svn.code.sf.net/p/syscheck-hde/code/trunk/SysCheckHDE/%s", fileName);
ret = http_request(buf, 1 << 31); ret = http_request(buf, 1 << 31);
if (!ret) if (!ret)
@ -28,6 +32,7 @@ s32 downloadSyscheckFile(const char* update_dir, const char* fileName) {
int i; int i;
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
ret = http_request(buf, 1 << 31); ret = http_request(buf, 1 << 31);
gprintf("result = %i\n", result);
if (ret) break; if (ret) break;
if (i >= 10) { if (i >= 10) {
gprintf("Error making http request\n"); gprintf("Error making http request\n");
@ -37,11 +42,8 @@ s32 downloadSyscheckFile(const char* update_dir, const char* fileName) {
} }
ret = http_get_result(&http_status, &outbuf, &length); ret = http_get_result(&http_status, &outbuf, &length);
//u8 *file = (u8*)calloc(length, sizeof(u8))
if (((int)*outbuf & 0xF0000000) == 0xF0000000) gprintf("http_get_result returned %i\n", ret);
{
return -2;
}
sprintf(buf, "%s%s", update_dir, fileName); sprintf(buf, "%s%s", update_dir, fileName);
@ -55,15 +57,18 @@ s32 downloadSyscheckFile(const char* update_dir, const char* fileName) {
fwrite(outbuf, length, 1, file); fwrite(outbuf, length, 1, file);
fclose(file); fclose(file);
} }
free(outbuf); if (outbuf) free(outbuf);
return 0; return 0;
} }
s32 updateApp(void) { s32 updateApp(void) {
MountSD();
fatInitDefault();
int ret = net_init(); int ret = net_init();
ssl_init(); ssl_init();
char update_dir[21]; char update_dir[25];
sprintf(update_dir, "%s:/apps/SysCheckHDE", arguments.USB ? "usb" : "sd"); char *version;
sprintf(update_dir, "%s:/apps/SysCheckHDE/", arguments.USB ? "usb" : "sd");
mkdir("/apps",S_IWRITE|S_IREAD); // attempt to make dir mkdir("/apps",S_IWRITE|S_IREAD); // attempt to make dir
mkdir("/apps/SysCheckHDE",S_IWRITE|S_IREAD); // attempt to make dir mkdir("/apps/SysCheckHDE",S_IWRITE|S_IREAD); // attempt to make dir
chdir(update_dir); chdir(update_dir);
@ -76,7 +81,7 @@ s32 updateApp(void) {
u8* outbuf; u8* outbuf;
u32 length; u32 length;
ret = http_request("https://sourceforge.net/p/syscheck-hde/code/HEAD/tree/trunk/Version.txt?format=raw", 1 << 31); ret = http_request("http://svn.code.sf.net/p/syscheck-hde/code/trunk/Version.txt", 1 << 31);
if (!ret) if (!ret)
{ {
gprintf("Error making http request\n"); gprintf("Error making http request\n");
@ -84,13 +89,15 @@ s32 updateApp(void) {
} }
ret = http_get_result(&http_status, &outbuf, &length); ret = http_get_result(&http_status, &outbuf, &length);
version = (char*)calloc(length, sizeof(char));
if (!strncmp((char*)outbuf, "Version=", sizeof("Version="))) strncpy(version, (char*)outbuf, length);
gprintf("ret = %i, http_status = %u, outbuf = %s, length = %u, version = %s\n", ret, http_status, (char*)outbuf, length, version+8);
if (!strncmp(version, "Version=", sizeof("Version=") - 1))
{ {
int version = atoi((char*)(outbuf + sizeof("Version="))); int latest_version = atoi(version + sizeof("Version=") - 1);
gprintf("INT: %i\n", version); gprintf("INT: %i\n", latest_version);
free(version);
if (version > REVISION) { if (latest_version > REVISION) {
ret = downloadSyscheckFile(update_dir, "boot.dol"); ret = downloadSyscheckFile(update_dir, "boot.dol");
if (ret < 0) { if (ret < 0) {
net_deinit(); net_deinit();
@ -113,8 +120,10 @@ s32 updateApp(void) {
} else { } else {
net_deinit(); net_deinit();
free(version);
return -3; return -3;
} }
if (outbuf) free(outbuf);
net_deinit(); net_deinit();
return ret; return ret;
} }