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 | m_File->Flush(); |
---|
29 | wxDELETE(m_File); |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | bool TmDmCopier::CopyFrom(const wxFileName & filename) { |
---|
35 | wxFFile mySrcFile; |
---|
36 | if (mySrcFile.Open(filename.GetFullPath()) == false) { |
---|
37 | m_Errors.Add(wxString::Format(_("Unable to open: %s"), filename.GetFullPath())); |
---|
38 | return false; |
---|
39 | } |
---|
40 | |
---|
41 | wxString mySrcTxt; |
---|
42 | if(mySrcFile.ReadAll(&mySrcTxt)==false){ |
---|
43 | m_Errors.Add(wxString::Format(_("Reading from: %s failed!"), filename.GetFullPath())); |
---|
44 | return false; |
---|
45 | } |
---|
46 | return CopyFrom(mySrcTxt); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | bool TmDmCopier::CopyFrom(const wxString & text) { |
---|
52 | m_File->SeekEnd(); |
---|
53 | if (m_File->Write(text) == false) { |
---|
54 | m_Errors.Add(wxString::Format(_("Writing to: %s failed!"), m_File->GetName())); |
---|
55 | return false; |
---|
56 | } |
---|
57 | |
---|
58 | return true; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | wxArrayString TmDmCopier::GetErrors(){ |
---|
64 | return m_Errors; |
---|
65 | } |
---|