[15] | 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" |
---|
[16] | 18 | #include "tmdmcopier.h" |
---|
[15] | 19 | |
---|
[16] | 20 | TmDmCreator::TmDmCreator() { |
---|
[15] | 21 | } |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
[16] | 25 | TmDmCreator::~TmDmCreator() { |
---|
[15] | 26 | } |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | |
---|
[16] | 30 | void TmDmCreator::SetBaseSQL(wxFileName value) { |
---|
[15] | 31 | m_FileNameBaseSQL = value; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
[16] | 36 | void TmDmCreator::SetUserSQL(wxFileName value) { |
---|
[15] | 37 | m_FileNameUserSQL = value; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
[16] | 42 | void TmDmCreator::SetUserContent(wxFileName value) { |
---|
[15] | 43 | m_FileNameUserContent = value; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
[16] | 48 | void TmDmCreator::SetOutSQL(wxFileName value) { |
---|
[15] | 49 | m_FileNameOutSQL = value; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
[16] | 53 | bool 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 | } |
---|
[15] | 65 | |
---|
[16] | 66 | |
---|
| 67 | |
---|
| 68 | bool 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; |
---|
[15] | 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
[16] | 92 | bool 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; |
---|
[15] | 109 | } |
---|
| 110 | |
---|