+ // Check that the input filename is not empty.
+
+ if (InputFilename.empty()){
+
+ return CONVERTRESULT_INPUTFILEEMPTY;
+
+ }
+
+ // Check that the input file given exists.
+
+ if (!wxFileExists(InputFilename)){
+
+ return CONVERTRESULT_INPUTFILEMISSING;
+
+ }
+
+ wxFile InputFile;
+
+ if (!InputFile.Open(InputFilename, wxFile::read, wxS_DEFAULT)){
+
+ return CONVERTRESULT_INPUTFILEERROR;
+
+ }
+
+ // Check that the output file can be opened.
+
+ bool OutputPipe = false;
+ wxFile OutputFile;
+
+ if (!OutputFilename.IsEmpty()){
+
+ if (!OutputFile.Open(OutputFilename, wxFile::write, wxS_DEFAULT)){
+ return CONVERTRESULT_OUTPUTFILEERROR;
+ }
+
+ } else {
+
+ OutputPipe = true;
+
+ }
+
+ // Check that the file has the correct file format.
+
+ vCard vCard4Format;
+ wxString FinalData;
+
+ if (InputFormat == "vCard4"){
+
+ // Read from the file.
+
+ wxString InputFileData;
+ InputFile.ReadAll(&InputFileData, wxConvAuto());
+
+ vCard vCard4Format;
+
+ vCard4Format.LoadString(InputFileData);
+
+ if (vCard4Format.Get("VERSION") != "4.0"){
+ return CONVERTRESULT_INPUTFILEINVALIDFORMAT;
+ }
+
+ } else if (InputFormat == "vCard3"){
+
+ // Read from the file.
+
+ wxString InputFileData;
+ InputFile.ReadAll(&InputFileData, wxConvAuto());
+
+ vCard InputvCard;
+
+ InputvCard.LoadString(InputFileData);
+
+ if (InputvCard.Get("VERSION") != "3.0"){
+ return CONVERTRESULT_INPUTFILEINVALIDFORMAT;
+ }