/** Removes the standard storage path and replace with a tag */ QString PathUtils::RemoveStoragePath(QString path) { // Depending on the platform, we might get either "/" or "\" // so we need to go to the standard ("/") QString goodPath = QDir::fromNativeSeparators(path); if (goodPath.startsWith(GetStoragePath())) { int i = goodPath.length()- GetStoragePath().length(); return QString("%%STOREPATH%%") + goodPath.right(i); } else return goodPath; }
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; }
bool Exword::RemoveDictionary(RemoteDictionary *dict) { bool success = false; exword_cryptkey_t ck; int rsp; if (!IsConnected()) return success; if (dict->Exists()) { 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); exword_setpath(m_device, (uint8_t*)GetStoragePath().utf8_str().data(), 0); 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) rsp |= exword_remove_file(m_device, (char*)dict->GetId().utf8_str().data(), 0); rsp |= exword_lock(m_device); success = (rsp == EXWORD_SUCCESS); } return success; }
/** Inserts the standard storage path is there is a storage path tag */ QString PathUtils::InsertStoragePath(QString path) { if (path.startsWith(QString("%%STOREPATH%%"))) { QString newPath = GetStoragePath(); newPath += path.right(path.length() - 13); return QDir::toNativeSeparators(newPath); } return QDir::toNativeSeparators(path); }
Capacity Exword::GetCapacity() { exword_capacity_t cap = {0,}; int rsp; if (IsConnected()) { exword_setpath(m_device, (uint8_t*)GetStoragePath().utf8_str().data(), 0); rsp = exword_get_capacity(m_device, &cap); if (rsp != EXWORD_SUCCESS) return Capacity(); } return Capacity(cap.total, cap.free); }
void Exword::ReadAdmini(wxMemoryBuffer& buffer) { int rsp, length; char *data; exword_setpath(m_device, (uint8_t*)GetStoragePath().utf8_str().data(), 0); for (int i = 0; admini_list[i] != NULL; i++) { rsp = exword_get_file(m_device, (char*)admini_list[i], &data, &length); if (rsp == EXWORD_SUCCESS && length > 0) { buffer.AppendData(data, length); free(data); break; } free(data); } }
DirEnts Exword::List(wxString path, wxString pattern) { exword_dirent_t *entries; uint16_t count; DirEnts list; wxString fullpath = GetStoragePath() + path; if (IsConnected()) { if (exword_setpath(m_device, (uint8_t*)fullpath.utf8_str().data(), 0) == EXWORD_SUCCESS) { if (exword_list(m_device, &entries, &count) == EXWORD_SUCCESS) { for (int i = 0; i < count; i++) { DirEntry entry(&entries[i]); if (wxMatchWild(pattern.Lower(), entry.GetFilename().Lower(), true)) list.Add(entry); } exword_free_list(entries); } } } return list; }