source: trunk/tmdmcreator/src/tmdmcreator.cpp @ 16

Revision 16, 3.2 KB checked in by lucsch, 12 years ago (diff)

Copying Base and User SQL files into output file is now working

Line 
1/***************************************************************************
2 tmdmcreator.cpp
3 -------------------
4 copyright            : (C) 2013 CREALP Lucien Schreiber
5 email                : lucien.schreiber at crealp dot vs dot ch
6 ***************************************************************************/
7
8/***************************************************************************
9 *                                                                         *
10 *   This program is free software; you can redistribute it and/or modify  *
11 *   it under the terms of the GNU General Public License as published by  *
12 *   the Free Software Foundation; either version 2 of the License, or     *
13 *   (at your option) any later version.                                   *
14 *                                                                         *
15 ***************************************************************************/
16
17#include "tmdmcreator.h"
18#include "tmdmcopier.h"
19
20TmDmCreator::TmDmCreator() {
21}
22
23
24
25TmDmCreator::~TmDmCreator() {
26}
27
28
29
30void TmDmCreator::SetBaseSQL(wxFileName value) {
31  m_FileNameBaseSQL = value;
32}
33
34
35
36void TmDmCreator::SetUserSQL(wxFileName value) {
37  m_FileNameUserSQL = value;
38}
39
40
41
42void TmDmCreator::SetUserContent(wxFileName value) {
43  m_FileNameUserContent = value;
44}
45
46
47
48void TmDmCreator::SetOutSQL(wxFileName value) {
49  m_FileNameOutSQL = value;
50}
51
52
53bool TmDmCreator::_CheckExistsAndExt(const wxFileName & filename, const wxString & extension, wxArrayString * errormsg){
54    wxASSERT(errormsg);
55    if (filename.Exists() == false) {
56        errormsg->Add(wxString::Format(_("File: %s didn't exists!"), filename.GetFullPath()));
57        return false;
58    }
59    if (filename.GetExt().Lower() != extension) {
60        errormsg->Add(wxString::Format(_("Wrong extension for: %s  (expected: %s)"), filename.GetFullPath(), extension));
61        return false;
62    }
63    return true;
64}
65
66
67
68bool TmDmCreator::CheckFiles(wxArrayString & errormsg) {
69    errormsg.Clear();
70    if (_CheckExistsAndExt(m_FileNameBaseSQL, _T("sql"), &errormsg) == false) {
71        return false;
72    }
73    if (_CheckExistsAndExt(m_FileNameUserSQL, _T("sql"), &errormsg) == false) {
74        return false;
75    }
76    if (_CheckExistsAndExt(m_FileNameUserContent, _T("txt"), &errormsg) == false) {
77        return false;
78    }
79    if (m_FileNameOutSQL.Exists()) {
80        errormsg.Add(wxString::Format(_("output file: %s allready exists!"), m_FileNameOutSQL.GetFullPath()));
81        return false;
82    }
83    if (m_FileNameOutSQL.IsDirWritable() == false){
84        errormsg.Add(wxString::Format(_T("Writing not permitted into %s"), m_FileNameOutSQL.GetPath()));
85        return false;
86    }
87    return true;
88}
89
90
91
92bool TmDmCreator::ProcessFiles(wxArrayString & errorsmsg) {
93    errorsmsg.Clear();
94    // Copy structure to out
95    TmDmCopier myCopier(m_FileNameOutSQL);
96    if (myCopier.CopyFrom(m_FileNameBaseSQL) == false) {
97        errorsmsg.Add(wxString::Format(_("Copying: %s failed!"), m_FileNameBaseSQL.GetFullPath()));
98        return false;
99    }
100   
101    if (myCopier.CopyFrom(m_FileNameUserSQL) == false) {
102        errorsmsg.Add(wxString::Format(_("Copying: %s failed!"), m_FileNameUserSQL.GetFullPath()));
103        return false;
104    }
105   
106   
107   
108    return true;
109}
110
Note: See TracBrowser for help on using the repository browser.