mirror of https://github.com/sm64pc/sm64pc.git
Fixed language json loader on Windows
This commit is contained in:
parent
a6eb06e5ea
commit
646c2e08c9
|
@ -5,57 +5,75 @@
|
|||
#include <string.h>
|
||||
#include "dialog_ids.h"
|
||||
#include "game/ingame_menu.h"
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include "libs/dir_utils.h"
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
struct DialogEntry* * dialogPool;
|
||||
#define _READFILE_GUESS 256
|
||||
|
||||
char* load_file(char const* path) {
|
||||
char* buffer = 0;
|
||||
long length = 0;
|
||||
FILE * f = fopen (path, "rb");
|
||||
#define SPANISH "./res/texts/es.json"
|
||||
#define ENGLISH "./res/texts/us.json"
|
||||
|
||||
if (f) {
|
||||
fseek (f, 0, SEEK_END);
|
||||
length = ftell (f);
|
||||
fseek (f, 0, SEEK_SET);
|
||||
buffer = (char*) malloc((length+1)*sizeof(char));
|
||||
if (buffer) {
|
||||
fread(buffer, sizeof(char), length, f);
|
||||
}
|
||||
fclose(f);
|
||||
buffer[length] = '\0';
|
||||
return buffer;
|
||||
char* read_file(char* name){
|
||||
FILE* file;
|
||||
file = fopen(name, "r");
|
||||
|
||||
if(!file)
|
||||
return NULL;
|
||||
|
||||
char* result = malloc(sizeof(char) * _READFILE_GUESS + 1);
|
||||
|
||||
if(result == NULL)
|
||||
return NULL;
|
||||
|
||||
size_t pos = 0;
|
||||
size_t capacity = _READFILE_GUESS;
|
||||
char ch;
|
||||
|
||||
while((ch = getc(file)) != EOF){
|
||||
result[pos++] = ch;
|
||||
|
||||
if(pos >= capacity){
|
||||
capacity += _READFILE_GUESS;
|
||||
result = realloc(result, sizeof(char) * capacity + 1);
|
||||
if(result == NULL)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
fclose(file);
|
||||
result = realloc(result, sizeof(char) * pos);
|
||||
if(result == NULL)
|
||||
return NULL;
|
||||
result[pos] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void preloadTexts(){
|
||||
|
||||
char * cwd = "/home/alex/Documents/Projects/Render96/Render96ex - FastBuild/build/us_pc";
|
||||
//getcwd(cwd, sizeof(cwd));
|
||||
#ifndef WIN32
|
||||
char * file = "/res/texts/es.json";
|
||||
#else
|
||||
char * file = "\\res\\texts\\es.json";
|
||||
#endif
|
||||
char * file = ENGLISH;
|
||||
|
||||
char * language_file = malloc((strlen(cwd) + strlen(file)) * sizeof(char));
|
||||
strcpy(language_file, "");
|
||||
strcat(language_file, cwd);
|
||||
strcat(language_file, file);
|
||||
#ifndef WIN32
|
||||
char * language_file = realpath(file, NULL);
|
||||
#else
|
||||
char * language_file = malloc(_MAX_PATH * sizeof(char));
|
||||
_fullpath(language_file, file, _MAX_PATH );
|
||||
#endif
|
||||
|
||||
printf("Loading File: %s\n", language_file);
|
||||
|
||||
char * jsonTxt = load_file( language_file );
|
||||
if(jsonTxt == NULL) return;
|
||||
char * jsonTxt = read_file(language_file);
|
||||
|
||||
cJSON *json = cJSON_Parse(jsonTxt);
|
||||
if (json == NULL) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
|
||||
if (error_ptr != NULL) {
|
||||
fprintf(stderr, "Error before: %s\n", error_ptr);
|
||||
}else{
|
||||
fprintf(stderr, "Error loading the JSON file\n");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -96,7 +114,8 @@ void preloadTexts(){
|
|||
dialogPool[id] = entry;
|
||||
free(dialogTxt);
|
||||
}
|
||||
free(jsonTxt);
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
|
||||
void alloc_dialog_pool(void){
|
||||
|
|
|
@ -11,7 +11,7 @@ struct Character charmap[340] = {
|
|||
{"V", 0x1F}, {"W", 0x20}, {"W", 0x20}, {"X", 0x21}, {"X", 0x21}, {"Y", 0x22}, {"Y", 0x22}, {"Z", 0x23}, {"Z", 0x23},
|
||||
{"a", 0x24}, {"b", 0x25}, {"c", 0x26}, {"d", 0x27}, {"e", 0x28}, {"f", 0x29}, {"g", 0x2A}, {"h", 0x2B}, {"i", 0x2C},
|
||||
{"j", 0x2D}, {"k", 0x2E}, {"l", 0x2F}, {"m", 0x30}, {"n", 0x31}, {"o", 0x32}, {"p", 0x33}, {"q", 0x34}, {"r", 0x35},
|
||||
{"s", 0x36}, {"t", 0x37}, {"u", 0x38}, {"v", 0x39}, {"w", 0x3A}, {"x", 0x3B}, {"y", 0x3C}, {"z", 0x3D}, {"\\", 0x3E},
|
||||
{"s", 0x36}, {"t", 0x37}, {"u", 0x38}, {"v", 0x39}, {"w", 0x3A}, {"x", 0x3B}, {"y", 0x3C}, {"z", 0x3D}, {"'", 0x3E},
|
||||
{".", 0x3F}, {"☺", 0x41}, {"あ", 0x40}, {"い", 0x41}, {"う", 0x42}, {"え", 0x43}, {"お", 0x44}, {"か", 0x45}, {"き", 0x46},
|
||||
{"く", 0x47}, {"け", 0x48}, {"こ", 0x49}, {"さ", 0x4A}, {"し", 0x4B}, {"す", 0x4C}, {"せ", 0x4D}, {"そ", 0x4E}, {"た", 0x4F},
|
||||
{"ち", 0x50}, {"つ", 0x51}, {"て", 0x52}, {"と", 0x53}, {"な", 0x54}, {"に", 0x55}, {"ぬ", 0x56}, {"ね", 0x57}, {"の", 0x58},
|
||||
|
@ -44,7 +44,7 @@ struct Character charmap[340] = {
|
|||
struct Character getCharacter(char* ch){
|
||||
struct Character tmp = {NULL, 0};
|
||||
for(s32 cmid = 0; cmid < 340; cmid++){
|
||||
if(strcmp(charmap[cmid].txt, ch) == 0) {
|
||||
if(strncmp(charmap[cmid].txt, ch, strlen(charmap[cmid].txt)) == 0) {
|
||||
tmp = charmap[cmid];
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "types.h"
|
||||
|
||||
struct Character{
|
||||
char * txt;
|
||||
char txt[3];
|
||||
s32 value;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue