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>
|
2015-09-29 00:32:10 +02:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <unistd.h>
|
2015-10-09 02:04:26 +02:00
|
|
|
#include <fat.h>
|
2013-10-12 20:38:34 +02:00
|
|
|
|
|
|
|
#include "update.h"
|
2015-10-09 02:04:26 +02:00
|
|
|
#include "fatMounter.h"
|
2013-10-12 20:38:34 +02:00
|
|
|
#include "gecko.h"
|
|
|
|
#include "http.h"
|
2015-10-05 06:11:56 +02:00
|
|
|
#include "ssl.h"
|
2015-09-29 00:32:10 +02:00
|
|
|
#include "tools.h"
|
2013-10-12 20:38:34 +02:00
|
|
|
|
2015-10-09 02:04:26 +02:00
|
|
|
extern http_res result;
|
|
|
|
|
2015-09-29 00:32:10 +02:00
|
|
|
s32 downloadSyscheckFile(const char* update_dir, 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;
|
2015-10-05 06:11:56 +02:00
|
|
|
|
2015-10-09 02:04:26 +02:00
|
|
|
snprintf(buf, sizeof(buf), "http://svn.code.sf.net/p/syscheck-hde/code/trunk/SysCheckHDE/%s", fileName);
|
2015-09-29 00:32:10 +02:00
|
|
|
|
2013-10-12 20:38:34 +02:00
|
|
|
ret = http_request(buf, 1 << 31);
|
2015-09-29 00:32:10 +02:00
|
|
|
if (!ret)
|
2013-10-12 20:38:34 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
ret = http_request(buf, 1 << 31);
|
2015-10-09 02:04:26 +02:00
|
|
|
gprintf("result = %i\n", result);
|
2013-10-12 20:38:34 +02:00
|
|
|
if (ret) break;
|
|
|
|
if (i >= 10) {
|
|
|
|
gprintf("Error making http request\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-19 19:47:13 +02:00
|
|
|
|
2015-09-29 00:32:10 +02:00
|
|
|
ret = http_get_result(&http_status, &outbuf, &length);
|
2015-10-09 02:04:26 +02:00
|
|
|
gprintf("http_get_result returned %i\n", ret);
|
2015-09-29 00:32:10 +02:00
|
|
|
|
|
|
|
sprintf(buf, "%s%s", update_dir, fileName);
|
|
|
|
|
2013-10-12 20:38:34 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-10-09 02:04:26 +02:00
|
|
|
if (outbuf) free(outbuf);
|
2013-10-12 20:38:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:41:01 +02:00
|
|
|
s32 updateApp(void) {
|
2015-09-29 00:32:10 +02:00
|
|
|
int ret = net_init();
|
2015-10-05 06:11:56 +02:00
|
|
|
ssl_init();
|
2015-10-09 02:04:26 +02:00
|
|
|
char update_dir[25];
|
|
|
|
char *version;
|
|
|
|
sprintf(update_dir, "%s:/apps/SysCheckHDE/", arguments.USB ? "usb" : "sd");
|
2015-10-05 06:11:56 +02:00
|
|
|
mkdir("/apps",S_IWRITE|S_IREAD); // attempt to make dir
|
|
|
|
mkdir("/apps/SysCheckHDE",S_IWRITE|S_IREAD); // attempt to make dir
|
2015-09-29 00:32:10 +02:00
|
|
|
chdir(update_dir);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
net_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|
2013-10-12 20:38:34 +02:00
|
|
|
u32 http_status;
|
|
|
|
u8* outbuf;
|
2013-10-12 20:56:41 +02:00
|
|
|
u32 length;
|
2015-09-29 00:32:10 +02:00
|
|
|
|
2015-10-09 02:04:26 +02:00
|
|
|
ret = http_request("http://svn.code.sf.net/p/syscheck-hde/code/trunk/Version.txt", 1 << 31);
|
2015-09-29 00:32:10 +02:00
|
|
|
if (!ret)
|
2013-10-12 20:38:34 +02:00
|
|
|
{
|
|
|
|
gprintf("Error making http request\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-29 00:32:10 +02:00
|
|
|
ret = http_get_result(&http_status, &outbuf, &length);
|
2015-10-09 02:04:26 +02:00
|
|
|
version = (char*)calloc(length, sizeof(char));
|
|
|
|
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))
|
2013-10-12 20:38:34 +02:00
|
|
|
{
|
2015-10-09 02:04:26 +02:00
|
|
|
int latest_version = atoi(version + sizeof("Version=") - 1);
|
|
|
|
gprintf("INT: %i\n", latest_version);
|
|
|
|
free(version);
|
|
|
|
if (latest_version > REVISION) {
|
2015-09-29 00:32:10 +02:00
|
|
|
ret = downloadSyscheckFile(update_dir, "boot.dol");
|
|
|
|
if (ret < 0) {
|
|
|
|
net_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = downloadSyscheckFile(update_dir, "meta.xml");
|
|
|
|
if (ret < 0) {
|
|
|
|
net_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = downloadSyscheckFile(update_dir, "icon.png");
|
|
|
|
if (ret < 0) {
|
|
|
|
net_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|
2013-10-12 20:38:34 +02:00
|
|
|
} else {
|
2015-09-29 00:32:10 +02:00
|
|
|
net_deinit();
|
2015-10-05 06:11:56 +02:00
|
|
|
return 2;
|
2013-10-12 20:38:34 +02:00
|
|
|
}
|
2015-09-29 00:32:10 +02:00
|
|
|
|
2013-10-12 20:38:34 +02:00
|
|
|
} else {
|
2015-09-29 00:32:10 +02:00
|
|
|
net_deinit();
|
2015-10-09 02:04:26 +02:00
|
|
|
free(version);
|
2015-09-29 00:32:10 +02:00
|
|
|
return -3;
|
2013-10-12 20:38:34 +02:00
|
|
|
}
|
2015-10-09 02:04:26 +02:00
|
|
|
if (outbuf) free(outbuf);
|
2013-10-12 20:38:34 +02:00
|
|
|
net_deinit();
|
|
|
|
return ret;
|
2015-09-29 00:32:10 +02:00
|
|
|
}
|