Skip to content

Commit

Permalink
Finished network update feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Sep 4, 2016
1 parent 0368a4a commit ec51cc1
Show file tree
Hide file tree
Showing 19 changed files with 424 additions and 67 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RESOURCES_PNG = resources/folder_icon.png resources/file_icon.png resources/arch
resources/battery_bar_charge.png resources/headphone.png resources/audio_previous.png resources/audio_pause.png \
resources/audio_play.png resources/audio_next.png
RESOURCES_TXT = resources/theme.txt resources/colors.txt resources/english_us.txt
OBJS += $(RESOURCES_PNG:.png=.o) $(RESOURCES_TXT:.txt=.o)
RESOURCES_BIN = resources/updater_eboot.bin resources/updater_param.bin
OBJS += $(RESOURCES_PNG:.png=.o) $(RESOURCES_TXT:.txt=.o) $(RESOURCES_BIN:.bin=.o)

LIBS = -lftpvita -lvita2d -lpng -ljpeg -lz -lm -lc \
-lSceAppMgr_stub -lSceAppUtil_stub -lSceCommonDialog_stub \
Expand Down Expand Up @@ -59,6 +60,8 @@ $(TARGET).elf: $(OBJS)
$(PREFIX)-ld -r -b binary -o $@ $^
%.o: %.txt
$(PREFIX)-ld -r -b binary -o $@ $^
%.o: %.bin
$(PREFIX)-ld -r -b binary -o $@ $^

