Changeset 16 for trunk/tmdmcreator/src
- Timestamp:
- 02/21/13 16:20:42 (12 years ago)
- Location:
- trunk/tmdmcreator/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tmdmcreator/src/main.cpp
r6 r16 27 27 #include <wx/dir.h> 28 28 #include <wx/filename.h> 29 #include "tmdmcreator.h" 29 30 30 31 … … 34 35 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, 35 36 { wxCMD_LINE_SWITCH, "v", "verbose", "Be more verbose" }, 36 { wxCMD_LINE_PARAM, NULL, NULL, "[structure sql file]"}, 37 { wxCMD_LINE_PARAM, NULL, NULL, "[content txt file]"}, 38 { wxCMD_LINE_PARAM, NULL, NULL, "[result sql file]"}, 37 { wxCMD_LINE_SWITCH, "t", "toolmap", "toolmap output" }, 38 { wxCMD_LINE_SWITCH, "o", "overwrite", "overwrite output" }, 39 { wxCMD_LINE_PARAM, NULL, NULL, "[base structure sql file]"}, 40 { wxCMD_LINE_PARAM, NULL, NULL, "[user structure sql file]"}, 41 { wxCMD_LINE_PARAM, NULL, NULL, "[user content txt file]"}, 42 { wxCMD_LINE_PARAM, NULL, NULL, "[result file]"}, 39 43 { wxCMD_LINE_NONE } 40 44 }; … … 42 46 43 47 44 void PrintArray(const wxArrayString & array, const wxString & msg){ 45 wxPrintf(msg + _T("\n")); 48 void PrintArray(const wxArrayString & array, const wxString & msg = wxEmptyString){ 49 if (msg != wxEmptyString) { 50 wxPrintf(msg + _T("\n")); 51 } 46 52 for (unsigned int i = 0; i< array.GetCount(); i++) { 47 53 wxPrintf(array[i] + _T("\n")); … … 74 80 // cmd line is correct !! 75 81 wxPrintf(myLogoTxt); 82 83 bool bVerbose = parser.Found("verbose"); 84 bool bToolMap = parser.Found("toolmap"); 85 if (parser.Found("overwrite")) { 86 wxRemoveFile(parser.GetParam(3)); 87 } 88 89 if (bToolMap == true) { 90 wxPrintf(_("Exporting to ToolMap project not supported for now!\n")); 91 return 0; 92 } 93 94 wxASSERT(parser.GetParamCount() == 4); 95 TmDmCreator myCreator; 96 myCreator.SetBaseSQL(wxFileName(parser.GetParam(0))); 97 myCreator.SetUserSQL(wxFileName(parser.GetParam(1))); 98 myCreator.SetUserContent(wxFileName(parser.GetParam(2))); 99 myCreator.SetOutSQL(wxFileName(parser.GetParam(3))); 100 101 wxArrayString myErrors; 102 if (myCreator.CheckFiles(myErrors) == false) { 103 if (bVerbose == true) { 104 PrintArray(myErrors); 105 } 106 wxPrintf(_("Error while checking files, aborting!\n")); 107 return 0; 108 } 109 110 if (myCreator.ProcessFiles(myErrors) == false) { 111 if (bVerbose == true) { 112 PrintArray(myErrors); 113 } 114 wxPrintf(_("Error processing files, aborting\n")); 115 return 0; 116 } 117 118 wxPrintf(_("Processing succeed!\n")); 76 119 return 0; 77 120 } -
trunk/tmdmcreator/src/tmdmcopier.cpp
r15 r16 2 2 tmdmcopier.cpp 3 3 ------------------- 4 copyright : (C) 2013 CREALP Lucien Schreiber 4 copyright : (C) 2013 CREALP Lucien Schreiber 5 5 email : lucien.schreiber at crealp dot vs dot ch 6 6 ***************************************************************************/ … … 18 18 19 19 TmDmCopier::TmDmCopier(const wxFileName & destfile) { 20 m_File = new wxFFile(); 21 bool bOpen = m_File->Open(destfile.GetFullPath(), "a"); 22 wxASSERT(bOpen == true); 20 23 } 21 24 25 26 22 27 TmDmCopier::~TmDmCopier() { 28 wxDELETE(m_File); 23 29 } 24 30 25 void TmDmCopier::SetCopyMode(TMDMCOPIER_MODE value) { 26 m_CopyMode = value; 31 32 33 bool TmDmCopier::CopyFrom(const wxFileName & filename) { 34 wxFFile mySrcFile; 35 if (mySrcFile.Open(filename.GetFullPath()) == false) { 36 m_Errors.Add(wxString::Format(_("Unable to open: %s"), filename.GetFullPath())); 37 return false; 38 } 39 40 wxString mySrcTxt; 41 if(mySrcFile.ReadAll(&mySrcTxt)==false){ 42 m_Errors.Add(wxString::Format(_("Reading from: %s failed!"), filename.GetFullPath())); 43 return false; 44 } 45 return CopyFrom(mySrcTxt); 27 46 } 28 47 29 bool TmDmCopier::CopyFrom(const wxFileName & filename) { 48 49 50 bool TmDmCopier::CopyFrom(const wxString & text) { 51 if (m_File->Write(text) == false) { 52 m_Errors.Add(wxString::Format(_("Writing to: %s failed!"), m_File->GetName())); 53 return false; 54 } 55 56 return true; 30 57 } 31 58 32 bool TmDmCopier::CopyFrom(const wxString & text) { 59 60 61 wxArrayString TmDmCopier::GetErrors(){ 62 return m_Errors; 33 63 } 34 35 bool TmDmCopier::IsCopyAllowed() {36 }37 -
trunk/tmdmcreator/src/tmdmcopier.h
r15 r16 23 23 24 24 #include <wx/filename.h> 25 #include <wx/ffile.h> 25 26 26 enum TMDMCOPIER_MODE {27 TMDMCOPIER_MODE_ERASE = 0,28 TMDMCOPIER_MODE_APPEND29 };30 27 31 28 32 29 class TmDmCopier { 33 30 private: 34 TMDMCOPIER_MODE m_CopyMode; 31 wxFFile * m_File; 32 wxArrayString m_Errors; 35 33 36 34 public: … … 38 36 virtual ~TmDmCopier(); 39 37 40 void SetCopyMode(TMDMCOPIER_MODE value);41 38 bool CopyFrom(const wxFileName & filename); 42 39 bool CopyFrom(const wxString & text); 43 bool IsCopyAllowed(); 40 41 wxArrayString GetErrors(); 44 42 }; 45 43 #endif -
trunk/tmdmcreator/src/tmdmcreator.cpp
r15 r16 16 16 17 17 #include "tmdmcreator.h" 18 #include "tmdmcopier.h" 18 19 19 tmdmcreator::tmdmcreator() {20 TmDmCreator::TmDmCreator() { 20 21 } 21 22 22 23 23 24 24 tmdmcreator::~tmdmcreator() {25 TmDmCreator::~TmDmCreator() { 25 26 } 26 27 27 28 28 29 29 void tmdmcreator::SetBaseSQL(wxFileName value) {30 void TmDmCreator::SetBaseSQL(wxFileName value) { 30 31 m_FileNameBaseSQL = value; 31 32 } … … 33 34 34 35 35 void tmdmcreator::SetUserSQL(wxFileName value) {36 void TmDmCreator::SetUserSQL(wxFileName value) { 36 37 m_FileNameUserSQL = value; 37 38 } … … 39 40 40 41 41 void tmdmcreator::SetUserContent(wxFileName value) {42 void TmDmCreator::SetUserContent(wxFileName value) { 42 43 m_FileNameUserContent = value; 43 44 } … … 45 46 46 47 47 void tmdmcreator::SetOutSQL(wxFileName value) {48 void TmDmCreator::SetOutSQL(wxFileName value) { 48 49 m_FileNameOutSQL = value; 49 50 } 50 51 51 52 52 53 bool tmdmcreator::CheckFiles(wxArrayString & errormsg) { 54 return false; 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; 55 64 } 56 65 57 66 58 67 59 bool tmdmcreator::ProcessFiles(wxArrayString & errorsmsg) { 60 return false; 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; 61 88 } 62 89 90 91 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; 109 } 110 -
trunk/tmdmcreator/src/tmdmcreator.h
r15 r16 21 21 #include <wx/wx.h> 22 22 #endif 23 24 23 #include <wx/filename.h> 25 24 26 class tmdmcreator {25 class TmDmCreator { 27 26 private: 28 27 wxFileName m_FileNameBaseSQL; … … 31 30 wxFileName m_FileNameOutSQL; 32 31 32 bool _CheckExistsAndExt(const wxFileName & filename, const wxString & extension, wxArrayString * errormsg); 33 33 34 public: 34 tmdmcreator();35 virtual ~ tmdmcreator();36 35 TmDmCreator(); 36 virtual ~TmDmCreator(); 37 37 38 void SetBaseSQL(wxFileName value); 38 39 void SetUserSQL(wxFileName value); … … 41 42 42 43 bool CheckFiles(wxArrayString & errormsg); 43 bool ProcessFiles(wxArrayString & errorsmsg); 44 bool ProcessFiles(wxArrayString & errorsmsg); 44 45 }; 45 46 #endif -
trunk/tmdmcreator/src/tmdmprocessor.cpp
r15 r16 2 2 tmdmprocessor.cpp 3 3 ------------------- 4 copyright : (C) 2013 CREALP Lucien Schreiber 4 copyright : (C) 2013 CREALP Lucien Schreiber 5 5 email : lucien.schreiber at crealp dot vs dot ch 6 6 ***************************************************************************/ … … 21 21 } 22 22 23 24 23 25 TmDmProcessor::~TmDmProcessor() { 24 26 } 25 27 28 29 26 30 int TmDmProcessor::FindBlock(const wxString & blockname) { 31 return wxNOT_FOUND; 27 32 } 33 34 35 36 37 38 39 28 40 29 41 TmDmProcessorSimple::TmDmProcessorSimple() { 30 42 } 31 43 44 45 32 46 TmDmProcessorSimple::~TmDmProcessorSimple() { 33 47 } 34 48 49 50 35 51 bool TmDmProcessorSimple::ProcessBlock(int blockstart, TmDmCopier * copier) { 52 return false; 36 53 } 54 55 56 57 58 59 60 61 37 62 38 63 TmDmProcessorAttributs::TmDmProcessorAttributs() { … … 43 68 44 69 bool TmDmProcessorAttributs::ProcessBlock(int blockstart, TmDmCopier * copier) { 70 return false; 45 71 } 46 72 -
trunk/tmdmcreator/src/tmdmprocessor.h
r15 r16 2 2 tmdmprocessor.h 3 3 ------------------- 4 copyright : (C) 2013 CREALP Lucien Schreiber 4 copyright : (C) 2013 CREALP Lucien Schreiber 5 5 email : lucien.schreiber at crealp dot vs dot ch 6 6 ***************************************************************************/ … … 25 25 #endif 26 26 27 28 27 class TmDmCopier; 29 30 28 class TmDmProcessor { 31 29 protected: 32 30 TmDmCopier * m_Copier; 31 32 public: 33 TmDmProcessor(); 34 virtual ~TmDmProcessor(); 35 36 int FindBlock(const wxString & blockname); 37 virtual bool ProcessBlock(int blockstart, TmDmCopier * copier) = 0; 38 }; 33 39 34 40 35 public:36 TmDmProcessor();37 41 38 virtual ~TmDmProcessor();39 42 40 int FindBlock(const wxString & blockname);41 43 42 virtual bool ProcessBlock(int blockstart, TmDmCopier * copier) = 0;43 44 45 46 class TmDmProcessorSimple : public TmDmProcessor { 47 public: 48 TmDmProcessorSimple(); 49 virtual ~TmDmProcessorSimple(); 50 51 virtual bool ProcessBlock(int blockstart, TmDmCopier * copier); 44 52 }; 45 class TmDmProcessorSimple : public TmDmProcessor {46 public:47 TmDmProcessorSimple();48 53 49 virtual ~TmDmProcessorSimple();50 54 55 56 57 58 59 60 class TmDmProcessorAttributs : public TmDmProcessor { 61 public: 62 TmDmProcessorAttributs(); 63 virtual ~TmDmProcessorAttributs(); 64 51 65 virtual bool ProcessBlock(int blockstart, TmDmCopier * copier); 52 53 };54 class TmDmProcessorAttributs : public TmDmProcessor {55 public:56 TmDmProcessorAttributs();57 58 virtual ~TmDmProcessorAttributs();59 60 virtual bool ProcessBlock(int blockstart, TmDmCopier * copier);61 62 66 }; 63 67 #endif
Note: See TracChangeset
for help on using the changeset viewer.