1 // convert.h - Convert subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
21 ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat,
22 wxString InputFilename, wxString OutputFilename){
24 std::vector<wxString> ValidFormats = {
29 bool ValidInput = false;
30 bool ValidOutput = false;
32 // Check that the input format is valid.
34 for (long l = 0; l < ValidFormats.size(); l++){
36 if (InputFormat == ValidFormats[l]){
43 if (ValidInput == false){
45 return CONVERTRESULT_INVALIDINPUTFORMAT;
49 // Check that the output format is valid.
51 for (long l = 0; l < ValidFormats.size(); l++){
53 if (OutputFormat == ValidFormats[l]){
60 if (ValidOutput == false){
62 return CONVERTRESULT_INVALIDOUTPUTFORMAT;
66 // Check that the input and output formats
69 if (InputFormat == OutputFormat){
71 return CONVERTRESULT_FORMATSSAME;
75 // Check that the input file given exists.
77 if (!wxFileExists(InputFilename)){
79 return CONVERTRESULT_INPUTFILEMISSING;
85 if (!InputFile.Open(InputFilename, wxFile::read, wxS_DEFAULT)){
87 int InputFileErrNo = InputFile.GetLastError();
89 return CONVERTRESULT_INPUTFILEERROR;
93 // Check that the output file can be opened.
97 if (!OutputFilename.IsEmpty()){
99 if (!OutputFile.Open(OutputFilename, wxFile::write, wxS_DEFAULT)){
100 return CONVERTRESULT_OUTPUTFILEERROR;
105 return CONVERTRESULT_OK;