Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
998a601976db067bde4cc565db2fa38ae80decf4
[xestiacalendar/.git] / source / common / defaults.cpp
1 // defaults.cpp - Default settings subroutines.
2 //
3 // (c) 2012-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar. Originally from Xestia Address Book.
6 //
7 // Xestia Calendar 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 Calendar 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 Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include <wx/wx.h>
20 #include <wx/ffile.h>
22 void SetupDefaultCalendar(){
23     
24         // Setup the default calendar if there are none.
25     
26         // Check if the 'Default.local' directory exists.
27     
28         wxString DefaultLocalDir;
29     
30 #if defined(__HAIKU__)
31         
32 #elif defined(__WIN32__)
33     
34         DefaultLocalDir.Clear();
35         DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
36         DefaultLocalDir.Append(wxT("\\Xestia\\Calendar\\accounts\\"));
37         DefaultLocalDir.Append(wxT("Default.local"));
39 #elif defined(__APPLE__)
41         DefaultLocalDir.Clear();
42         DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
43         DefaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Calendar/accounts/"));
44         DefaultLocalDir.Append(wxT("Default.local"));
46 #else
47     
48         DefaultLocalDir.Clear();
49         DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
50         DefaultLocalDir.Append(wxT("/.xestiacal/accounts/"));
51         DefaultLocalDir.Append(wxT("Default.local"));
53 #endif
55         if (wxDirExists(DefaultLocalDir) == FALSE){
56         
57                 if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
58         
59                 }
60         
61         }
62     
63 }
65 void SetupDefaultSettings(){
66     
67         // Setup the default settings if they don't exist.
68     
69         // Setup default (non account) settings if they don't exist.
70     
71         wxString DefaultPrefDir;
72     
73 #if defined(__HAIKU__)
74     
75     
76 #elif defined(__WIN32__)
77     
78         DefaultPrefDir.Clear();
79         DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
80         DefaultPrefDir.Append(wxT("\\Xestia\\Calendar\\preferences\\"));
81     
82 #elif defined(__APPLE__)
83     
84         DefaultPrefDir.Clear();
85         DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
86         DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Calendar/preferences/"));
87     
88 #else
89     
90         DefaultPrefDir.Clear();
91         DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
92         DefaultPrefDir.Append(wxT("/.xestiacal/preferences/"));
93     
94 #endif
95     
96         // Create the accounts file if it doesn't exist.
97     
98         if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
99         
100                 wxString AccountsFilename;
101                 wxFFile AccountsFile;
102         
103                 AccountsFilename = DefaultPrefDir;
104                 AccountsFilename.Append(wxT("accounts"));
105         
106 #if wxABI_VERSION < 20900
107                 AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
108 #else
109                 AccountsFile.Open(AccountsFilename, wxT("w"));
110 #endif
111         
112                 AccountsFile.Write(wxT(""));
113         
114         }
115     
116         // Create the preferences file if it doesn't exist.
117     
118         if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
119         
120                 wxString PrefsFilename;
121                 wxFFile PrefsFile;
122         
123                 PrefsFilename = DefaultPrefDir;
124                 PrefsFilename.Append(wxT("settings"));
125         
126 #if wxABI_VERSION < 20900
127                 PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
128 #else
129                 PrefsFile.Open(PrefsFilename, wxT("w"));
130 #endif
131         
132                 PrefsFile.Write(wxT("HideLocalCalendars=false\nSaveWindowPosition=true\n"));
133         
134         }
135     
138 void SetupDirectories(){
139     
140         // Create the directories if they don't exist.
141     
142         wxString DefaultSettingsDir;
144 #if defined(__HAIKU__)
145     
146 #elif defined(__WIN32__)
147     
148         DefaultSettingsDir.Clear();
149         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
150         DefaultSettingsDir.Append(wxT("\\Xestia\\"));
151     
152         if (wxDirExists(DefaultSettingsDir) == FALSE){
153         
154                 // Create the directory.
155         
156                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
157             
158                 }
159         
160         }
161     
162         // 'Calendar' to the directory.
163     
164         DefaultSettingsDir.Append(wxT("\\Calendar\\"));
165     
166 #elif defined(__APPLE__)
167     
168         DefaultSettingsDir.Clear();
169         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
170         DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
171     
172         if (wxDirExists(DefaultSettingsDir) == FALSE){
173         
174                 // Create the directory.
175         
176                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
177             
178                 }
179         
180         }
181     
182         // Append 'Calendar' to the directory.
183     
184         DefaultSettingsDir.Append(wxT("/Calendar/"));
185     
186 #else
187     
188         DefaultSettingsDir.Clear();
189         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
190         DefaultSettingsDir.Append(wxT("/.xestiacal/"));
191     
192 #endif
193     
194         // Check if the directory exists.
195     
196         if (wxDirExists(DefaultSettingsDir) == FALSE){
197         
198                 // Create the directory.
199         
200                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){         
201             
202                 }
203         
204         }
205     
206         if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
207         
208                 if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){               
209             
210                 }
211         
212         }
213     
214         if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
215         
216                 if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){            
217             
218                 }
219         
220         }
221     
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