static int __crypt( crypt_handle * ch, char * in, char * out, int blocks, int enc ) { if ( !ch || !in || !out || blocks <= 0 ) return -1; while ( blocks-- ) { if ( crypt_data( ch, in, out, 8, enc ) <= 0 ) return -1; in += 8; out += 8; } return 0; }
bool Exword::InstallDictionary(LocalDictionary *dict) { bool success = false; exword_cryptkey_t ck; Capacity cap; wxArrayString files; int rsp; if (!IsConnected()) return success; wxString content_path = GetStoragePath() + dict->GetId() + wxT("\\_CONTENT"); wxString user_path = GetStoragePath() + dict->GetId() + wxT("\\_USER"); memset(&ck, 0, sizeof(exword_cryptkey_t)); memcpy(ck.blk1, key1, 2); memcpy(ck.blk1 + 10, key1 + 10, 2); memcpy(ck.blk2, key1 + 2, 8); memcpy(ck.blk2 + 8, key1 + 12, 4); if (dict->Exists()) { rsp = exword_unlock(m_device); rsp |= exword_cname(m_device, (char*)dict->GetName().mb_str(wxCSConv(wxT("SJIS"))).data(), (char*)dict->GetId().utf8_str().data()); rsp |= exword_cryptkey(m_device, &ck); if (rsp == EXWORD_SUCCESS) { files = dict->GetFiles(); exword_setpath(m_device, (uint8_t*)content_path.utf8_str().data(), 1); for (unsigned int i = 0; i < files.GetCount(); ++i) { wxFile file(files[i]); wxFileName filename(files[i]); wxString ext = filename.GetExt(); if (file.IsOpened()) { char *data = new char[file.Length()]; file.Read(data, file.Length()); if (ext == wxT("txt") || ext == wxT("bmp") || ext == wxT("htm") || ext == wxT("TXT") || ext == wxT("BMP") || ext == wxT("HTM")) { crypt_data(data, file.Length(), (char *)ck.xorkey); } rsp |= exword_send_file(m_device, (char*)filename.GetFullName().utf8_str().data(), data, file.Length()); delete [] data; } } exword_setpath(m_device, (uint8_t*)user_path.utf8_str().data(), 1); } rsp |= exword_lock(m_device); success = (rsp == EXWORD_SUCCESS); } return success; }