2013-10-12 20:38:34 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <network.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "update.h"
|
|
|
|
#include "gecko.h"
|
|
|
|
#include "http.h"
|
|
|
|
|
2013-10-12 21:15:02 +02:00
|
|
|
s32 downloadSyscheckFile(const char* fileName) {
|
2013-10-12 20:38:34 +02:00
|
|
|
int ret = 0;
|
2014-02-10 16:00:50 +01:00
|
|
|
char buf[128] = {0};
|
2013-10-12 20:38:34 +02:00
|
|
|
u32 http_status;
|
|
|
|
u8* outbuf;
|
2014-02-18 02:37:54 +01:00
|
|
|
u32 length;
|
2013-10-12 20:38:34 +02:00
|
|
|
|
2014-02-10 16:00:50 +01:00
|
|
|
snprintf(buf, sizeof(buf), "http://syscheck-hd.googlecode.com/svn/trunk/SysCheckHDE/%s", fileName);
|
2013-10-12 20:38:34 +02:00
|
|
|
|
|
|
|
ret = http_request(buf, 1 << 31);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
ret = http_request(buf, 1 << 31);
|
|
|
|
if (ret) break;
|
|
|
|
if (i >= 10) {
|
|
|
|
gprintf("Error making http request\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-18 02:37:54 +01:00
|
|
|
ret = http_get_result(&http_status, &outbuf, &length);
|
2013-10-12 20:38:34 +02:00
|
|
|
|
|
|
|
if (((int)*outbuf & 0xF0000000) == 0xF0000000)
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%s%s", PATH, fileName);
|
|
|
|
|
|
|
|
FILE *file = fopen(buf, "w");
|
|
|
|
|
|
|
|
if(!file)
|
|
|
|
{
|
|
|
|
gprintf("File Error\n");
|
|
|
|
return -3;
|
|
|
|
} else {
|
2014-02-18 02:37:54 +01:00
|
|
|
fwrite(outbuf, length, 1, file);
|
2013-10-12 20:38:34 +02:00
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
free(outbuf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:41:01 +02:00
|
|
|
s32 updateApp(void) {
|
2013-10-12 20:38:34 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = net_init();
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
u32 http_status;
|
|
|
|
u8* outbuf;
|
2013-10-12 20:56:41 +02:00
|
|
|
u32 length;
|
2013-10-12 20:38:34 +02:00
|
|
|
|
2014-02-28 02:44:22 +01:00
|
|
|
ret = http_request("http://syscheck-hd.googlecode.com/svn/trunk/Version.txt", 1 << 31);
|
2013-10-12 20:38:34 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
gprintf("Error making http request\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-12 20:56:41 +02:00
|
|
|
ret = http_get_result(&http_status, &outbuf, &length);
|
2013-10-12 20:38:34 +02:00
|
|
|
|
|
|
|
if (((int)*outbuf & 0xF0000000) == 0xF0000000)
|
|
|
|
{
|
|
|
|
ret = -2;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:44:22 +01:00
|
|
|
if (!strncmp((char*)outbuf, "Version=", sizeof("Version=")))
|
2013-10-12 20:38:34 +02:00
|
|
|
{
|
2014-02-28 02:44:22 +01:00
|
|
|
int version = atoi((char*)(outbuf + sizeof("Version=")));
|
2013-10-12 20:38:34 +02:00
|
|
|
gprintf("INT: %i\n", version);
|
|
|
|
|
|
|
|
if (version > REVISION) {
|
|
|
|
ret = downloadSyscheckFile("boot.dol");
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = downloadSyscheckFile("meta.xml");
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = downloadSyscheckFile("icon.png");
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
ret = 2;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ret = -3;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
net_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|