Example #1
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;
}
Example #2
0
int set_path(exword_t *d, char* device, char *pathname)
{
	char *path, *p;
	int rsp, i = 0, j;
	path = malloc(strlen(device) + strlen(pathname) + 2);
	if (!path)
		return 0x50;
	strcpy(path, device);
	strcat(path, "\\");
	strcat(path, pathname);
	p = path;
	while(p[0] != '\0') {
		while((p[0] == '/' || p[0] == '\\') &&
		      (p[1] == '/' || p[1] == '\\')) {
			char *t = p;
			while(t[0] != '\0') {
				t++;
				t[-1] = t[0];
			}
		}
		if (p[0] == '/')
			p[0] = '\\';
		p++;
	}
	rsp = exword_setpath(d, path, SETPATH_NOCREATE);
fail:
	free(path);
	return rsp;
}
Example #3
0
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;
}
Example #4
0
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);
}
Example #5
0
bool Exword::Connect(ExwordMode mode, ExwordRegion region)
{
    unsigned short options = 0;
    m_connected = false;
    switch(mode) {
    case LIBRARY:
        options |= EXWORD_MODE_LIBRARY;
        break;
    case TEXT:
        options |= EXWORD_MODE_TEXT;
        break;
    case CD:
        options |= EXWORD_MODE_CD;
    }
    switch(region) {
    case JAPANESE:
        options |= EXWORD_REGION_JA;
        break;
    case CHINESE:
        options |= EXWORD_REGION_CN;
        break;
    case INDIAN:
        options |= EXWORD_REGION_IN;
        break;
    case KOREAN:
        options |= EXWORD_REGION_KR;
        break;
    case ITALIAN:
        options |= EXWORD_REGION_IT;
        break;
    case GERMAN:
        options |= EXWORD_REGION_DE;
        break;
    case SPANISH:
        options |= EXWORD_REGION_ES;
        break;
    case FRENCH:
        options |= EXWORD_REGION_FR;
        break;
    case RUSSIAN:
        options |= EXWORD_REGION_RU;
        break;
    }
    if (exword_connect(m_device, options) == EXWORD_SUCCESS) {
        exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0);
        m_connected = true;
        m_mode = mode;
        m_region = region;
        m_storage = INTERNAL;
        m_timer.Start(100);
    }
    return m_connected;
}
Example #6
0
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);
    }
}
Example #7
0
bool Exword::Authenticate(wxString user, wxMemoryBuffer& key)
{
    bool success = false;
    int rsp;
    uint16_t count;
    exword_dirent_t *entries;
    exword_authchallenge_t c;
    exword_authinfo_t ai;
    exword_userid_t u;

    if (!IsConnected())
        return success;

    memcpy(c.challenge, key.GetData(), 20);
    memcpy(ai.blk1, "FFFFFFFFFFFFFFFF", 16);
    strncpy((char*)ai.blk2, user.utf8_str().data(), 24);
    strncpy(u.name, user.utf8_str().data(), 16);
    exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0);
    rsp = exword_authchallenge(m_device, c);
    if (rsp == EXWORD_SUCCESS) {
        exword_setpath(m_device, (uint8_t*)"", 0);
        exword_list(m_device, &entries, &count);
        for (int i = 0; i < count; i++) {
            if (strcmp((const char*)entries[i].name, "_SD_00") == 0) {
                exword_setpath(m_device, (uint8_t*)"\\_SD_00", 0);
                rsp = exword_authchallenge(m_device, c);
                if (rsp != EXWORD_SUCCESS)
                    exword_authinfo(m_device, &ai);
             }
        }
        exword_free_list(entries);
        exword_userid(m_device, u);
        success = true;
    }
    return success;
}
Example #8
0
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;
}
Example #9
0
wxMemoryBuffer Exword::Reset(wxString user)
{
    wxMemoryBuffer key(20);
    exword_authinfo_t ai;
    exword_userid_t u;

    if (!IsConnected())
        return key;

    memset(&ai, 0, sizeof(exword_authinfo_t));
    memset(&u, 0, sizeof(exword_userid_t));
    memcpy(ai.blk1, "FFFFFFFFFFFFFFFF", 16);
    strncpy((char*)ai.blk2, user.utf8_str().data(), 24);
    strncpy(u.name, user.utf8_str().data(), 16);
    exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0);
    exword_authinfo(m_device, &ai);
    exword_userid(m_device, u);
    key.AppendData(ai.challenge, 20);
    return key;
}
Example #10
0
bool Exword::IsSdInserted()
{
    exword_dirent_t *entries;
    uint16_t count;
    bool found = false;

    if (!IsConnected())
         return found;

    if (exword_setpath(m_device, (uint8_t*)"", 0) == EXWORD_SUCCESS) {
        if (exword_list(m_device, &entries, &count) == EXWORD_SUCCESS) {
            for (int i = 0; i < count; i++) {
                if (strcmp((const char*)entries[i].name, "_SD_00") == 0)
                    found = true;
            }
            exword_free_list(entries);
        }
    }

    return found;
}