Merge remote-tracking branch 'refs/remotes/TheOfficialFloW/master'

This commit is contained in:
littlebalup 2016-09-04 13:38:19 +02:00
commit ac13223f8b
22 changed files with 744 additions and 176 deletions

View File

@ -1,6 +1,6 @@
TITLE_ID = VITASHELL
TARGET = VitaShell
OBJS = main.o init.o io_process.o package_installer.o archive.o photo.o file.o text.o hex.o sfo.o \
OBJS = main.o init.o io_process.o package_installer.o network_update.o archive.o photo.o file.o text.o hex.o sfo.o \
uncommon_dialog.o message_dialog.o ime_dialog.o config.o theme.o language.o utils.o sha1.o \
audioplayer.o minizip/unzip.o minizip/ioapi.o
@ -10,13 +10,14 @@ 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 \
-lSceCtrl_stub -lSceDisplay_stub -lSceGxm_stub -lSceIme_stub \
-lSceKernel_stub -lSceNet_stub -lSceNetCtl_stub \
-lSceSysmodule_stub -lScePower_stub -lScePgf_stub libpromoter/libScePromoterUtil_stub.a \
-lSceHttp_stub -lSceKernel_stub -lSceNet_stub -lSceNetCtl_stub \
-lSceSsl_stub -lSceSysmodule_stub -lScePower_stub -lScePgf_stub libpromoter/libScePromoterUtil_stub.a \
-lSceAudio_stub -lSceAudiodec_stub -lSceTouch_stub
#NETDBG_IP ?= 192.168.1.50
@ -38,7 +39,7 @@ ASFLAGS = $(CFLAGS)
all: $(TARGET).vpk
%.vpk: eboot.bin
vita-mksfoex -d PARENTAL_LEVEL=1 -s APP_VER=00.90 -s TITLE_ID=$(TITLE_ID) "$(TARGET)" param.sfo
vita-mksfoex -d PARENTAL_LEVEL=1 -s APP_VER=00.91 -s TITLE_ID=$(TITLE_ID) "$(TARGET)" param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin \
--add pkg/sce_sys/icon0.png=sce_sys/icon0.png \
--add pkg/sce_sys/livearea/contents/bg.png=sce_sys/livearea/contents/bg.png \
@ -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) \

View File

@ -70,6 +70,13 @@ https://github.com/xy2iii/vitashell-themes
Be sure you pull request your customized design or language file there.
### Changelog 0.91 ###
- Added automatic network update. VitaShell will now notify you when there's a new update.
You'll then be able to download it within the VitaShell application and it will update both
molecularShell and VitaShell to the newest verison.
- Added text and audio file icon by littlebalup.
- Updated to latest libftpvita which fixed file size string > 2GB and added APPE command.
### Changelog 0.9 ###
- Added possibility to use specific background for file browser, hex editor, text editor, photo viewer.
- Added files and folder icons by littlebalup.

8
file.c
View File

