// export-vcard3.cpp - Export vCard3 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 #include "../vcard/vcard.h" #include "../vcard/vcard34conv.h" void ExportVCard3(bool DirMode, wxString OutputLocation, wxArrayString *FileList, int *ExportCount){ // Export a vCard 3.0 contact file. if (DirMode == TRUE){ // Output each contact into the directory. // Load the contact file and covert it to vCard 3.0. wxString Filename; wxString FinalFilename; wxString ContactData; for (int i = 0; i < FileList->GetCount(); i++){ // Get the final part of the path (filename). vCard34Conv vCardConvObj; vCardConvObj.ConvertToV3(FileList->Item(i), &ContactData); #if defined(__HAIKU__) #elif defined(__WIN32__) wxStringTokenizer FileToken(FileList->Item(i), wxT("\\")); while (FileToken.HasMoreTokens()){ Filename = FileToken.GetNextToken(); } FinalFilename.Append(OutputLocation); FinalFilename.Append(wxT("\\")); FinalFilename.Append(Filename); #else wxStringTokenizer FileToken(FileList->Item(i), wxT("//")); while(FileToken.HasMoreTokens()){ Filename = FileToken.GetNextToken(); } FinalFilename.Append(OutputLocation); FinalFilename.Append(wxT("/")); FinalFilename.Append(Filename); #endif // Write the converted card to the file. wxFFile OutputFile; #if wxABI_VERSION < 20900 OutputFile.Open(FinalFilename, wxT("w")); #else OutputFile.Open(FinalFilename, wxT("w")); #endif OutputFile.Write(ContactData, wxConvAuto()); OutputFile.Close(); (*ExportCount)++; Filename.Clear(); FinalFilename.Clear(); ContactData.Clear(); } } else { // Output all contacts into one file. wxFFile OutputFile; // 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. vCard34Conv vCardConvObj; vCardConvObj.ConvertToV3(FileList->Item(i), &InputFileData); OutputFile.Write(InputFileData, wxConvAuto()); InputFileData.Clear(); (*ExportCount)++; } OutputFile.Close(); } }