Changeset 16 for trunk/tmdmcreator/src


Ignore:
Timestamp:
02/21/13 16:20:42 (12 years ago)
Author:
lucsch
Message:

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

Location:
trunk/tmdmcreator/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/tmdmcreator/src/main.cpp

    r6 r16  
    2727#include <wx/dir.h> 
    2828#include <wx/filename.h> 
     29#include "tmdmcreator.h" 
    2930 
    3031 
     
    3435        wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, 
    3536    { 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]"}, 
    3943    { wxCMD_LINE_NONE } 
    4044}; 
     
    4246 
    4347 
    44 void PrintArray(const wxArrayString & array, const wxString & msg){ 
    45     wxPrintf(msg + _T("\n")); 
     48void PrintArray(const wxArrayString & array, const wxString & msg = wxEmptyString){ 
     49    if (msg != wxEmptyString) { 
     50        wxPrintf(msg + _T("\n")); 
     51    } 
    4652    for (unsigned int i = 0; i< array.GetCount(); i++) { 
    4753        wxPrintf(array[i] + _T("\n")); 
     
    7480    // cmd line is correct !! 
    7581    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")); 
    76119    return 0; 
    77120} 
  • trunk/tmdmcreator/src/tmdmcopier.cpp

    r15 r16  
    22 tmdmcopier.cpp 
    33 ------------------- 
    4  copyright            : (C) 2013 CREALP Lucien Schreiber  
     4 copyright            : (C) 2013 CREALP Lucien Schreiber 
    55 email                : lucien.schreiber at crealp dot vs dot ch 
    66 ***************************************************************************/ 
     
    1818 
    1919TmDmCopier::TmDmCopier(const wxFileName & destfile) { 
     20    m_File = new wxFFile(); 
     21    bool bOpen = m_File->Open(destfile.GetFullPath(), "a"); 
     22    wxASSERT(bOpen == true); 
    2023} 
    2124 
     25 
     26 
    2227TmDmCopier::~TmDmCopier() { 
     28    wxDELETE(m_File); 
    2329} 
    2430 
    25 void TmDmCopier::SetCopyMode(TMDMCOPIER_MODE value) { 
    26   m_CopyMode = value; 
     31 
     32 
     33bool 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); 
    2746} 
    2847 
    29 bool TmDmCopier::CopyFrom(const wxFileName & filename) { 
     48 
     49 
     50bool 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; 
    3057} 
    3158 
    32 bool TmDmCopier::CopyFrom(const wxString & text) { 
     59 
     60 
     61wxArrayString TmDmCopier::GetErrors(){ 
     62    return m_Errors; 
    3363} 
    34  
    35 bool TmDmCopier::IsCopyAllowed() { 
    36 } 
    37  
  • trunk/tmdmcreator/src/tmdmcopier.h

    r15 r16  
    2323 
    2424#include <wx/filename.h> 
     25#include <wx/ffile.h> 
    2526 
    26 enum TMDMCOPIER_MODE { 
    27     TMDMCOPIER_MODE_ERASE = 0, 
    28     TMDMCOPIER_MODE_APPEND 
    29 }; 
    3027 
    3128 
    3229class TmDmCopier { 
    3330private: 
    34     TMDMCOPIER_MODE m_CopyMode; 
     31    wxFFile * m_File; 
     32    wxArrayString m_Errors; 
    3533     
    3634public: 
     
    3836    virtual ~TmDmCopier(); 
    3937     
    40     void SetCopyMode(TMDMCOPIER_MODE value); 
    4138    bool CopyFrom(const wxFileName & filename); 
    4239    bool CopyFrom(const wxString & text); 
    43     bool IsCopyAllowed(); 
     40     
     41    wxArrayString GetErrors(); 
    4442}; 
    4543#endif 
  • trunk/tmdmcreator/src/tmdmcreator.cpp

    r15 r16  
    1616 
    1717#include "tmdmcreator.h" 
     18#include "tmdmcopier.h" 
    1819 
    19 tmdmcreator::tmdmcreator() { 
     20TmDmCreator::TmDmCreator() { 
    2021} 
    2122 
    2223 
    2324 
    24 tmdmcreator::~tmdmcreator() { 
     25TmDmCreator::~TmDmCreator() { 
    2526} 
    2627 
    2728 
    2829 
    29 void tmdmcreator::SetBaseSQL(wxFileName value) { 
     30void TmDmCreator::SetBaseSQL(wxFileName value) { 
    3031  m_FileNameBaseSQL = value; 
    3132} 
     
    3334 
    3435 
    35 void tmdmcreator::SetUserSQL(wxFileName value) { 
     36void TmDmCreator::SetUserSQL(wxFileName value) { 
    3637  m_FileNameUserSQL = value; 
    3738} 
     
    3940 
    4041 
    41 void tmdmcreator::SetUserContent(wxFileName value) { 
     42void TmDmCreator::SetUserContent(wxFileName value) { 
    4243  m_FileNameUserContent = value; 
    4344} 
     
    4546 
    4647 
    47 void tmdmcreator::SetOutSQL(wxFileName value) { 
     48void TmDmCreator::SetOutSQL(wxFileName value) { 
    4849  m_FileNameOutSQL = value; 
    4950} 
    5051 
    5152 
    52  
    53 bool tmdmcreator::CheckFiles(wxArrayString & errormsg) { 
    54     return false; 
     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; 
    5564} 
    5665 
    5766 
    5867 
    59 bool tmdmcreator::ProcessFiles(wxArrayString & errorsmsg) { 
    60     return false; 
     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; 
    6188} 
    6289 
     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 
  • trunk/tmdmcreator/src/tmdmcreator.h

    r15 r16  
    2121#include <wx/wx.h> 
    2222#endif 
    23  
    2423#include <wx/filename.h> 
    2524 
    26 class tmdmcreator { 
     25class TmDmCreator { 
    2726private: 
    2827    wxFileName m_FileNameBaseSQL; 
     
    3130    wxFileName m_FileNameOutSQL; 
    3231     
     32    bool _CheckExistsAndExt(const wxFileName & filename, const wxString & extension, wxArrayString * errormsg); 
     33     
    3334public: 
    34     tmdmcreator(); 
    35     virtual ~tmdmcreator(); 
    36  
     35    TmDmCreator(); 
     36    virtual ~TmDmCreator(); 
     37     
    3738    void SetBaseSQL(wxFileName value); 
    3839    void SetUserSQL(wxFileName value); 
     
    4142     
    4243    bool CheckFiles(wxArrayString & errormsg); 
    43     bool ProcessFiles(wxArrayString & errorsmsg); 
     44    bool ProcessFiles(wxArrayString & errorsmsg);     
    4445}; 
    4546#endif 
  • trunk/tmdmcreator/src/tmdmprocessor.cpp

    r15 r16  
    22 tmdmprocessor.cpp 
    33 ------------------- 
    4  copyright            : (C) 2013 CREALP Lucien Schreiber  
     4 copyright            : (C) 2013 CREALP Lucien Schreiber 
    55 email                : lucien.schreiber at crealp dot vs dot ch 
    66 ***************************************************************************/ 
     
    2121} 
    2222 
     23 
     24 
    2325TmDmProcessor::~TmDmProcessor() { 
    2426} 
    2527 
     28 
     29 
    2630int TmDmProcessor::FindBlock(const wxString & blockname) { 
     31    return wxNOT_FOUND; 
    2732} 
     33 
     34 
     35 
     36 
     37 
     38 
     39 
    2840 
    2941TmDmProcessorSimple::TmDmProcessorSimple() { 
    3042} 
    3143 
     44 
     45 
    3246TmDmProcessorSimple::~TmDmProcessorSimple() { 
    3347} 
    3448 
     49 
     50 
    3551bool TmDmProcessorSimple::ProcessBlock(int blockstart, TmDmCopier * copier) { 
     52    return false; 
    3653} 
     54 
     55 
     56 
     57 
     58 
     59 
     60 
     61 
    3762 
    3863TmDmProcessorAttributs::TmDmProcessorAttributs() { 
     
    4368 
    4469bool TmDmProcessorAttributs::ProcessBlock(int blockstart, TmDmCopier * copier) { 
     70    return false; 
    4571} 
    4672 
  • trunk/tmdmcreator/src/tmdmprocessor.h

    r15 r16  
    22 tmdmprocessor.h 
    33 ------------------- 
    4  copyright            : (C) 2013 CREALP Lucien Schreiber  
     4 copyright            : (C) 2013 CREALP Lucien Schreiber 
    55 email                : lucien.schreiber at crealp dot vs dot ch 
    66 ***************************************************************************/ 
     
    2525#endif 
    2626 
    27  
    2827class TmDmCopier; 
    29  
    3028class TmDmProcessor { 
    31   protected: 
     29protected: 
    3230    TmDmCopier * m_Copier; 
     31     
     32public: 
     33    TmDmProcessor(); 
     34    virtual ~TmDmProcessor(); 
     35     
     36    int FindBlock(const wxString & blockname); 
     37    virtual bool ProcessBlock(int blockstart, TmDmCopier * copier) = 0; 
     38}; 
    3339 
    3440 
    35   public: 
    36     TmDmProcessor(); 
    3741 
    38     virtual ~TmDmProcessor(); 
    3942 
    40     int FindBlock(const wxString & blockname); 
    4143 
    42     virtual bool ProcessBlock(int blockstart, TmDmCopier * copier) = 0; 
    4344 
     45 
     46class TmDmProcessorSimple : public TmDmProcessor { 
     47public: 
     48    TmDmProcessorSimple(); 
     49    virtual ~TmDmProcessorSimple(); 
     50     
     51    virtual bool ProcessBlock(int blockstart, TmDmCopier * copier); 
    4452}; 
    45 class TmDmProcessorSimple : public TmDmProcessor { 
    46   public: 
    47     TmDmProcessorSimple(); 
    4853 
    49     virtual ~TmDmProcessorSimple(); 
    5054 
     55 
     56 
     57 
     58 
     59 
     60class TmDmProcessorAttributs : public TmDmProcessor { 
     61public: 
     62    TmDmProcessorAttributs(); 
     63    virtual ~TmDmProcessorAttributs(); 
     64     
    5165    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  
    6266}; 
    6367#endif 
Note: See TracChangeset for help on using the changeset viewer.