📄 poomfilemanagement.cpp
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
//
// @author Marco Magistrali
//
#include <windows.h>
#include <oleauto.h>
#include "pimstore.h"
#include <stdio.h>
#include "base/Log.h"
#include "pim/Utils.h"
#include "pim/POOMFileManagement.h"
#include "pim/SettingFunctions.h"
/*
*
* FILE MANAGEMENT
*
*
*/
void writeToFile(vector<long> ¤tOid, vector<long> ¤tHash, int dataType, wchar_t* path) {
wchar_t wfilename[DIM_FILE];
wchar_t* pt = NULL;
char filename [DIM_FILE];
BOOL usedDefaultChar;
if (dataType == olFolderContacts)
pt = TEXT(FILENAME_CONTACTS);
else if (dataType == olFolderCalendar)
pt = TEXT(FILENAME_APPOINTMENTS);
else if (dataType == olFolderTasks)
pt = TEXT(FILENAME_TASKS);
if (wcscmp(path, TEXT("\\")) == 0)
wsprintf(wfilename, TEXT("\\%s"),pt);
else
wsprintf(wfilename, TEXT("%s\\%s"),path, pt);
WideCharToMultiByte (CP_ACP, 0, wfilename, 255, filename, 255, "?", &usedDefaultChar);
FILE* f;
if (dataType == olFolderContacts) {
f = fopen(filename, "w+");
fwprintf(f, TEXT("<contacts>\n"));
}
else if (dataType == olFolderCalendar){
f = fopen(filename, "w+");
fwprintf(f, TEXT("<appointments>\n"));
}
else if (dataType == olFolderTasks){
f = fopen(filename, "w+");
fwprintf(f, TEXT("<tasks>\n"));
}
//~fwprintf(f, TEXT("<num>%i</num>\n"), length(currentOid));
fwprintf(f, TEXT("<num>%i</num>\n"), currentOid.size());
//~int oidLength = length(currentOid);
int oidLength = currentOid.size();
for (int i = 0; i < oidLength; i++) {
long currentLongOid = currentOid[i];
long currentLongHash = currentHash[i];
fwprintf(f, TEXT("<item>\n"));
fwprintf(f, TEXT("<oid>%i</oid>\n"), currentLongOid);
fwprintf(f, TEXT("<hash>%i</hash>\n"), currentLongHash);
fwprintf(f, TEXT("</item>\n"));
}
if (dataType == olFolderContacts) {
fwprintf(f, TEXT("</contacts>\n"));
}
else if (dataType == olFolderCalendar){
fwprintf(f, TEXT("</appointments>\n"));
}
else if (dataType == olFolderTasks){
fwprintf(f, TEXT("</tasks>\n"));
}
fflush(f);
fclose(f);
}
// method used to check if file with previous appointments or contacts exist! if not exists force slow sync
BOOL existsFile(int dataType, wchar_t* path) {
wchar_t wfilename[DIM_FILE];
wchar_t* pt = NULL;
char filename [DIM_FILE];
BOOL usedDefaultChar;
BOOL exists = FALSE;
if (dataType == olFolderContacts)
pt = TEXT(FILENAME_CONTACTS);
else if (dataType == olFolderCalendar)
pt = TEXT(FILENAME_APPOINTMENTS);
else if (dataType == olFolderTasks)
pt = TEXT(FILENAME_TASKS);
else if (dataType == constFiles)
pt = TEXT(FILENAME_FILES);
else if (dataType == constNotes)
pt = TEXT(FILENAME_NOTES);
else if (dataType == constFavorites)
pt = TEXT(FILENAME_FAVORITES);
wsprintf(wfilename, TEXT("%s\\%s"),path, pt);
WideCharToMultiByte (CP_ACP, 0, wfilename, DIM_FILE -1, filename, DIM_FILE -1, "?", &usedDefaultChar);
FILE* f = NULL;
f = fopen(filename, "r");
if (f != NULL) {
fflush(f);
fclose(f);
exists = TRUE;
}
return exists;
}
void readFromFile(long* previousCountItem, vector<long> &previousOid, vector<long> &previousHash, int dataType, wchar_t* path) {
wchar_t wfilename[DIM_FILE];
wchar_t* pt = NULL;
char filename [DIM_FILE];
BOOL usedDefaultChar;
if (dataType == olFolderContacts)
pt = TEXT(FILENAME_CONTACTS);
else if (dataType == olFolderCalendar)
pt = TEXT(FILENAME_APPOINTMENTS);
else if (dataType == olFolderTasks)
pt = TEXT(FILENAME_TASKS);
if (wcscmp(path, TEXT("\\")) == 0)
wsprintf(wfilename, TEXT("\\%s"), pt);
else
wsprintf(wfilename, TEXT("%s\\%s"),path, pt);
WideCharToMultiByte (CP_ACP, 0, wfilename, DIM_FILE -1, filename, DIM_FILE -1, "?", &usedDefaultChar);
wchar_t* element = NULL;
wchar_t line[100];
FILE* f;
wchar_t* tmp = NULL;
if (dataType == olFolderContacts)
f = fopen(filename, "r");
else if (dataType == olFolderCalendar)
f = fopen(filename, "r");
else if (dataType == olFolderTasks)
f = fopen(filename, "r");
while(fgetws(line, 99, f) != NULL) {
if ((element = getElementContent(line, TEXT("oid"), NULL)) != NULL) {
previousOid.push_back(wcstol(element, &tmp, 0));
}
else if ((element = getElementContent(line, TEXT("hash"), NULL)) != NULL) {
previousHash.push_back(wcstol(element, &tmp, 0));
}
else if ((element = getElementContent(line, TEXT("num"), NULL)) != NULL) {
(*previousCountItem) = wcstol(element, &tmp, 0);
}
delete [] element;
}
fflush(f);
fclose(f);
}
void readAppOidToReset(vector<long> &oidToReset, wchar_t* wpath) {
wstring filename(L"appOidToReset.dat");
wstring path(wpath);
path += L"\\";
path += filename;
wchar_t* element = NULL;
wchar_t line[100];
FILE* f;
wchar_t* tmp = NULL;
f = _wfopen(path.c_str(), L"r");
if (!f) {
return;
}
while(fgetws(line, 99, f) != NULL) {
if ((element = getElementContent(line, TEXT("oid"), NULL)) != NULL) {
oidToReset.push_back(wcstol(element, &tmp, 0));
}
delete [] element;
}
fflush(f);
fclose(f);
DeleteFile(path.c_str());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -