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 // Check if the 'Default.local' directory exists.
26 wxString DefaultLocalDir;
28 #if defined(__HAIKU__)
30 //preffilename = wxT("noo");
32 #elif defined(__WIN32__)
34 DefaultLocalDir.Clear();
35 DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
36 DefaultLocalDir.Append(wxT("\\Xestia\\Address Book\\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/Address Book/accounts/"));
44 DefaultLocalDir.Append(wxT("Default.local"));
48 DefaultLocalDir.Clear();
49 DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
50 DefaultLocalDir.Append(wxT("/.xestiaab/accounts/"));
51 DefaultLocalDir.Append(wxT("Default.local"));
55 if (wxDirExists(DefaultLocalDir) == FALSE){
57 if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
65 void SetupDefaultSettings(){
67 // Setup default (non account) settings if they don't exist.
69 wxString DefaultPrefDir;
71 #if defined(__HAIKU__)
73 //preffilename = wxT("noo");
75 #elif defined(__WIN32__)
77 DefaultPrefDir.Clear();
78 DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
79 DefaultPrefDir.Append(wxT("\\Xestia\\Address Book\\preferences\\"));
81 #elif defined(__APPLE__)
83 DefaultPrefDir.Clear();
84 DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
85 DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Address Book/preferences"));
89 DefaultPrefDir.Clear();
90 DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
91 DefaultPrefDir.Append(wxT("/.xestiaab/preferences/"));
95 // Create the accounts file if it doesn't exist.
97 if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
99 wxString AccountsFilename;
100 wxFFile AccountsFile;
102 AccountsFilename = DefaultPrefDir;
103 AccountsFilename.Append(wxT("accounts"));
105 #if wxABI_VERSION < 20900
106 AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
108 AccountsFile.Open(AccountsFilename, wxT("w"));
111 AccountsFile.Write(wxT(""));
115 // Create the preferences file if it doesn't exist.
117 if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
119 wxString PrefsFilename;
122 PrefsFilename = DefaultPrefDir;
123 PrefsFilename.Append(wxT("settings"));
125 #if wxABI_VERSION < 20900
126 PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
128 PrefsFile.Open(PrefsFilename, wxT("w"));
131 PrefsFile.Write(wxT("HideLocalAddressBooks=false\nSaveWindowPosition=true\n"));
137 void SetupDirectories(){
139 // Create the directories if they don't exist.
141 wxString DefaultSettingsDir;
143 #if defined(__HAIKU__)
145 //preffilename = wxT("noo");
147 #elif defined(__WIN32__)
149 DefaultSettingsDir.Clear();
150 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
151 DefaultSettingsDir.Append(wxT("\\Xestia\\"));
153 if (wxDirExists(DefaultSettingsDir) == FALSE){
155 // Create the directory.
157 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
163 // TODO: APPEND 'Address Book' to the directory.
165 DefaultSettingsDir.Append(wxT("\\Address Book\\"));
167 #elif defined(__APPLE__)
169 DefaultSettingsDir.Clear();
170 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
171 DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
173 if (wxDirExists(DefaultSettingsDir) == FALSE){
175 // Create the directory.
177 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
183 // TODO: APPEND 'Address Book' to the directory.
185 DefaultSettingsDir.Append(wxT("/Address Book/"));
189 DefaultSettingsDir.Clear();
190 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
191 DefaultSettingsDir.Append(wxT("/.xestiaab/"));
195 // Check if the directory exists.
197 if (wxDirExists(DefaultSettingsDir) == FALSE){
199 // Create the directory.
201 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
207 if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
209 if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){
215 if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
217 if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){