Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Idented code properly in common/defaults.cpp
[xestiaab/.git] / source / common / defaults.cpp
1 // defaults.cpp - Default settings subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <wx/wx.h>
20 #include <wx/ffile.h>
22 void SetupDefaultAddressBook(){
23     
24         // Setup the default address book if there are none.
25     
26         // Check if the 'Default.local' directory exists.
27     
28         wxString DefaultLocalDir;
29     
30 #if defined(__HAIKU__)
31     
32         //preffilename = wxT("noo");
33     
34 #elif defined(__WIN32__)
35     
36         DefaultLocalDir.Clear();
37         DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
38         DefaultLocalDir.Append(wxT("\\Xestia\\Address Book\\accounts\\"));
39         DefaultLocalDir.Append(wxT("Default.local"));
40     
41 #elif defined(__APPLE__)
42     
43         DefaultLocalDir.Clear();
44         DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
45         DefaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Address Book/accounts/"));
46         DefaultLocalDir.Append(wxT("Default.local"));
47     
48 #else
49     
50         DefaultLocalDir.Clear();
51         DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
52         DefaultLocalDir.Append(wxT("/.xestiaab/accounts/"));
53         DefaultLocalDir.Append(wxT("Default.local"));
54     
55 #endif
56     
57         if (wxDirExists(DefaultLocalDir) == FALSE){
58         
59                 if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
60             
61                 }
62         
63         }
64     
65 }
67 void SetupDefaultSettings(){
68     
69         // Setup the default settings if they don't exist.
70     
71         // Setup default (non account) settings if they don't exist.
72     
73         wxString DefaultPrefDir;
74     
75 #if defined(__HAIKU__)
76     
77         //preffilename = wxT("noo");
78     
79 #elif defined(__WIN32__)
80     
81         DefaultPrefDir.Clear();
82         DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
83         DefaultPrefDir.Append(wxT("\\Xestia\\Address Book\\preferences\\"));
84     
85 #elif defined(__APPLE__)
86     
87         DefaultPrefDir.Clear();
88         DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
89         DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Address Book/preferences"));
90     
91 #else
92     
93         DefaultPrefDir.Clear();
94         DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
95         DefaultPrefDir.Append(wxT("/.xestiaab/preferences/"));
96     
97 #endif
98     
99         // Create the accounts file if it doesn't exist.
100     
101         if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
102         
103                 wxString AccountsFilename;
104                 wxFFile AccountsFile;
105         
106                 AccountsFilename = DefaultPrefDir;
107                 AccountsFilename.Append(wxT("accounts"));
108         
109 #if wxABI_VERSION < 20900
110                 AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
111 #else
112                 AccountsFile.Open(AccountsFilename, wxT("w"));
113 #endif
114         
115                 AccountsFile.Write(wxT(""));
116         
117         }
118     
119         // Create the preferences file if it doesn't exist.
120     
121         if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
122         
123                 wxString PrefsFilename;
124                 wxFFile PrefsFile;
125         
126                 PrefsFilename = DefaultPrefDir;
127                 PrefsFilename.Append(wxT("settings"));
128         
129 #if wxABI_VERSION < 20900
130                 PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
131 #else
132                 PrefsFile.Open(PrefsFilename, wxT("w"));
133 #endif
134         
135                 PrefsFile.Write(wxT("HideLocalAddressBooks=false\nSaveWindowPosition=true\n"));
136         
137         }
138     
141 void SetupDirectories(){
142     
143         // Create the directories if they don't exist.
144     
145         wxString DefaultSettingsDir;
146     
147 #if defined(__HAIKU__)
148     
149         //preffilename = wxT("noo");
150     
151 #elif defined(__WIN32__)
152     
153         DefaultSettingsDir.Clear();
154         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
155         DefaultSettingsDir.Append(wxT("\\Xestia\\"));
156     
157         if (wxDirExists(DefaultSettingsDir) == FALSE){
158         
159                 // Create the directory.
160         
161                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
162             
163                 }
164         
165         }
166     
167         // 'Address Book' to the directory.
168     
169         DefaultSettingsDir.Append(wxT("\\Address Book\\"));
170     
171 #elif defined(__APPLE__)
172     
173         DefaultSettingsDir.Clear();
174         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
175         DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
176     
177         if (wxDirExists(DefaultSettingsDir) == FALSE){
178         
179                 // Create the directory.
180         
181                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
182             
183                 }
184         
185         }
186     
187         // Append 'Address Book' to the directory.
188     
189         DefaultSettingsDir.Append(wxT("/Address Book/"));
190     
191 #else
192     
193         DefaultSettingsDir.Clear();
194         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
195         DefaultSettingsDir.Append(wxT("/.xestiaab/"));
196     
197 #endif
198     
199         // Check if the directory exists.
200     
201         if (wxDirExists(DefaultSettingsDir) == FALSE){
202         
203                 // Create the directory.
204         
205                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){         
206             
207                 }
208         
209         }
210     
211         if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
212         
213                 if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){               
214             
215                 }
216         
217         }
218     
219         if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
220         
221                 if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){            
222             
223                 }
224         
225         }
226     
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy