Example #1
0
void ProcessChanges(wchar_t* dir){
	
	HANDLE hFind = INVALID_HANDLE_VALUE;
	WIN32_FIND_DATA ffd;
	TCHAR szDir[MAX_PATH];

	StringCchCopy(szDir, MAX_PATH, dir);
    StringCchCat(szDir, MAX_PATH, TEXT("\\*"));

	stringstream idfile;
	idfile << ws2s(dir) << "\\.id";

	stringstream revfile;
	revfile << ws2s(dir) << "\\.rev";

	
	string id = readSingleLine(idfile.str().c_str());
	string rev = readSingleLine(revfile.str().c_str());
	
	if ( id.length() == 0 ){
		return;
	}

	hFind = FindFirstFile(szDir, &ffd);

	bool hasUploadedAttachments = false;
				

	do
    {
		if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
		}
		else
		{
			if ( wcscmp(L".id", ffd.cFileName) != 0 && wcscmp(L".rev", ffd.cFileName) != 0 ){
				wchar_t filename[MAX_PATH];
				StringCchCopy(filename, MAX_PATH, dir);
				StringCchCat(filename, MAX_PATH, L"\\");
				StringCchCat(filename, MAX_PATH, ffd.cFileName);

				string c = md5file(filename);

				/* Compare to content md5 of attachment in the db */
				Document doc = db.getDocument(id, rev);
				try {
					Attachment a = doc.getAttachment(ws2s(ffd.cFileName));
					string serverMD5 = a.getContentMD5();
					const char* j = serverMD5.c_str();
					int i = strcmp(c.c_str(), j);
					if ( i != 0 ) {
						doc.updateAttachmentFromFile(a.getID(), ws2s(filename));
						hasUploadedAttachments = true;
					}
				}catch(AttachmentNotFoundException e){
					doc.addAttachmentFromFile(ws2s(ffd.cFileName), "", ws2s(filename));
					hasUploadedAttachments = true;
				}
			}
		}
	}
	while (FindNextFile(hFind, &ffd) != 0);

	FindClose(hFind);

	if ( hasUploadedAttachments ){
		PostMessage(GetParent(attachmentsHwnd), WM_ATTACHMENTS_UPLOADED, 0, 0);
	}

}