-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_prefs.cpp
99 lines (85 loc) · 2.35 KB
/
echo_prefs.cpp
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
// echo_prefs.cpp
/*
This file is part of L-Echo.
L-Echo 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.
L-Echo 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 L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/
#include "echo_prefs.h"
#include "echo_error.h"
#include "echo_debug.h"
#include "echo_ingame_loader.h"
#include "echo_platform.h"
#include "echo_xml.h"
#ifndef __ECHO_NDS_PREFS__
#define __ECHO_NDS_PREFS__
#define HAND_ATTR_NAME "handedness"
#define HAND_LEFT_VALUE "left"
#define HAND_RIGHT_VALUE "right"
STATUS open_prefs(echo_xml** document)
{
char** path = new(char*);
if(echo_prefsfile(path) == WIN)
{
ECHO_PRINT("prefs path: %s\n", *path);
const STATUS result = echo_xml_load_file(document, *path);
delete path;
return(result);
}
delete path;
return(FAIL);
}
STATUS get_hand(echo_xml* document, HAND* handedness)
{
char** attr = new(char*);
echo_xml_element** root = new(echo_xml_element*);
if(echo_xml_get_root(document, root) == WIN &&
echo_xml_get_attribute(*root, HAND_ATTR_NAME, attr) == WIN)
{
if(!strcmp(*attr, HAND_LEFT_VALUE))
{
*handedness = LEFT_HAND;
delete root;
delete attr;
return(WIN);
}
else if(!strcmp(*attr, HAND_RIGHT_VALUE))
{
*handedness = RIGHT_HAND;
delete root;
delete attr;
return(WIN);
}
}
delete root;
delete attr;
return(FAIL);
}
STATUS set_hand(echo_xml* document, HAND handedness)
{
echo_xml_element** root = new(echo_xml_element*);
if(echo_xml_get_root(document, root) == WIN &&
echo_xml_set_attribute(*root, HAND_ATTR_NAME
, handedness == LEFT_HAND ? HAND_LEFT_VALUE : HAND_RIGHT_VALUE))
{
delete root;
return(WIN);
}
delete root;
return(FAIL);
}
STATUS close_prefs(echo_xml* document)
{
if(echo_xml_save_file(document) == WIN &&
echo_xml_delete_file(document) == WIN)
return(WIN);
return(FAIL);
}
#endif