@ -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 },
{ ".VPK", FILE_TYPE_VPK },
{ ".ZIP", FILE_TYPE_ZIP },
{ ".TXT", FILE_TYPE_TXT },
{ ".VPK", FILE_TYPE_VPK },
{ ".XML", FILE_TYPE_XML },
{ ".ZIP", FILE_TYPE_ZIP },
};
int getFileType(char *file) {

8
file.h
View File

@ -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_VPK,
FILE_TYPE_ZIP,
FILE_TYPE_TXT,
FILE_TYPE_VPK,
FILE_TYPE_XML,
FILE_TYPE_ZIP,
};
enum SortFlags {

38
init.c
View File

@ -165,13 +165,35 @@ void finishVita2dLib() {
audio_next_image = NULL;
}
void initNet() {
static char memory[16 * 1024];
SceNetInitParam param;
param.memory = memory;
param.size = sizeof(memory);
param.flags = 0;
sceNetInit(&param);
sceNetCtlInit();
sceSslInit(300 * 1024);
sceHttpInit(40 * 1024);
}
void finishNet() {
sceSslTerm();
sceHttpTerm();
sceNetCtlTerm();
sceNetTerm();
}
void initVitaShell() {
// Init random number generator
srand(time(NULL));
// Set sampling mode
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
// Enable front touchscreen
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, 1);
@ -182,12 +204,13 @@ void initVitaShell() {
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) != SCE_SYSMODULE_LOADED)
sceSysmoduleLoadModule(SCE_SYSMODULE_NET);
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_HTTPS) != SCE_SYSMODULE_LOADED)
sceSysmoduleLoadModule(SCE_SYSMODULE_HTTPS);
// Init
initSceAppUtil();
initVita2dLib();
// Init netdbg
netdbg_init();
initNet();
// Init power tick thread
initPowerTickThread();
@ -209,14 +232,15 @@ void initVitaShell() {
}
void finishVitaShell() {
// Finish netdbg
netdbg_fini();
// Finish
finishNet();
finishVita2dLib();
finishSceAppUtil();
// Unload modules
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_HTTPS) == SCE_SYSMODULE_LOADED)
sceSysmoduleUnloadModule(SCE_SYSMODULE_HTTPS);
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) == SCE_SYSMODULE_LOADED)
sceSysmoduleUnloadModule(SCE_SYSMODULE_NET);

8
init.h
View File

