-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalaos_config.cpp
105 lines (95 loc) · 3.34 KB
/
calaos_config.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
98
99
100
101
102
103
104
105
/******************************************************************************
** Copyright (c) 2007-2008, Calaos. All Rights Reserved.
**
** This file is part of Calaos Home.
**
** Calaos Home 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.
**
** Calaos Home 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 Foobar; if not, write to the Free Software
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
******************************************************************************/
//
// Write/Read config options from local_config.xml
//
#include <Utils.h>
#include <Ecore_File.h>
void print_usage(void)
{
cout << "Calaos Configuration Utility." << endl;
cout << "(c)2008 Calaos" << endl << endl;
cout << "Usage:\tcalaos_config <action> [params]" << endl << endl;
cout << "Where action can be:" << endl;
cout << "\tlist\t\tLists all keys:values" << endl;
cout << "\tset [key]\tSet the value for the specified key" << endl;
cout << "\tget [key]\tPrint the value for the specified key" << endl;
cout << "\tdel [key]\tDelete entry for the specified key" << endl;
}
int main (int argc, char **argv)
{
if (!ecore_file_exists(DEFAULT_CONFIG))
{
Utils::logger("root") << Priority::ERROR << "Error: Default config not found (" << DEFAULT_CONFIG << ")" << log4cpp::eol;
exit(1);
}
if (argc < 2)
{
print_usage();
return 1;
}
string action = argv[1];
Utils::InitLoggingSystem(string(DEFAULT_CONFIG_PATH) + "calaos_console_log.conf");
if (action == "get")
{
string key = argv[2];
if (key == "hwid")
cout << Utils::getHardwareID();
else
cout << Utils::get_config_option(key);
}
else if (action == "set")
{
if (argc < 4)
{
print_usage();
return 1;
}
string key = argv[2];
string value = argv[3];
if (key == "hwid")
Utils::logger("root") << Priority::ERROR << "Can't change hwid" << log4cpp::eol;
else
Utils::set_config_option(key, value);
}
else if (action == "list")
{
Params options;
Utils::get_config_options(options);
cout << "Local configuration:" << endl;
for (int i = 0;i < options.size();i++)
{
std::string key, value;
options.get_item(i, key, value);
cout << key << ": " << value << endl;
}
}
else if (action == "del")
{
Utils::del_config_option(argv[2]);
}
else
{
print_usage();
return 1;
}
return 0;
}