clean:
@rm -rf $(TARGET).vpk $(TARGET).velf $(TARGET).elf $(OBJS) \
Expand Down
Empty file removed VitaShellUpdater/main.c
Empty file.
6 changes: 4 additions & 2 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,16 @@ typedef struct {

static ExtensionType extension_types[] = {
{ ".BMP", FILE_TYPE_BMP },
{ ".INI", FILE_TYPE_INI },
{ ".JPG", FILE_TYPE_JPEG },
{ ".JPEG", FILE_TYPE_JPEG },
{ ".PNG", FILE_TYPE_PNG },
{ ".MP3", FILE_TYPE_MP3 },
{ ".PNG", FILE_TYPE_PNG },
{ ".SFO", FILE_TYPE_SFO },
{ ".TXT", FILE_TYPE_TXT },
{ ".VPK", FILE_TYPE_VPK },
{ ".XML", FILE_TYPE_XML },
{ ".ZIP", FILE_TYPE_ZIP },
{ ".TXT", FILE_TYPE_TXT },
};

int getFileType(char *file) {
Expand Down
6 changes: 4 additions & 2 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
enum FileTypes {
FILE_TYPE_UNKNOWN,
FILE_TYPE_BMP,
FILE_TYPE_INI,
FILE_TYPE_JPEG,
FILE_TYPE_PNG,
FILE_TYPE_MP3,
FILE_TYPE_PNG,
FILE_TYPE_SFO,
FILE_TYPE_TXT,
FILE_TYPE_VPK,
FILE_TYPE_XML,
FILE_TYPE_ZIP,
FILE_TYPE_TXT,
};

enum SortFlags {
Expand Down
1 change: 1 addition & 0 deletions language.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void loadLanguage(int id) {
LANGUAGE_ENTRY(DELETING),
LANGUAGE_ENTRY(INSTALLING),
LANGUAGE_ENTRY(DOWNLOADING),
LANGUAGE_ENTRY(EXTRACTING),
LANGUAGE_ENTRY(DELETE_FILE_QUESTION),
LANGUAGE_ENTRY(DELETE_FOLDER_QUESTION),
LANGUAGE_ENTRY(DELETE_FILES_FOLDERS_QUESTION),
Expand Down
1 change: 1 addition & 0 deletions language.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum LanguageContainer {
DELETING,
INSTALLING,
DOWNLOADING,
EXTRACTING,
DELETE_FILE_QUESTION,
DELETE_FOLDER_QUESTION,
DELETE_FILES_FOLDERS_QUESTION,
Expand Down
105 changes: 62 additions & 43 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ int handleFile(char *file, FileListEntry *entry) {
}

switch (type) {
case FILE_TYPE_INI:
case FILE_TYPE_TXT:
case FILE_TYPE_XML:
case FILE_TYPE_UNKNOWN:
res = textViewer(file);
break;
Expand Down Expand Up @@ -758,7 +760,6 @@ int dialogSteps() {
case DIALOG_STEP_COPIED:
case DIALOG_STEP_DELETED:
case DIALOG_STEP_INSTALLED:
case DIALOG_STEP_DOWNLOADED:
if (msg_result == MESSAGE_DIALOG_RESULT_NONE || msg_result == MESSAGE_DIALOG_RESULT_FINISHED) {
refresh = 1;
dialog_step = DIALOG_STEP_NONE;
Expand Down Expand Up @@ -835,47 +836,6 @@ int dialogSteps() {

break;

case DIALOG_STEP_INSTALL_QUESTION:
if (msg_result == MESSAGE_DIALOG_RESULT_YES) {
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[INSTALLING]);
dialog_step = DIALOG_STEP_INSTALL_CONFIRMED;
} else if (msg_result == MESSAGE_DIALOG_RESULT_NO) {
dialog_step = DIALOG_STEP_NONE;
}

break;

case DIALOG_STEP_INSTALL_CONFIRMED:
if (msg_result == MESSAGE_DIALOG_RESULT_RUNNING) {
InstallArguments args;
args.file = cur_file;

SceUID thid = sceKernelCreateThread("install_thread", (SceKernelThreadEntry)install_thread, 0x40, 0x10000, 0, 0, NULL);
if (thid >= 0)
sceKernelStartThread(thid, sizeof(InstallArguments), &args);

dialog_step = DIALOG_STEP_INSTALLING;
}

break;

case DIALOG_STEP_INSTALL_WARNING:
if (msg_result == MESSAGE_DIALOG_RESULT_YES) {
dialog_step = DIALOG_STEP_INSTALL_WARNING_AGREED;
} else if (msg_result == MESSAGE_DIALOG_RESULT_NO) {
dialog_step = DIALOG_STEP_CANCELLED;
}

break;

case DIALOG_STEP_UPDATE_QUESTION:
if (msg_result == MESSAGE_DIALOG_RESULT_YES) {
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[DOWNLOADING]);
dialog_step = DIALOG_STEP_UPDATE_CONFIRMED;
} else if (msg_result == MESSAGE_DIALOG_RESULT_NO) {
dialog_step = DIALOG_STEP_NONE;
}

case DIALOG_STEP_RENAME:
if (ime_result == IME_DIALOG_RESULT_FINISHED) {
char *name = (char *)getImeDialogInputTextUTF8();
Expand Down Expand Up @@ -934,6 +894,65 @@ int dialogSteps() {
}

break;

case DIALOG_STEP_INSTALL_QUESTION:
if (msg_result == MESSAGE_DIALOG_RESULT_YES) {
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[INSTALLING]);
dialog_step = DIALOG_STEP_INSTALL_CONFIRMED;
} else if (msg_result == MESSAGE_DIALOG_RESULT_NO) {
dialog_step = DIALOG_STEP_NONE;
}

break;

case DIALOG_STEP_INSTALL_CONFIRMED:
if (msg_result == MESSAGE_DIALOG_RESULT_RUNNING) {
InstallArguments args;
args.file = cur_file;

SceUID thid = sceKernelCreateThread("install_thread", (SceKernelThreadEntry)install_thread, 0x40, 0x10000, 0, 0, NULL);
if (thid >= 0)
sceKernelStartThread(thid, sizeof(InstallArguments), &args);

dialog_step = DIALOG_STEP_INSTALLING;
}

break;

case DIALOG_STEP_INSTALL_WARNING:
if (msg_result == MESSAGE_DIALOG_RESULT_YES) {
dialog_step = DIALOG_STEP_INSTALL_WARNING_AGREED;
} else if (msg_result == MESSAGE_DIALOG_RESULT_NO) {
dialog_step = DIALOG_STEP_CANCELLED;
}

break;

case DIALOG_STEP_UPDATE_QUESTION:
if (msg_result == MESSAGE_DIALOG_RESULT_YES) {
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[DOWNLOADING]);
dialog_step = DIALOG_STEP_DOWNLOADING;
} else if (msg_result == MESSAGE_DIALOG_RESULT_NO) {
dialog_step = DIALOG_STEP_NONE;
}

case DIALOG_STEP_DOWNLOADED:
if (msg_result == MESSAGE_DIALOG_RESULT_FINISHED) {
initMessageDialog(MESSAGE_DIALOG_PROGRESS_BAR, language_container[INSTALLING]);

SceUID thid = sceKernelCreateThread("update_extract_thread", (SceKernelThreadEntry)update_extract_thread, 0x40, 0x10000, 0, 0, NULL);
if (thid >= 0)
sceKernelStartThread(thid, 0, NULL);

dialog_step = DIALOG_STEP_EXTRACTING;
}

break;

case DIALOG_STEP_EXTRACTED:
launchAppByUriExit("VSUPDATER");
dialog_step = DIALOG_STEP_NONE;
break;
}

return refresh;
Expand Down Expand Up @@ -1166,7 +1185,7 @@ int shellMain() {
} else if (file_entry->type == FILE_TYPE_SFO) { // SFO
// note: specific color to be determined
vita2d_draw_texture(sfo_icon, SHELL_MARGIN_X, y + 3.0f);
} else if (file_entry->type == FILE_TYPE_TXT) { // TXT
} else if (file_entry->type == FILE_TYPE_INI || file_entry->type == FILE_TYPE_TXT || file_entry->type == FILE_TYPE_XML) { // TXT
// note: specific color to be determined
vita2d_draw_texture(text_icon, SHELL_MARGIN_X, y + 3.0f);
} else { // Other files
Expand Down
4 changes: 3 additions & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ enum DialogSteps {
DIALOG_STEP_RENAME,

DIALOG_STEP_UPDATE_QUESTION,
DIALOG_STEP_UPDATE_CONFIRMED,
DIALOG_STEP_DOWNLOADING,
DIALOG_STEP_DOWNLOADED,
DIALOG_STEP_EXTRACTING,
DIALOG_STEP_EXTRACTED,
};

extern vita2d_pgf *font;
Expand Down
112 changes: 109 additions & 3 deletions network_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@
#include "main.h"
#include "io_process.h"
#include "network_update.h"
#include "package_installer.h"
#include "archive.h"
#include "file.h"
#include "message_dialog.h"
#include "language.h"
#include "utils.h"

#define BASE_ADDRESS "https://github.com/TheOfficialFloW/VitaShell/releases/download"
#define VITASHELL_UPDATE_FILE "ux0:VitaShell/VitaShell.vpk"

extern unsigned char _binary_resources_updater_eboot_bin_start;
extern unsigned char _binary_resources_updater_eboot_bin_size;
extern unsigned char _binary_resources_updater_param_bin_start;
extern unsigned char _binary_resources_updater_param_bin_size;

int getDownloadFileSize(char *src, uint64_t *size) {
int tpl = sceHttpCreateTemplate("VitaShell/1.00 libhttp/1.1", SCE_HTTP_VERSION_1_1, 1);
if (tpl < 0)
Expand Down Expand Up @@ -117,7 +127,7 @@ int downloadProcess(char *version_string) {

// Download url
char url[128];
sprintf(url, "https://github.com/TheOfficialFloW/VitaShell/releases/download/%s/VitaShell.vpk", version_string);
sprintf(url, BASE_ADDRESS "/%s/VitaShell.vpk", version_string);

// File size
uint64_t size = 0;
Expand All @@ -128,7 +138,7 @@ int downloadProcess(char *version_string) {

// Download
uint64_t value = 0;
int res = downloadFile(url, "ux0:VitaShell/Vitashell.vpk", &value, size, SetProgress, cancelHandler);
int res = downloadFile(url, VITASHELL_UPDATE_FILE, &value, size, SetProgress, cancelHandler);
if (res <= 0) {
closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED;
Expand Down Expand Up @@ -158,7 +168,7 @@ int downloadProcess(char *version_string) {
int network_update_thread(SceSize args, void *argp) {
sceHttpsDisableOption(SCE_HTTPS_FLAG_SERVER_VERIFY);

if (downloadFile("http://github.com/TheOfficialFloW/VitaShell/releases/download/0.0/version.bin", "ux0:VitaShell/version.bin", NULL, 0, NULL, NULL) > 0) {
if (downloadFile(BASE_ADDRESS "/0.0/version.bin", "ux0:VitaShell/version.bin", NULL, 0, NULL, NULL) > 0) {
uint32_t version = 0;
ReadFile("ux0:VitaShell/version.bin", &version, sizeof(uint32_t));
sceIoRemove("ux0:VitaShell/version.bin");
Expand Down Expand Up @@ -195,5 +205,101 @@ int network_update_thread(SceSize args, void *argp) {
}
}

return sceKernelExitDeleteThread(0);
}

int installUpdater() {
// Recursively clean up package_temp directory
removePath(PACKAGE_PARENT, NULL, 0, NULL, NULL);
sceIoMkdir(PACKAGE_PARENT, 0777);

sceIoMkdir("ux0:ptmp", 0777);
sceIoMkdir("ux0:ptmp/pkg", 0777);
sceIoMkdir("ux0:ptmp/pkg/sce_sys", 0777);

WriteFile("ux0:ptmp/pkg/eboot.bin", (void *)&_binary_resources_updater_eboot_bin_start, (int)&_binary_resources_updater_eboot_bin_size);
WriteFile("ux0:ptmp/pkg/sce_sys/param.sfo", (void *)&_binary_resources_updater_param_bin_start, (int)&_binary_resources_updater_param_bin_size);

// Make head.bin
makeHeadBin();

// Promote
promote(PACKAGE_DIR);
}

int update_extract_thread(SceSize args, void *argp) {
SceUID thid = -1;

// Lock power timers
powerLock();

// Set progress to 0%
sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 0);
sceKernelDelayThread(DIALOG_WAIT); // Needed to see the percentage

// Install updater
installUpdater();

// Recursively clean up package_temp directory
removePath(PACKAGE_PARENT, NULL, 0, NULL, NULL);
sceIoMkdir(PACKAGE_PARENT, 0777);

// Open archive
int res = archiveOpen(VITASHELL_UPDATE_FILE);
if (res < 0) {
closeWaitDialog();
errorDialog(res);
goto EXIT;
}

// Src path
char *src_path = VITASHELL_UPDATE_FILE "/";

// Get archive path info
uint64_t size = 0;
uint32_t folders = 0, files = 0;
getArchivePathInfo(src_path, &size, &folders, &files);

// Update thread
thid = createStartUpdateThread(size + folders);

// Extract process
uint64_t value = 0;

res = extractArchivePath(src_path, PACKAGE_DIR "/", &value, size + folders, SetProgress, cancelHandler);
if (res <= 0) {
closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED;
errorDialog(res);
goto EXIT;
}

// Remove update file
sceIoRemove(VITASHELL_UPDATE_FILE);

// Make head.bin
res = makeHeadBin();
if (res < 0) {
closeWaitDialog();
errorDialog(res);
goto EXIT;
}

// Set progress to 100%
sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 100);
sceKernelDelayThread(COUNTUP_WAIT);

// Close
sceMsgDialogClose();

dialog_step = DIALOG_STEP_EXTRACTED;

EXIT:
if (thid >= 0)
sceKernelWaitThreadEnd(thid, NULL, NULL);

// Unlock power timers
powerUnlock();

return sceKernelExitDeleteThread(0);
}
1 change: 1 addition & 0 deletions network_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
#define __NETWORK_UPDATE_H__

int network_update_thread(SceSize args, void *argp);
int update_extract_thread(SceSize args, void *argp);

#endif
Loading

0 comments on commit ec51cc1

Please sign in to comment.