1 // export-vcard4.cpp - Export vCard4 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/>
20 #include <wx/arrstr.h>
21 #include <wx/filefn.h>
22 #include <wx/tokenzr.h>
24 void ExportVCard4(bool DirMode, wxString OutputLocation, wxArrayString *FileList, int *ExportCount){
26 // Export a vCard 4.0 contact file.
30 // Output each contact into the directory.
32 // Simply just copy the files unchanged.
35 wxString FinalFilename;
37 for (int i = 0; i < FileList->GetCount(); i++){
39 // Get the final part of the path (filename).
41 #if defined(__HAIKU__)
44 #elif defined(__WIN32__)
46 wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
48 while (FileToken.HasMoreTokens()){
49 Filename = FileToken.GetNextToken();
52 // Copy the file to the requested directory.
54 FinalFilename.Append(OutputLocation);
55 FinalFilename.Append(wxT("/"));
56 FinalFilename.Append(Filename);
60 wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
62 while(FileToken.HasMoreTokens()){
63 Filename = FileToken.GetNextToken();
66 // Copy the file to the requested directory.
68 FinalFilename.Append(OutputLocation);
69 FinalFilename.Append(wxT("/"));
70 FinalFilename.Append(Filename);
77 FinalFilename.Clear();
83 // Output all contacts into one file.
88 // Open the output file.
90 #if wxABI_VERSION < 20900
91 OutputFile.Open(OutputLocation.c_str(), wxT("w"));
93 OutputFile.Open(OutputLocation, wxT("w"));
96 wxString InputFileData;
98 for (int i = 0; i < FileList->GetCount(); i++){
100 // Open up the input file.
102 InputFile.Open(FileList->Item(i), wxT("r"));
104 InputFile.ReadAll(&InputFileData, wxConvAuto());
106 OutputFile.Write(InputFileData, wxConvAuto());
109 InputFileData.Clear();