forked from TheOfficialFloW/VitaShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
207 lines (167 loc) · 7.41 KB
/
Copy pathinit.c
File metadata and controls
207 lines (167 loc) · 7.41 KB
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
/*
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 "init.h"
#include "file.h"
#include "utils.h"
extern unsigned char _binary_resources_ftp_png_start;
extern unsigned char _binary_resources_ftp_png_size;
extern unsigned char _binary_resources_dialog_png_start;
extern unsigned char _binary_resources_dialog_png_size;
extern unsigned char _binary_resources_context_png_start;
extern unsigned char _binary_resources_context_png_size;
extern unsigned char _binary_resources_battery_png_start;
extern unsigned char _binary_resources_battery_png_size;
extern unsigned char _binary_resources_battery_bar_red_png_start;
extern unsigned char _binary_resources_battery_bar_red_png_size;
extern unsigned char _binary_resources_battery_bar_green_png_start;
extern unsigned char _binary_resources_battery_bar_green_png_size;
extern unsigned char _binary_resources_theme_txt_start;
extern unsigned char _binary_resources_theme_txt_size;
extern unsigned char _binary_resources_colors_txt_start;
extern unsigned char _binary_resources_colors_txt_size;
extern unsigned char _binary_resources_english_us_txt_start;
extern unsigned char _binary_resources_english_us_txt_size;
extern unsigned char _binary_resources_headphone_png_start;
extern unsigned char _binary_resources_audio_previous_png_start;
extern unsigned char _binary_resources_audio_pause_png_start;
extern unsigned char _binary_resources_audio_play_png_start;
extern unsigned char _binary_resources_audio_next_png_start;
static DefaultFile default_files[] = {
{ "ux0:VitaShell/language/english_us.txt", (void *)&_binary_resources_english_us_txt_start, (int)&_binary_resources_english_us_txt_size },
{ "ux0:VitaShell/theme/theme.txt", (void *)&_binary_resources_theme_txt_start, (int)&_binary_resources_theme_txt_size },
{ "ux0:VitaShell/theme/Default/colors.txt", (void *)&_binary_resources_colors_txt_start, (int)&_binary_resources_colors_txt_size },
{ "ux0:VitaShell/theme/Default/ftp.png", (void *)&_binary_resources_ftp_png_start, (int)&_binary_resources_ftp_png_size },
{ "ux0:VitaShell/theme/Default/dialog.png", (void *)&_binary_resources_dialog_png_start, (int)&_binary_resources_dialog_png_size },
{ "ux0:VitaShell/theme/Default/context.png", (void *)&_binary_resources_context_png_start, (int)&_binary_resources_context_png_size },
{ "ux0:VitaShell/theme/Default/battery.png", (void *)&_binary_resources_battery_png_start, (int)&_binary_resources_battery_png_size },
{ "ux0:VitaShell/theme/Default/battery_bar_red.png", (void *)&_binary_resources_battery_bar_red_png_start, (int)&_binary_resources_battery_bar_red_png_size },
{ "ux0:VitaShell/theme/Default/battery_bar_green.png", (void *)&_binary_resources_battery_bar_green_png_start, (int)&_binary_resources_battery_bar_green_png_size },
};
vita2d_pgf *font = NULL;
char font_size_cache[256];
vita2d_texture *headphone_image = NULL, *audio_previous_image = NULL, *audio_pause_image = NULL, *audio_play_image = NULL, *audio_next_image = NULL;
// System params
int language = 0, enter_button = 0, date_format = 0, time_format = 0;
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);
if (enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE) {
SCE_CTRL_ENTER = SCE_CTRL_CIRCLE;
SCE_CTRL_CANCEL = SCE_CTRL_CROSS;
}
// 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);
}
void finishSceAppUtil() {
// Unmount
sceAppUtilPhotoUmount();
sceAppUtilMusicUmount();
// Shutdown AppUtil
sceAppUtilShutdown();
}
void initVita2dLib() {
vita2d_init();
font = vita2d_load_default_pgf();
// Font size cache
int i;
for (i = 0; i < 256; i++) {
char character[2];
character[0] = i;
character[1] = '\0';
font_size_cache[i] = vita2d_pgf_text_width(font, FONT_SIZE, character);
}
headphone_image = vita2d_load_PNG_buffer(&_binary_resources_headphone_png_start);
audio_previous_image = vita2d_load_PNG_buffer(&_binary_resources_audio_previous_png_start);
audio_pause_image = vita2d_load_PNG_buffer(&_binary_resources_audio_pause_png_start);
audio_play_image = vita2d_load_PNG_buffer(&_binary_resources_audio_play_png_start);
audio_next_image = vita2d_load_PNG_buffer(&_binary_resources_audio_next_png_start);
}
void finishVita2dLib() {
vita2d_free_texture(headphone_image);
vita2d_free_texture(audio_previous_image);
vita2d_free_texture(audio_pause_image);
vita2d_free_texture(audio_play_image);
vita2d_free_texture(audio_next_image);
vita2d_free_pgf(font);
vita2d_fini();
font = NULL;
headphone_image = NULL;
audio_previous_image = NULL;
audio_pause_image = NULL;
audio_play_image = NULL;
audio_next_image = NULL;
}
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);
// Load modules
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_PGF) != SCE_SYSMODULE_LOADED)
sceSysmoduleLoadModule(SCE_SYSMODULE_PGF);
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) != SCE_SYSMODULE_LOADED)
sceSysmoduleLoadModule(SCE_SYSMODULE_NET);
// Init
initSceAppUtil();
initVita2dLib();
// Init netdbg
netdbg_init();
// Init power tick thread
initPowerTickThread();
// Make VitaShell folders
sceIoMkdir("ux0:VitaShell", 0777);
sceIoMkdir("ux0:VitaShell/language", 0777);
sceIoMkdir("ux0:VitaShell/theme", 0777);
sceIoMkdir("ux0:VitaShell/theme/Default", 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)
WriteFile(default_files[i].path, default_files[i].buffer, default_files[i].size);
}
}
void finishVitaShell() {
// Finish netdbg
netdbg_fini();
// Finish
finishVita2dLib();
finishSceAppUtil();
// Unload modules
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) == SCE_SYSMODULE_LOADED)
sceSysmoduleUnloadModule(SCE_SYSMODULE_NET);
if (sceSysmoduleIsLoaded(SCE_SYSMODULE_PGF) == SCE_SYSMODULE_LOADED)
sceSysmoduleUnloadModule(SCE_SYSMODULE_PGF);
}