-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetting.cpp
95 lines (84 loc) · 2.72 KB
/
setting.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
/*
#############################################################################################
# Tux in Space - space exploration game #
# Copyright (C) 2016-2017 [email protected] #
# #
# 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, version 3 or compatibles. #
# #
# 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, write to the Free Software #
# Foundation, Inc. #
#############################################################################################
*
* Here are stuff linked whit settings
*/
#include "setting.h"
// Internal constants
// Default values for the set structure
#define DEFAULT_OPS_HEIGHT 48
#define DEFAULT_OPS_WIDTH 68
using namespace std;
/***
* set_Save save in a file the config of tset set
*/
void setting::Save() {
ofstream cf(CONFIGURATION_FILE);
if(!cf) {
debug_Printf(IRREGULARITY" setting::Save() Can't open the - " CONFIGURATION_FILE " - file");
return;
}
cf << height << "\n" << width << "\n";
}
/***
* set_Init is a function that load from the config file
*/
setting::setting() {
ifstream cf(CONFIGURATION_FILE);
// If there is a file
if(cf) {
// scan OPS settings
cf >> height;
cf >> width;
}
// if not, load defaults
else
Defaults();
}
/***
* This function reset the settings to the default values
*/
void setting::Defaults(){
height = DEFAULT_OPS_HEIGHT;
width = DEFAULT_OPS_WIDTH;
}
/***
* This function initializes the directories if them doesn't exist
* NOTE:
* This function works only in *nix! Is not portable!
*/
signal setting::InitDir() {
// The state of the directories
struct stat st = {0};
// Check for the object directory and Create it if not present
if (stat(OBJECT_PATH, &st) == -1) {
mkdir(OBJECT_PATH, 0700);
// Check that the directories has been created succefully
if (stat(OBJECT_PATH, &st) == -1)
return signal::file_err;
}
// Check for the system directory and Create it if not present
if (stat(SYSTEM_PATH, &st) == -1) {
mkdir(SYSTEM_PATH, 0700);
// Check that the directories has been created succefully
if (stat(SYSTEM_PATH, &st) == -1)
return signal::file_err;
}
return signal::good;
}