1 /*
2 * Copyright 2007 Simone Della Longa <simonedll@yahoo.it>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "main.h"
20 using namespace std;
21 bool
fixSimDir(wxString * dirPath)22 fixSimDir (wxString * dirPath)
23 {
24 if (!wxDirExists (*dirPath))
25 {
26 if (!wxMkdir (*dirPath))
27 {
28 cout << "Could not Create Directory " << wx2std (*dirPath) << endl;
29 return FALSE;
30 }
31 }
32 return TRUE;
33 }
34
35 bool
openOrInitialize(wxString * fullPath,char * initializeData)36 openOrInitialize (wxString * fullPath, char *initializeData)
37 {
38 cout << "Loading " << wx2std (*fullPath) << endl;
39 wxFile settingsFile;
40 if (!settingsFile.Exists (*fullPath))
41 {
42 if (!openOrCreate (&settingsFile, fullPath))
43 {
44 exit (1);
45 }
46
47 unsigned int wrote = settingsFile.Write (initializeData,
48 sizeof (char) *
49 strlen (initializeData));
50 if (wrote != sizeof (char) * strlen (initializeData))
51 {
52 wxMessageBox (_T ("Some error occurred writing to file?"),
53 _T ("SimDock"), wxOK | wxICON_INFORMATION, NULL);
54 return FALSE;
55 }
56 }
57 //cout << "Loading settings file:" << wx2std (*fullPath) << endl;
58
59 return TRUE;
60
61 }
62
63
64
65 bool
openOrCreate(wxFile * settingsFile,wxString * fullPath)66 openOrCreate (wxFile * settingsFile, wxString * fullPath)
67 {
68 if (!settingsFile->Create (*fullPath, true))
69 {
70 wxMessageBox (_T ("Could not Create file!!!"), _T ("SimDock"),
71 wxOK | wxICON_INFORMATION, NULL);
72 return FALSE;
73 }
74 if (!settingsFile->Open (*fullPath, wxFile::write))
75 {
76 wxMessageBox (_T ("Could not open file for writing!!!"), _T ("SimDock"),
77 wxOK | wxICON_INFORMATION, NULL);
78 return FALSE;
79 }
80 return TRUE;
81 }
82