-
Notifications
You must be signed in to change notification settings - Fork 15
/
language.c
109 lines (89 loc) · 3.19 KB
/
language.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
/*
* this file is part of Game Categories Lite
*
* Copyright (C) 2009 Bubbletune
* Copyright (C) 2011 Codestation
*
* 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 <pspsdk.h>
#include <pspkernel.h>
#include <string.h>
#include <pspreg.h>
#include "language.h"
#include "categories_lite.h"
#include "category_lite_lang.h"
#include "utils.h"
#include "psppaf.h"
static const char *lang[] = { "ja", "en", "fr", "es", "de", "it", "nl", "pt", "ru", "ko", "ch1", "ch2" };
int lang_width[] = {1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1};
LanguageContainer lang_container;
int LoadLanguageContainer(void *data, int size)
{
int res, j;
int i = 0;
char *p = data;
char line[256];
do {
sce_paf_private_memset(line, 0, sizeof(line));
if ((res = GetLine(p, size, line)) > 0) {
if (((char **) &lang_container)[i]) {
sce_paf_private_free(((char **) &lang_container)[i]);
}
for (j = 0; j < sce_paf_private_strlen(line); j++) {
if (line[j] == 0x5c) {
line[j] = '\n';
}
}
((char **) &lang_container)[i] = sce_paf_private_malloc(sce_paf_private_strlen(line) + 1);
sce_paf_private_strcpy(((char **) &lang_container)[i], line);
i++;
}
size -= res;
p += res;
} while (res > 0 && i < (int)(sizeof(lang_container) / sizeof(char **)));
if (i == (sizeof(lang_container) / sizeof(char **))) {
return 1;
}
return 0;
}
void LoadLanguage(int id, int location)
{
int loaded = 0;
union _d {
char *temp;
u32 *magic;
} d;
if (id >= 0 && id < (int)(sizeof(lang) / sizeof(char *))) {
char path[128];
sce_paf_private_snprintf(path, 128, "xx0:/seplugins/category_lite_%s.txt", lang[id]);
SET_DEVICENAME(path, location);
SceUID fd = sceIoOpen(path, PSP_O_RDONLY, 0);
if (fd >= 0) {
int size = sceIoLseek(fd, 0, PSP_SEEK_END);
sceIoLseek(fd, 0, PSP_SEEK_SET);
d.temp = (char *)sce_paf_private_malloc(size);
sceIoRead(fd, d.temp, size);
// skip unicode BOM (if present)
loaded = ISSET(*d.magic & 0xFFFFFF, 0xBFBBEF) ? 3 : 0;
loaded = LoadLanguageContainer(d.temp + loaded, size - loaded);
sce_paf_private_free(d.temp);
}
}
if (!loaded) {
// not doing unicode BOM check here, all the source files must not
// contain the BOM without exceptions
LoadLanguageContainer(category_lite_lang, size_category_lite_lang);
}
}