| 1 | /*************************************************************************** |
|---|
| 2 | tmdmcopier.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 "tmdmcopier.h" |
|---|
| 18 | |
|---|
| 19 | TmDmCopier::TmDmCopier(const wxFileName & destfile) { |
|---|
| 20 | m_File = new wxFFile(); |
|---|
| 21 | bool bOpen = m_File->Open(destfile.GetFullPath(), "a"); |
|---|
| 22 | wxASSERT(bOpen == true); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | TmDmCopier::~TmDmCopier() { |
|---|
| 28 | wxDELETE(m_File); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 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); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 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; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | wxArrayString TmDmCopier::GetErrors(){ |
|---|
| 62 | return m_Errors; |
|---|
| 63 | } |
|---|