// export-vcard4.cpp - Export vCard4 subroutines. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include #include #include #include void ExportVCard4(bool DirMode, wxString OutputLocation, wxArrayString *FileList, int *ExportCount){ // Export a vCard 4.0 contact file. if (DirMode == TRUE){ // Output each contact into the directory. // Simply just copy the files unchanged. wxString Filename; wxString FinalFilename; for (int i = 0; i < FileList->GetCount(); i++){ // Get the final part of the path (filename). #if defined(__HAIKU__) #elif defined(__WIN32__) wxStringTokenizer FileToken(FileList->Item(i), wxT("//")); while (FileToken.HasMoreTokens()){ Filename = FileToken.GetNextToken(); } // Copy the file to the requested directory. FinalFilename.Append(OutputLocation); FinalFilename.Append(wxT("/")); FinalFilename.Append(Filename); #else wxStringTokenizer FileToken(FileList->Item(i), wxT("//")); while(FileToken.HasMoreTokens()){ Filename = FileToken.GetNextToken(); } // Copy the file to the requested directory. FinalFilename.Append(OutputLocation); FinalFilename.Append(wxT("/")); FinalFilename.Append(Filename); #endif (*ExportCount)++; Filename.Clear(); FinalFilename.Clear(); } } else { // Output all contacts into one file. wxFFile OutputFile; wxFFile InputFile; // Open the output file. #if wxABI_VERSION < 20900 OutputFile.Open(OutputLocation.c_str(), wxT("w")); #else OutputFile.Open(OutputLocation, wxT("w")); #endif wxString InputFileData; for (int i = 0; i < FileList->GetCount(); i++){ // Open up the input file. InputFile.Open(FileList->Item(i), wxT("r")); InputFile.ReadAll(&InputFileData, wxConvAuto()); OutputFile.Write(InputFileData, wxConvAuto()); InputFile.Close(); InputFileData.Clear(); (*ExportCount)++; } OutputFile.Close(); } }