forked from TheOfficialFloW/VitaShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
452 lines (378 loc) · 16.7 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
VitaShell
Copyright (C) 2015-2018, 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 "browser.h"
#include "init.h"
#include "file.h"
#include "package_installer.h"
#include "utils.h"
#include "qr.h"
#include "rif.h"
#include "audio/vita_audio.h"
INCLUDE_EXTERN_RESOURCE(english_us_txt);
INCLUDE_EXTERN_RESOURCE(theme_txt);
INCLUDE_EXTERN_RESOURCE(default_colors_txt);
INCLUDE_EXTERN_RESOURCE(default_archive_icon_png);
INCLUDE_EXTERN_RESOURCE(default_audio_icon_png);
INCLUDE_EXTERN_RESOURCE(default_battery_bar_charge_png);
INCLUDE_EXTERN_RESOURCE(default_battery_bar_green_png);
INCLUDE_EXTERN_RESOURCE(default_battery_bar_red_png);
INCLUDE_EXTERN_RESOURCE(default_battery_png);
INCLUDE_EXTERN_RESOURCE(default_cover_png);
INCLUDE_EXTERN_RESOURCE(default_fastforward_png);
INCLUDE_EXTERN_RESOURCE(default_fastrewind_png);
INCLUDE_EXTERN_RESOURCE(default_file_icon_png);
INCLUDE_EXTERN_RESOURCE(default_folder_icon_png);
INCLUDE_EXTERN_RESOURCE(default_ftp_png);
INCLUDE_EXTERN_RESOURCE(default_image_icon_png);
INCLUDE_EXTERN_RESOURCE(default_pause_png);
INCLUDE_EXTERN_RESOURCE(default_play_png);
INCLUDE_EXTERN_RESOURCE(default_sfo_icon_png);
INCLUDE_EXTERN_RESOURCE(default_text_icon_png);
INCLUDE_EXTERN_RESOURCE(default_file_symlink_icon_png);
INCLUDE_EXTERN_RESOURCE(default_folder_symlink_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_colors_txt);
INCLUDE_EXTERN_RESOURCE(electron_archive_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_audio_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_battery_bar_charge_png);
INCLUDE_EXTERN_RESOURCE(electron_battery_bar_green_png);
INCLUDE_EXTERN_RESOURCE(electron_battery_bar_red_png);
INCLUDE_EXTERN_RESOURCE(electron_battery_png);
INCLUDE_EXTERN_RESOURCE(electron_bg_audioplayer_png);
INCLUDE_EXTERN_RESOURCE(electron_bg_browser_png);
INCLUDE_EXTERN_RESOURCE(electron_bg_hexeditor_png);
INCLUDE_EXTERN_RESOURCE(electron_bg_photoviewer_png);
INCLUDE_EXTERN_RESOURCE(electron_bg_texteditor_png);
INCLUDE_EXTERN_RESOURCE(electron_context_png);
INCLUDE_EXTERN_RESOURCE(electron_context_more_png);
INCLUDE_EXTERN_RESOURCE(electron_cover_png);
INCLUDE_EXTERN_RESOURCE(electron_dialog_png);
INCLUDE_EXTERN_RESOURCE(electron_fastforward_png);
INCLUDE_EXTERN_RESOURCE(electron_fastrewind_png);
INCLUDE_EXTERN_RESOURCE(electron_file_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_folder_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_ftp_png);
INCLUDE_EXTERN_RESOURCE(electron_image_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_pause_png);
INCLUDE_EXTERN_RESOURCE(electron_play_png);
INCLUDE_EXTERN_RESOURCE(electron_sfo_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_text_icon_png);
INCLUDE_EXTERN_RESOURCE(electron_settings_png);
INCLUDE_EXTERN_RESOURCE(umass_skprx);
extern unsigned char _binary_build_modules_kernel_kernel_skprx_start;
extern unsigned char _binary_build_modules_kernel_kernel_skprx_size;
extern unsigned char _binary_build_modules_user_user_suprx_start;
extern unsigned char _binary_build_modules_user_user_suprx_size;
extern unsigned char _binary_build_modules_patch_patch_skprx_start;
extern unsigned char _binary_build_modules_patch_patch_skprx_size;
extern unsigned char _binary_build_modules_usbdevice_usbdevice_skprx_start;
extern unsigned char _binary_build_modules_usbdevice_usbdevice_skprx_size;
#define DEFAULT_FILE(path, name, replace) { path, (void *)&_binary_resources_##name##_start, (int)&_binary_resources_##name##_size, replace }
static DefaultFile default_files[] = {
DEFAULT_FILE("ux0:VitaShell/language/english_us.txt", english_us_txt, 0),
DEFAULT_FILE("ux0:VitaShell/theme/theme.txt", theme_txt, 0),
DEFAULT_FILE("ux0:VitaShell/theme/Default/colors.txt", default_colors_txt, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/archive_icon.png", default_archive_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/audio_icon.png", default_audio_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/battery.png", default_battery_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/battery_bar_charge.png", default_battery_bar_charge_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/battery_bar_green.png", default_battery_bar_green_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/battery_bar_red.png", default_battery_bar_red_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/cover.png", default_cover_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/fastforward.png", default_fastforward_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/fastrewind.png", default_fastrewind_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/file_icon.png", default_file_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/file_symlink_icon.png",default_file_symlink_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/folder_icon.png", default_folder_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/folder_symlink_icon.png",default_folder_symlink_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/ftp.png", default_ftp_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/image_icon.png", default_image_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/pause.png", default_pause_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/play.png", default_play_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/sfo_icon.png", default_sfo_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Default/text_icon.png", default_text_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/colors.txt", electron_colors_txt, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/archive_icon.png", electron_archive_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/audio_icon.png", electron_audio_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/battery.png", electron_battery_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/battery_bar_charge.png", electron_battery_bar_charge_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/battery_bar_green.png", electron_battery_bar_green_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/battery_bar_red.png", electron_battery_bar_red_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/bg_audioplayer.png", electron_bg_audioplayer_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/bg_browser.png", electron_bg_browser_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/bg_hexeditor.png", electron_bg_hexeditor_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/bg_photoviewer.png", electron_bg_photoviewer_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/bg_texteditor.png", electron_bg_texteditor_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/context.png", electron_context_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/context_more.png", electron_context_more_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/cover.png", electron_cover_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/dialog.png", electron_dialog_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/fastforward.png", electron_fastforward_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/fastrewind.png", electron_fastrewind_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/file_icon.png", electron_file_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/folder_icon.png", electron_folder_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/ftp.png", electron_ftp_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/image_icon.png", electron_image_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/pause.png", electron_pause_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/play.png", electron_play_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/sfo_icon.png", electron_sfo_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/text_icon.png", electron_text_icon_png, 1),
DEFAULT_FILE("ux0:VitaShell/theme/Electron/settings.png", electron_settings_png, 1),
DEFAULT_FILE("ux0:VitaShell/module/umass.skprx", umass_skprx, 1),
{ "ux0:VitaShell/module/kernel.skprx", (void *)&_binary_build_modules_kernel_kernel_skprx_start,
(int)&_binary_build_modules_kernel_kernel_skprx_size, 1 },
{ "ux0:VitaShell/module/user.suprx", (void *)&_binary_build_modules_user_user_suprx_start,
(int)&_binary_build_modules_user_user_suprx_size, 1 },
{ "ux0:VitaShell/module/patch.skprx", (void *)&_binary_build_modules_patch_patch_skprx_start,
(int)&_binary_build_modules_patch_patch_skprx_size, 1 },
{ "ux0:VitaShell/module/usbdevice.skprx", (void *)&_binary_build_modules_usbdevice_usbdevice_skprx_start,
(int)&_binary_build_modules_usbdevice_usbdevice_skprx_size, 1 },
};
char vitashell_titleid[12];
int is_safe_mode = 0;
SceUID patch_modid = -1, kernel_modid = -1, user_modid = -1;
// System params
int language = 0, enter_button = 0, date_format = 0, time_format = 0;
int isSafeMode() {
return is_safe_mode;
}
static void initSceAppUtil() {
// Init SceAppUtil
SceAppUtilInitParam init_param;
SceAppUtilBootParam boot_param;
memset(&init_param, 0, sizeof(SceAppUtilInitParam));
memset(&boot_param, 0, sizeof(SceAppUtilBootParam));
sceAppUtilInit(&init_param, &boot_param);
// Mount
sceAppUtilMusicMount();
sceAppUtilPhotoMount();
// System params
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, &language);
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_ENTER_BUTTON, &enter_button);
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_DATE_FORMAT, &date_format);
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_TIME_FORMAT, &time_format);
// Set common dialog config
SceCommonDialogConfigParam config;
sceCommonDialogConfigParamInit(&config);
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, (int *)&config.language);
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_ENTER_BUTTON, (int *)&config.enterButtonAssign);
sceCommonDialogSetConfigParam(&config);
}
static void finishSceAppUtil() {
// Unmount
sceAppUtilPhotoUmount();
sceAppUtilMusicUmount();
// Shutdown AppUtil
sceAppUtilShutdown();
}
static int isKoreanChar(unsigned int c) {
unsigned short ch = c;
// Hangul compatibility jamo block
if (0x3130 <= ch && ch <= 0x318F) {
return 1;
}
// Hangul syllables block
if (0xAC00 <= ch && ch <= 0xD7AF) {
return 1;
}
// Korean won sign
if (ch == 0xFFE6) {
return 1;
}
return 0;
}
static int isLatinChar(unsigned int c) {
unsigned short ch = c;
// Basic latin block + latin-1 supplement block
if (ch <= 0x00FF) {
return 1;
}
// Cyrillic block
if (0x0400 <= ch && ch <= 0x04FF) {
return 1;
}
return 0;
}
vita2d_pgf *loadSystemFonts() {
vita2d_system_pgf_config configs[] = {
{ SCE_FONT_LANGUAGE_KOREAN, isKoreanChar },
{ SCE_FONT_LANGUAGE_LATIN, isLatinChar },
{ SCE_FONT_LANGUAGE_DEFAULT, NULL },
};
return vita2d_load_system_pgf(3, configs);
}
static void initVita2dLib() {
vita2d_init();
}
static void finishVita2dLib() {
vita2d_free_pgf(font);
vita2d_fini();
font = NULL;
}
static int initSQLite() {
return sqlite_init();
}
static int finishSQLite() {
return sqlite_exit();
}
#define NET_MEMORY_SIZE (4 * 1024 * 1024)
static char *net_memory = NULL;
static void initNet() {
net_memory = malloc(NET_MEMORY_SIZE);
SceNetInitParam param;
param.memory = net_memory;
param.size = NET_MEMORY_SIZE;
param.flags = 0;
sceNetInit(¶m);
sceNetCtlInit();
sceSslInit(300 * 1024);
sceHttpInit(40 * 1024);
sceHttpsDisableOption(SCE_HTTPS_FLAG_SERVER_VERIFY);
sceNetAdhocInit();
SceNetAdhocctlAdhocId adhocId;
memset(&adhocId, 0, sizeof(SceNetAdhocctlAdhocId));
adhocId.type = SCE_NET_ADHOCCTL_ADHOCTYPE_RESERVED;
memcpy(&adhocId.data[0], VITASHELL_TITLEID, SCE_NET_ADHOCCTL_ADHOCID_LEN);
sceNetAdhocctlInit(&adhocId);
}
static void finishNet() {
sceNetAdhocctlTerm();
sceNetAdhocTerm();
sceSslTerm();
sceHttpTerm();
sceNetCtlTerm();
sceNetTerm();
free(net_memory);
}
void installDefaultFiles() {
// Make VitaShell folders
sceIoMkdir("ux0:VitaShell", 0777);
sceIoMkdir("ux0:VitaShell/internal", 0777);
sceIoMkdir("ux0:VitaShell/language", 0777);
sceIoMkdir("ux0:VitaShell/module", 0777);
sceIoMkdir("ux0:VitaShell/theme", 0777);
sceIoMkdir("ux0:VitaShell/theme/Default", 0777);
sceIoMkdir("ux0:VitaShell/theme/Electron", 0777);
// Write default files if they don't exist
int i;
for (i = 0; i < (sizeof(default_files) / sizeof(DefaultFile)); i++) {
SceIoStat stat;
memset(&stat, 0, sizeof(stat));
if (sceIoGetstat(default_files[i].path, &stat) < 0 || (default_files[i].replace && (int)stat.st_size != default_files[i].size))
WriteFile(default_files[i].path, default_files[i].buffer, default_files[i].size);
}
}
void initVitaShell() {
// Set CPU to 444mhz
scePowerSetArmClockFrequency(444);
// Init SceShellUtil events
sceShellUtilInitEvents(0);
// Prevent automatic CMA connection
sceShellUtilLock(SCE_SHELL_UTIL_LOCK_TYPE_USB_CONNECTION);
// Get titleid
memset(vitashell_titleid, 0, sizeof(vitashell_titleid));
sceAppMgrAppParamGetString(sceKernelGetProcessId(), 12, vitashell_titleid, sizeof(vitashell_titleid));
// Allow writing to ux0:app/VITASHELL
sceAppMgrUmount("app0:");
sceAppMgrUmount("savedata0:");
// Is safe mode
if (sceIoDevctl("ux0:", 0x3001, NULL, 0, NULL, 0) == 0x80010030)
is_safe_mode = 1;
// Set sampling mode
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
// Load modules
sceSysmoduleLoadModule(SCE_SYSMODULE_VIDEO_EXPORT);
sceSysmoduleLoadModule(SCE_SYSMODULE_PGF);
sceSysmoduleLoadModule(SCE_SYSMODULE_MUSIC_EXPORT);
sceSysmoduleLoadModule(SCE_SYSMODULE_PHOTO_EXPORT);
sceSysmoduleLoadModule(SCE_SYSMODULE_NET);
sceSysmoduleLoadModule(SCE_SYSMODULE_HTTPS);
sceSysmoduleLoadModule(SCE_SYSMODULE_PSPNET_ADHOC);
sceSysmoduleLoadModule(SCE_SYSMODULE_SQLITE);
// Init
vitaAudioInit(0x40);
initVita2dLib();
initSceAppUtil();
initNet();
initQR();
initSQLite();
// Init power tick thread
initPowerTickThread();
// Delete VitaShell updater if available
if (checkAppExist("VSUPDATER")) {
deleteApp("VSUPDATER");
}
// Install default files
installDefaultFiles();
// Load modules
int search_unk[2];
SceUID search_modid;
search_modid = _vshKernelSearchModuleByName("VitaShellPatch", search_unk);
if(search_modid < 0) {
patch_modid = taiLoadKernelModule("ux0:VitaShell/module/patch.skprx", 0, NULL);
if (patch_modid >= 0) {
int res = taiStartKernelModule(patch_modid, 0, NULL, 0, NULL, NULL);
if (res < 0)
taiStopUnloadKernelModule(patch_modid, 0, NULL, 0, NULL, NULL);
}
}
search_modid = _vshKernelSearchModuleByName("VitaShellKernel2", search_unk);
if(search_modid < 0) {
kernel_modid = taiLoadKernelModule("ux0:VitaShell/module/kernel.skprx", 0, NULL);
if (kernel_modid >= 0) {
int res = taiStartKernelModule(kernel_modid, 0, NULL, 0, NULL, NULL);
if (res < 0)
taiStopUnloadKernelModule(kernel_modid, 0, NULL, 0, NULL, NULL);
}
}
user_modid = sceKernelLoadStartModule("ux0:VitaShell/module/user.suprx", 0, NULL, 0, NULL, NULL);
// clear up recent folder frequently
SceIoStat stat;
SceDateTime now;
sceRtcGetCurrentClock(&now, 0);
int res = sceIoGetstat(VITASHELL_RECENT_PATH, &stat);
if (res >= 0) {
if (now.year * 365 + now.day - stat.st_ctime.year * 365 - stat.st_ctime.day
>= VITASHELL_RECENT_PATH_DELETE_INTERVAL_DAYS) {
removePath(VITASHELL_RECENT_PATH, 0);
}
}
if (!checkFolderExist(VITASHELL_BOOKMARKS_PATH)) {
sceIoMkdir(VITASHELL_BOOKMARKS_PATH, 0777);
}
if (!checkFolderExist(VITASHELL_RECENT_PATH)) {
sceIoMkdir(VITASHELL_RECENT_PATH, 0777);
}
time_last_recent_files = 0;
time_last_bookmarks = 0;
}
void finishVitaShell() {
// Finish
finishSQLite();
finishNet();
finishSceAppUtil();
finishVita2dLib();
finishQR();
vitaAudioShutdown();
// Unload modules
sceSysmoduleUnloadModule(SCE_SYSMODULE_SQLITE);
sceSysmoduleUnloadModule(SCE_SYSMODULE_PSPNET_ADHOC);
sceSysmoduleUnloadModule(SCE_SYSMODULE_HTTPS);
sceSysmoduleUnloadModule(SCE_SYSMODULE_NET);
sceSysmoduleUnloadModule(SCE_SYSMODULE_PHOTO_EXPORT);
sceSysmoduleUnloadModule(SCE_SYSMODULE_MUSIC_EXPORT);
sceSysmoduleUnloadModule(SCE_SYSMODULE_PGF);
sceSysmoduleUnloadModule(SCE_SYSMODULE_VIDEO_EXPORT);
}