1 // defaults.cpp - Default settings subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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/>
22 void SetupDefaultAddressBook(){
24 // Setup the default address book if there are none.
26 // Check if the 'Default.local' directory exists.
28 wxString DefaultLocalDir;
30 #if defined(__HAIKU__)
32 //preffilename = wxT("noo");
34 #elif defined(__WIN32__)
36 DefaultLocalDir.Clear();
37 DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
38 DefaultLocalDir.Append(wxT("\\Xestia\\Address Book\\accounts\\"));
39 DefaultLocalDir.Append(wxT("Default.local"));
41 #elif defined(__APPLE__)
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"));
50 DefaultLocalDir.Clear();
51 DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
52 DefaultLocalDir.Append(wxT("/.xestiaab/accounts/"));
53 DefaultLocalDir.Append(wxT("Default.local"));
57 if (wxDirExists(DefaultLocalDir) == FALSE){
59 if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
67 void SetupDefaultSettings(){
69 // Setup the default settings if they don't exist.
71 // Setup default (non account) settings if they don't exist.
73 wxString DefaultPrefDir;
75 #if defined(__HAIKU__)
77 //preffilename = wxT("noo");
79 #elif defined(__WIN32__)
81 DefaultPrefDir.Clear();
82 DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
83 DefaultPrefDir.Append(wxT("\\Xestia\\Address Book\\preferences\\"));
85 #elif defined(__APPLE__)
87 DefaultPrefDir.Clear();
88 DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
89 DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Address Book/preferences"));
93 DefaultPrefDir.Clear();
94 DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
95 DefaultPrefDir.Append(wxT("/.xestiaab/preferences/"));
99 // Create the accounts file if it doesn't exist.
101 if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
103 wxString AccountsFilename;
104 wxFFile AccountsFile;
106 AccountsFilename = DefaultPrefDir;
107 AccountsFilename.Append(wxT("accounts"));
109 #if wxABI_VERSION < 20900
110 AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
112 AccountsFile.Open(AccountsFilename, wxT("w"));
115 AccountsFile.Write(wxT(""));
119 // Create the preferences file if it doesn't exist.
121 if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
123 wxString PrefsFilename;
126 PrefsFilename = DefaultPrefDir;
127 PrefsFilename.Append(wxT("settings"));
129 #if wxABI_VERSION < 20900
130 PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
132 PrefsFile.Open(PrefsFilename, wxT("w"));
135 PrefsFile.Write(wxT("HideLocalAddressBooks=false\nSaveWindowPosition=true\n"));
141 void SetupDirectories(){
143 // Create the directories if they don't exist.
145 wxString DefaultSettingsDir;
147 #if defined(__HAIKU__)
149 //preffilename = wxT("noo");
151 #elif defined(__WIN32__)
153 DefaultSettingsDir.Clear();
154 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
155 DefaultSettingsDir.Append(wxT("\\Xestia\\"));
157 if (wxDirExists(DefaultSettingsDir) == FALSE){
159 // Create the directory.
161 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
167 // 'Address Book' to the directory.
169 DefaultSettingsDir.Append(wxT("\\Address Book\\"));
171 #elif defined(__APPLE__)
173 DefaultSettingsDir.Clear();
174 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
175 DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
177 if (wxDirExists(DefaultSettingsDir) == FALSE){
179 // Create the directory.
181 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
187 // Append 'Address Book' to the directory.
189 DefaultSettingsDir.Append(wxT("/Address Book/"));
193 DefaultSettingsDir.Clear();
194 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
195 DefaultSettingsDir.Append(wxT("/.xestiaab/"));
199 // Check if the directory exists.
201 if (wxDirExists(DefaultSettingsDir) == FALSE){
203 // Create the directory.
205 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
211 if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
213 if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){
219 if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
221 if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){