| 808 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2011 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emCORE.
|
|
|
7 |
//
|
|
|
8 |
// emCORE is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emCORE is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "emcoreapp.h"
|
|
|
25 |
#include "settings.h"
|
|
|
26 |
#include "mainchooser.h"
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
struct settingdata settings_default =
|
|
|
30 |
{
|
|
|
31 |
.version = SETTINGS_VERSION,
|
|
|
32 |
.timeout_initial = 30000000,
|
|
|
33 |
.timeout_idle = 300000000,
|
|
|
34 |
.timeout_item = 0,
|
|
|
35 |
.default_item = 1,
|
|
|
36 |
.fastboot_item = 0
|
|
|
37 |
};
|
|
|
38 |
|
|
|
39 |
struct settingdata settings;
|
|
|
40 |
|
|
|
41 |
void settings_reset()
|
|
|
42 |
{
|
|
|
43 |
memcpy(&settings, &settings_default, sizeof(settings));
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
void settings_validate_all()
|
|
|
47 |
{
|
|
|
48 |
if (settings.version != SETTINGS_VERSION) settings_reset();
|
|
|
49 |
if (settings.timeout_initial < 0) settings.timeout_initial = 0;
|
|
|
50 |
if (settings.timeout_initial > 2000000000) settings.timeout_initial = 2000000000;
|
|
|
51 |
if (settings.timeout_idle < 0) settings.timeout_idle = 0;
|
|
|
52 |
if (settings.timeout_idle > 2000000000) settings.timeout_idle = 2000000000;
|
|
|
53 |
if (settings.timeout_item < 0) settings.timeout_item = 0;
|
|
|
54 |
if (settings.timeout_item > 3) settings.timeout_item = 3;
|
|
|
55 |
if (settings.default_item < 0) settings.default_item = 0;
|
|
|
56 |
if (settings.default_item > 3) settings.default_item = 3;
|
|
|
57 |
if (settings.fastboot_item < 0) settings.fastboot_item = 0;
|
|
|
58 |
if (settings.fastboot_item > 3) settings.fastboot_item = 3;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
void settings_apply()
|
|
|
62 |
{
|
|
|
63 |
mainchooser_apply_settings();
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
void settings_init()
|
|
|
67 |
{
|
|
|
68 |
settings_reset();
|
|
|
69 |
int fd = file_open("/.apps/bootmenu/data/settings.dat", O_RDONLY);
|
|
|
70 |
if (fd > 0)
|
|
|
71 |
{
|
|
|
72 |
int size = filesize(fd);
|
|
|
73 |
if (size > 0)
|
|
|
74 |
{
|
|
|
75 |
if (size > sizeof(settings)) size = sizeof(settings);
|
|
|
76 |
read(fd, &settings, size);
|
|
|
77 |
}
|
|
|
78 |
close(fd);
|
|
|
79 |
}
|
|
|
80 |
settings_validate_all();
|
|
|
81 |
settings_apply();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
void settings_save()
|
|
|
85 |
{
|
|
|
86 |
mkdir("/.apps");
|
|
|
87 |
mkdir("/.apps/bootmenu");
|
|
|
88 |
mkdir("/.apps/bootmenu/data");
|
|
|
89 |
int fd = file_creat("/.apps/bootmenu/data/settings.dat");
|
|
|
90 |
if (fd > 0)
|
|
|
91 |
{
|
|
|
92 |
write(fd, &settings, sizeof(settings));
|
|
|
93 |
close(fd);
|
|
|
94 |
}
|
|
|
95 |
}
|