@ -21,6 +21,8 @@
#include "file.h"
#define NET_INIT_SIZE 1 * 1024 * 1024
extern int language, enter_button, date_format, time_format;
typedef struct {
@ -29,12 +31,6 @@ typedef struct {
int size;
} DefaultFile;
void initSceAppUtil();
void finishSceAppUtil();
void initVita2dLib();
void finishVita2dLib();
void initVitaShell();
void finishVitaShell();

View File

@ -84,6 +84,8 @@ void loadLanguage(int id) {
LANGUAGE_ENTRY(COPYING),
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),
@ -93,6 +95,7 @@ void loadLanguage(int id) {
LANGUAGE_ENTRY(WIFI_ERROR),
LANGUAGE_ENTRY(FTP_SERVER),
LANGUAGE_ENTRY(SYS_INFO),
LANGUAGE_ENTRY(UPDATE_QUESTION),
};
// Load default config file

View File

@ -42,6 +42,8 @@ enum LanguageContainer {
COPYING,
DELETING,
INSTALLING,
DOWNLOADING,
EXTRACTING,
DELETE_FILE_QUESTION,
DELETE_FOLDER_QUESTION,
DELETE_FILES_FOLDERS_QUESTION,
@ -51,6 +53,7 @@ enum LanguageContainer {
WIFI_ERROR,
FTP_SERVER,
SYS_INFO,
UPDATE_QUESTION,
LANGUAGE_CONTRAINER_SIZE,
};

125
main.c
View File

@ -37,6 +37,7 @@
#include "init.h"
#include "io_process.h"
#include "package_installer.h"
#include "network_update.h"
#include "archive.h"
#include "photo.h"
#include "file.h"
@ -258,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;
@ -312,7 +315,12 @@ void drawScrollBar(int pos, int n) {
void drawShellInfo(char *path) {
// Title
pgf_draw_textf(SHELL_MARGIN_X, SHELL_MARGIN_Y, TITLE_COLOR, FONT_SIZE, "VitaShell %d.%d", VITASHELL_VERSION_MAJOR, VITASHELL_VERSION_MINOR);
char version[8];
sprintf(version, "%X.%X", VITASHELL_VERSION_MAJOR, VITASHELL_VERSION_MINOR);
if (version[3] == '0')
version[3] = '\0';
pgf_draw_textf(SHELL_MARGIN_X, SHELL_MARGIN_Y, TITLE_COLOR, FONT_SIZE, "VitaShell %s", version);
// Battery
float battery_x = ALIGN_LEFT(SCREEN_WIDTH - SHELL_MARGIN_X, vita2d_texture_get_width(battery_image));
@ -828,39 +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_RENAME:
if (ime_result == IME_DIALOG_RESULT_FINISHED) {
char *name = (char *)getImeDialogInputTextUTF8();
@ -919,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;
@ -1151,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
@ -1255,16 +1289,6 @@ void initShell() {
}
void getNetInfo() {
static char memory[16 * 1024];
SceNetInitParam param;
param.memory = memory;
param.size = sizeof(memory);
param.flags = 0;
int net_init = sceNetInit(&param);
int netctl_init = sceNetCtlInit();
// Get mac address
sceNetGetMacAddress(&mac, 0);
@ -1275,12 +1299,6 @@ void getNetInfo() {
} else {
strcpy(ip, info.ip_address);
}
if (netctl_init >= 0)
sceNetCtlTerm();
if (net_init >= 0)
sceNetTerm();
}
int main(int argc, const char *argv[]) {
@ -1301,6 +1319,11 @@ int main(int argc, const char *argv[]) {
// Load language
loadLanguage(language);
// Automatic network update
SceUID thid = sceKernelCreateThread("network_update_thread", (SceKernelThreadEntry)network_update_thread, 0x40, 0x10000, 0, 0, NULL);
if (thid >= 0)
sceKernelStartThread(thid, 0, NULL);
// Main
initShell();
shellMain();

15
main.h
View File

@ -27,9 +27,11 @@
#include <psp2/display.h>
#include <psp2/kernel/modulemgr.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/libssl.h>
#include <psp2/io/dirent.h>
#include <psp2/io/fcntl.h>
#include <psp2/ime_dialog.h>
#include <psp2/net/http.h>
#include <psp2/net/net.h>
#include <psp2/net/netctl.h>
#include <psp2/message_dialog.h>
@ -59,12 +61,13 @@
#include "functions.h"
#define ENABLE_DEBUGNET_LOGGING 1
#define ENABLE_FILE_LOGGING 1
// VitaShell version major.minor
#define VITASHELL_VERSION_MAJOR 0
#define VITASHELL_VERSION_MINOR 9
#define VITASHELL_VERSION_MAJOR 0x0
#define VITASHELL_VERSION_MINOR 0x91
#define VITASHELL_VERSION ((VITASHELL_VERSION_MAJOR << 0x18) | (VITASHELL_VERSION_MINOR << 0x10))
#define ALIGN(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
@ -170,6 +173,12 @@ enum DialogSteps {
DIALOG_STEP_INSTALLED,
DIALOG_STEP_RENAME,
DIALOG_STEP_UPDATE_QUESTION,
DIALOG_STEP_DOWNLOADING,
DIALOG_STEP_DOWNLOADED,
DIALOG_STEP_EXTRACTING,
DIALOG_STEP_EXTRACTED,
};
extern vita2d_pgf *font;

305
network_update.c Normal file
View File

@ -0,0 +1,305 @@
/*
VitaShell
Copyright (C) 2015-2016, TheFloW
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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)
return tpl;
int conn = sceHttpCreateConnectionWithURL(tpl, src, 0);
if (conn < 0)
return conn;
int req = sceHttpCreateRequestWithURL(conn, SCE_HTTP_METHOD_GET, src, 0);
if (req < 0)
return req;
int res = sceHttpSendRequest(req, NULL, 0);
if (res < 0)
return res;
sceHttpGetResponseContentLength(req, size);
sceHttpDeleteRequest(req);
sceHttpDeleteConnection(conn);
sceHttpDeleteTemplate(tpl);
return 0;
}
int downloadFile(char *src, char *dst, uint64_t *value, uint64_t max, void (* SetProgress)(uint64_t value, uint64_t max), int (* cancelHandler)()) {
int ret = 1;
int tpl = sceHttpCreateTemplate("VitaShell/1.00 libhttp/1.1", SCE_HTTP_VERSION_1_1, 1);
if (tpl < 0)
return tpl;
int conn = sceHttpCreateConnectionWithURL(tpl, src, 0);
if (conn < 0)
return conn;
int req = sceHttpCreateRequestWithURL(conn, SCE_HTTP_METHOD_GET, src, 0);
if (req < 0)
return req;
int res = sceHttpSendRequest(req, NULL, 0);
if (res < 0)
return res;
SceUID fd = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
if (fd < 0)
return fd;
uint8_t buf[4096];
int read;
while ((read = sceHttpReadData(req, buf, sizeof(buf))) > 0) {
int res = sceIoWrite(fd, buf, read);
if (res < 0) {
ret = res;
break;
}
if (value)
(*value) += read;
if (SetProgress)
SetProgress(value ? *value : 0, max);
if (cancelHandler && cancelHandler()) {
sceIoClose(fd);
ret = 0;
break;
}
}
sceIoClose(fd);
sceHttpDeleteRequest(req);
sceHttpDeleteConnection(conn);
sceHttpDeleteTemplate(tpl);
return ret;
}
int downloadProcess(char *version_string) {
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
// Download url
char url[128];
sprintf(url, BASE_ADDRESS "/%s/VitaShell.vpk", version_string);
// File size
uint64_t size = 0;
getDownloadFileSize(url, &size);
// Update thread
thid = createStartUpdateThread(size);
// Download
uint64_t value = 0;
int res = downloadFile(url, VITASHELL_UPDATE_FILE, &value, size, SetProgress, cancelHandler);
if (res <= 0) {
closeWaitDialog();
dialog_step = DIALOG_STEP_CANCELLED;
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_DOWNLOADED;
EXIT:
if (thid >= 0)
sceKernelWaitThreadEnd(thid, NULL, NULL);
// Unlock power timers
powerUnlock();
return sceKernelExitDeleteThread(0);
}
int network_update_thread(SceSize args, void *argp) {
sceHttpsDisableOption(SCE_HTTPS_FLAG_SERVER_VERIFY);
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");
// Only show update question if no dialog is running
if (dialog_step == DIALOG_STEP_NONE) {
// New update available
if (version > VITASHELL_VERSION) {
int major = version >> 0x18;
int minor = version >> 0x10;
char version_string[8];
sprintf(version_string, "%X.%X", major, minor);
if (version_string[3] == '0')
version_string[3] = '\0';
// Update question
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_YESNO, language_container[UPDATE_QUESTION], version_string);
dialog_step = DIALOG_STEP_UPDATE_QUESTION;
// Wait for response
while (dialog_step == DIALOG_STEP_UPDATE_QUESTION) {
sceKernelDelayThread(1000);
}
// No
if (dialog_step == DIALOG_STEP_NONE) {
return 0;
}
// Yes
return downloadProcess(version_string);
}
}
}
return sceKernelExitDeleteThread(0);
}
void 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);
}

25
network_update.h Normal file
View File

@ -0,0 +1,25 @@
/*
VitaShell
Copyright (C) 2015-2016, TheFloW
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __NETWORK_UPDATE_H__
#define __NETWORK_UPDATE_H__
int network_update_thread(SceSize args, void *argp);
int update_extract_thread(SceSize args, void *argp);
#endif

View File

@ -31,12 +31,6 @@
#include "resources/base_head_bin.h"
#define ntohl __builtin_bswap32
#define PACKAGE_PARENT "ux0:ptmp"
#define PACKAGE_DIR PACKAGE_PARENT "/pkg"
#define HEAD_BIN PACKAGE_DIR "/sce_sys/package/head.bin"
void loadScePaf() {
uint32_t ptr[0x100] = { 0 };
ptr[0] = 0;
@ -68,7 +62,7 @@ int promote(char *path) {
if (res < 0)
return res;
sceKernelDelayThread(300 * 1000);
sceKernelDelayThread(100 * 1000);
} while (state);
int result = 0;

View File

@ -19,10 +19,19 @@
#ifndef __PACKAGE_INSTALLER_H__
#define __PACKAGE_INSTALLER_H__
#define ntohl __builtin_bswap32
#define PACKAGE_PARENT "ux0:ptmp"
#define PACKAGE_DIR PACKAGE_PARENT "/pkg"
#define HEAD_BIN PACKAGE_DIR "/sce_sys/package/head.bin"
typedef struct {
char *file;
} InstallArguments;
int promote(char *path);
int makeHeadBin();
int install_thread(SceSize args_size, InstallArguments *args);
#endif

View File

@ -28,7 +28,7 @@
<frame id="frame4">
<liveitem>
<text align="left" text-align="left" word-wrap="off" ellipsis="on">
<str size="18" color="#ffffff" shadow="on">v0.9</str>
<str size="18" color="#ffffff" shadow="on">v0.91</str>
</text>
</liveitem>
</frame>

View File

@ -22,6 +22,8 @@ MOVING = "Moving..."
COPYING = "Copying..."
DELETING = "Deleting..."
INSTALLING = "Installing..."
DOWNLOADING = "Downloading..."
EXTRACTING = "Extracting..."
DELETE_FILE_QUESTION = "Are you sure you want to delete this file?"
DELETE_FOLDER_QUESTION = "Are you sure you want to delete this folder?"
DELETE_FILES_FOLDERS_QUESTION = "Are you sure you want to delete these files/folders?"
@ -30,4 +32,5 @@ INSTALL_WARNING = "This package requests extended permissio
SAVE_MODIFICATIONS = "Do you want to save your modifications?"
WIFI_ERROR = "You must use Wi-Fi to do this."
FTP_SERVER = "FTP server is now running at\ftp://%s:%i\\Press 'OK' to keep it in background.\Press 'Cancel' to disconnect."
SYS_INFO = "System software: %s\Model: 0x%08X\MAC address: %s\IP address: %s\Memory card: %s/%s"
SYS_INFO = "System software: %s\Model: 0x%08X\MAC address: %s\IP address: %s\Memory card: %s/%s"
UPDATE_QUESTION = "VitaShell %s is now available.\\Do you want to update the application?"

BIN
resources/updater_eboot.bin Normal file

Binary file not shown.

BIN
resources/updater_param.bin Normal file

Binary file not shown.

40
updater/Makefile Normal file
View File

@ -0,0 +1,40 @@
TITLE_ID = VSUPDATER
TARGET = updater
OBJS = main.o
LIBS = -lSceAppMgr_stub ../libpromoter/libScePromoterUtil_stub.a -lSceSysmodule_stub
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
CFLAGS = -Wl,-q -Wall -O3 -marm
ASFLAGS = $(CFLAGS)
all: $(TARGET).vpk
%.vpk: eboot.bin
vita-mksfoex -s TITLE_ID=$(TITLE_ID) "VitaShell Updater" param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin $@
eboot.bin: $(TARGET).velf
vita-make-fself $< $@
%.velf: %.elf
vita-elf-create $< $@ ../libpromoter/promoterutil.json
$(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
%.o: %.png
$(PREFIX)-ld -r -b binary -o $@ $^
clean:
@rm -rf $(TARGET).vpk $(TARGET).velf $(TARGET).elf $(OBJS) \
eboot.bin param.sfo
vpksend: $(TARGET).vpk
curl -T $(TARGET).vpk ftp://$(PSVITAIP):1337/ux0:/
@echo "Sent."
send: eboot.bin
curl -T eboot.bin ftp://$(PSVITAIP):1337/ux0:/app/$(TITLE_ID)/
@echo "Sent."

199
updater/main.c Normal file
View File

@ -0,0 +1,199 @@
/*
VitaShell
Copyright (C) 2015-2016, TheFloW
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <psp2/appmgr.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/io/dirent.h>
#include <psp2/io/fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../sysmodule_internal.h"
#include "../libpromoter/promoterutil.h"
#define TRANSFER_SIZE 64 * 1024
#define PACKAGE_PARENT "ux0:ptmp"
#define PACKAGE_DIR PACKAGE_PARENT "/pkg"
#define HEAD_BIN PACKAGE_DIR "/sce_sys/package/head.bin"
typedef struct SfoHeader {
uint32_t magic;
uint32_t version;
uint32_t keyofs;
uint32_t valofs;
uint32_t count;
} __attribute__((packed)) SfoHeader;
typedef struct SfoEntry {
uint16_t nameofs;
uint8_t alignment;
uint8_t type;
uint32_t valsize;
uint32_t totalsize;
uint32_t dataofs;
} __attribute__((packed)) SfoEntry;
int launchAppByUriExit(char *titleid) {
char uri[32];
sprintf(uri, "psgm:play?titleid=%s", titleid);
sceKernelDelayThread(10000);
sceAppMgrLaunchAppByUri(0xFFFFF, uri);
sceKernelDelayThread(10000);
sceAppMgrLaunchAppByUri(0xFFFFF, uri);
sceKernelExitProcess(0);
return 0;
}
int copyFile(char *src_path, char *dst_path) {
SceUID fdsrc = sceIoOpen(src_path, SCE_O_RDONLY, 0);
if (fdsrc < 0)
return fdsrc;
SceUID fddst = sceIoOpen(dst_path, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
if (fddst < 0) {
sceIoClose(fdsrc);
return fddst;
}
void *buf = malloc(TRANSFER_SIZE);
int read;
while ((read = sceIoRead(fdsrc, buf, TRANSFER_SIZE)) > 0) {
sceIoWrite(fddst, buf, read);
}
free(buf);
sceIoClose(fddst);
sceIoClose(fdsrc);
return 0;
}
void loadScePaf() {
uint32_t ptr[0x100] = { 0 };
ptr[0] = 0;
ptr[1] = (uint32_t)&ptr[0];
uint32_t scepaf_argp[] = { 0x400000, 0xEA60, 0x40000, 0, 0 };
sceSysmoduleLoadModuleInternalWithArg(0x80000008, sizeof(scepaf_argp), scepaf_argp, ptr);
}
int promote(char *path) {
int res;
loadScePaf();
res = sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_PROMOTER_UTIL);
if (res < 0)
return res;
res = scePromoterUtilityInit();
if (res < 0)
return res;
res = scePromoterUtilityPromotePkg(path, 0);
if (res < 0)
return res;
int state = 0;
do {
res = scePromoterUtilityGetState(&state);
if (res < 0)
return res;
sceKernelDelayThread(100 * 1000);
} while (state);
int result = 0;
res = scePromoterUtilityGetResult(&result);
if (res < 0)
return res;
res = scePromoterUtilityExit();
if (res < 0)
return res;
res = sceSysmoduleUnloadModuleInternal(SCE_SYSMODULE_PROMOTER_UTIL);
if (res < 0)
return res;
return result;
}
char *get_title_id(const char *filename) {
char *res = NULL;
long size = 0;
FILE *fin = NULL;
char *buf = NULL;
int i;
SfoHeader *header;
SfoEntry *entry;
fin = fopen(filename, "rb");
if (!fin)
goto cleanup;
if (fseek(fin, 0, SEEK_END) != 0)
goto cleanup;
if ((size = ftell(fin)) == -1)
goto cleanup;
if (fseek(fin, 0, SEEK_SET) != 0)
goto cleanup;
buf = calloc(1, size + 1);
if (!buf)
goto cleanup;
if (fread(buf, size, 1, fin) != 1)
goto cleanup;
header = (SfoHeader*)buf;
entry = (SfoEntry*)(buf + sizeof(SfoHeader));
for (i = 0; i < header->count; ++i, ++entry) {
const char *name = buf + header->keyofs + entry->nameofs;
const char *value = buf + header->valofs + entry->dataofs;
if (name >= buf + size || value >= buf + size)
break;
if (strcmp(name, "TITLE_ID") == 0)
res = strdup(value);
}
cleanup:
if (buf)
free(buf);
if (fin)
fclose(fin);
return res;
}
int main(int argc, const char *argv[]) {
char *titleid = get_title_id(PACKAGE_DIR "/sce_sys/param.sfo");
if (titleid && strcmp(titleid, "VITASHELL") == 0) {
copyFile(PACKAGE_DIR "/eboot.bin", "ux0:app/MLCL00001/eboot.bin");
if (promote(PACKAGE_DIR) >= 0)
launchAppByUriExit("VITASHELL");
}
return sceKernelExitProcess(0);
}

92
utils.c
View File

@ -290,8 +290,6 @@ int debugPrintf(char *text, ...) {
vsprintf(string, text, list);
va_end(list);
netdbg(string);
#ifdef ENABLE_FILE_LOGGING
SceUID fd = sceIoOpen("ux0:vitashell_log.txt", SCE_O_WRONLY | SCE_O_CREAT | SCE_O_APPEND, 0777);
if (fd >= 0) {
@ -304,88 +302,16 @@ int debugPrintf(char *text, ...) {
return 0;
}
int netdbg_init() {
int ret = 0;
#ifdef NETDBG_ENABLE
SceNetSockaddrIn server;
SceNetInitParam initparam;
SceUShort16 port = NETDBG_DEFAULT_PORT;
int launchAppByUriExit(char *titleid) {
char uri[32];
sprintf(uri, "psgm:play?titleid=%s", titleid);
#ifdef NETDBG_PORT
port = NETDBG_PORT;
#endif
sceKernelDelayThread(10000);
sceAppMgrLaunchAppByUri(0xFFFFF, uri);
sceKernelDelayThread(10000);
sceAppMgrLaunchAppByUri(0xFFFFF, uri);
/* Init Net */
ret = sceNetShowNetstat();
if (ret == SCE_NET_ERROR_ENOTINIT) {
net_memory = malloc(NET_INIT_SIZE);
initparam.memory = net_memory;
initparam.size = NET_INIT_SIZE;
initparam.flags = 0;
ret = net_init = sceNetInit(&initparam);
if (net_init < 0)
goto error_netinit;
} else if (ret != 0) {
goto error_netstat;
}
server.sin_len = sizeof(server);
server.sin_family = SCE_NET_AF_INET;
sceNetInetPton(SCE_NET_AF_INET, NETDBG_IP, &server.sin_addr);
server.sin_port = sceNetHtons(port);
memset(server.sin_zero, 0, sizeof(server.sin_zero));
ret = netdbg_sock = sceNetSocket("VitaShellNetDbg", SCE_NET_AF_INET, SCE_NET_SOCK_STREAM, 0);
if (netdbg_sock < 0)
goto error_netsock;
ret = sceNetConnect(netdbg_sock, (SceNetSockaddr *)&server, sizeof(server));
if (ret < 0)
goto error_netconnect;
sceKernelExitProcess(0);
return 0;
error_netconnect:
sceNetSocketClose(netdbg_sock);
netdbg_sock = -1;
error_netsock:
if (net_init == 0) {
sceNetTerm();
net_init = -1;
}
error_netinit:
if (net_memory) {
free(net_memory);
net_memory = NULL;
}
error_netstat:
#endif
return ret;
}
void netdbg_fini() {
if (netdbg_sock > 0) {
sceNetSocketClose(netdbg_sock);
if (net_init == 0)
sceNetTerm();
if (net_memory)
free(net_memory);
netdbg_sock = -1;
net_init = -1;
net_memory = NULL;
}
}
int netdbg(const char *text, ...) {
va_list list;
char string[512];
if (netdbg_sock > 0) {
va_start(list, text);
vsprintf(string, text, list);
va_end(list);
return sceNetSend(netdbg_sock, string, strlen(string), 0);
}
return -1;
}
}

View File

@ -28,9 +28,6 @@
#define ANALOG_THRESHOLD 64
#define ANALOG_SENSITIVITY 16
#define NET_INIT_SIZE 1 * 1024 * 1024
#define NETDBG_DEFAULT_PORT 9023
enum {
SCE_CTRL_RIGHT_ANALOG_UP = 0x0020000,
SCE_CTRL_RIGHT_ANALOG_RIGHT = 0x0040000,
@ -74,8 +71,6 @@ int randomNumber(int low, int high);
int debugPrintf(char *text, ...);
int netdbg_init();
void netdbg_fini();
int netdbg(const char *text, ...);
int launchAppByUriExit(char *titleid);
#endif