Exemplo n.º 1
0
bool
SKKCandList::append_candidate (const WideString &cand,
                               const WideString &annot,
                               const WideString &cand_orig,
                               const AttributeList &attrs)
{
    if (cand.length() == 0)
        return false;

    if (m_candvec.size() < candvec_size) {
        m_candvec.push_back(CandEnt(cand, annot, cand_orig));
        return true;
    } else {
        m_annot_buf->m_index.push_back(m_annot_buf->m_buffer.size());
        if (!annot.empty())
            m_annot_buf->m_buffer.insert(m_annot_buf->m_buffer.end(),
                                      annot.begin(), annot.end());
        m_cand_orig_buf->m_index.push_back(m_cand_orig_buf->m_buffer.size());
        if (!cand_orig.empty())
            m_cand_orig_buf->m_buffer.insert(m_cand_orig_buf->m_buffer.end(),
                                             cand_orig.begin(),
                                             cand_orig.end());
        return CommonLookupTable::append_candidate(cand, attrs);
    }
}
 /**
  * Constructs a secure random number generator (RNG) implementing the named
  * random number algorithm if specified
  */
 SecureRandom::SecureRandom(const WideString& algorithm)   
     : m_lock(new Mutex),
       m_impl(SecureRandomBase::createInstance(TextConvert::WideToNarrow(AlgorithmName::normalizeAlgorithm(algorithm)), nullptr, 0))
 {
     ASSERT( !algorithm.empty() );
     ASSERT(m_lock.get() != nullptr);
     ASSERT(m_impl.get() != nullptr);
 }
Exemplo n.º 3
0
void
SKKInstance::update_candidates (void)
{
    if (m_skkcore.has_commit_string()) {
        commit_string(m_skkcore.get_commit_string());
        m_skkcore.clear_commit();
    }

    WideString preedit;
    AttributeList alist;
    m_skkcore.get_preedit_string(preedit);
    m_skkcore.get_preedit_attributes(alist);
    update_preedit_string(preedit, alist);
    if (!preedit.empty()) {
        update_preedit_caret(m_skkcore.caret_pos());
        show_preedit_string();
    } else {
        hide_preedit_string();
    }

    if (annot_view && !annot_pos &&
            m_skkcore.get_input_mode() == INPUT_MODE_CONVERTING) {
        WideString auxstr;
        m_skkcore.get_lookup_table().get_annot_string(auxstr);
        update_aux_string(auxstr);
        if (!auxstr.empty())
            show_aux_string();
        else
            hide_aux_string();
    } else {
        update_aux_string(WideString());
        hide_aux_string();
    }

    if (m_skkcore.get_input_mode() == INPUT_MODE_CONVERTING &&
            m_skkcore.lookup_table_visible()) {
        update_lookup_table(m_skkcore.get_lookup_table());
        show_lookup_table();
    } else {
        hide_lookup_table();
    }
}
  AlgorithmName::AlgorithmName(const WideString& algorithm, bool cipherOnly)
    : m_normal(TextConvert::WideToNarrow(normalizeAlgorithm(algorithm)))
  {
    ASSERT( !algorithm.empty() );

    // We'd prefer to throw in the ctor, but its a limitation, not a feature!
    // Actually, we need to narmalize first (in case of throw), so maybe it is a feature.
    NarrowString cipher;
    getCipher(cipher);

    if(cipherOnly && m_normal != cipher)
      throw NoSuchAlgorithmException(m_normal + " not available");
  }
Exemplo n.º 5
0
WideString
SKKCandList::get_candidate (int index) const
{
    WideString cand = CommonLookupTable::get_candidate(index);
    if (annot_view && annot_pos &&
        (annot_target || get_cursor_pos() == index)) {
        WideString annot = get_annot(index);
        if (!annot.empty()) {
            if (!annot_highlight)
                cand += utf8_mbstowcs(";");
            cand += get_annot(index);
        }
    }
    return cand;
}
Exemplo n.º 6
0
bool MailSender::SendEmail(const WideString& email, const WideString& subject, const WideString& messageText)
{
	// Don't try to send email if recipient is not set
	if (email.empty() || email == L"")
		return false;
	WideString mailtoText = L"";
	
	// Create mailto text
	mailtoText = Format(L"mailto:?to=%s&subject=%s&body=%s", email.c_str(), subject.c_str(), messageText.c_str());
	// Call default mail client
	int result = (int)ShellExecute(NULL, L"open", mailtoText.c_str(), NULL, NULL, SW_SHOWNORMAL);
	
	// If the function succeeds, it returns a value greater than 32.
	// If the function fails, it returns an error value that indicates the cause of the failure. 
	return (result > 32);
}
Exemplo n.º 7
0
AttributeList
SKKCandList::get_attributes (int index) const
{
    AttributeList al = CommonLookupTable::get_attributes(index);
    if (annot_view && annot_pos &&
        (annot_target || get_cursor_pos() == index)) {
        WideString annot = get_annot(index);
        WideString cand = get_cand(index);
        if (annot_highlight && !annot.empty()) {
            al.push_back(Attribute(cand.length(), annot.length(),
                                   SCIM_ATTR_BACKGROUND,
                                   annot_bgcolor));
        }
    }
    return al;
}
Exemplo n.º 8
0
D2Data::D2Data()
  : itemTypes(DictionaryMap::alNum)
  , baseItems(DictionaryMap::alNum)
  , images(DictionaryMap::pathName)
  , fonts(DictionaryMap::pathName)
{
  WideString path = cfg.getwstr("d2path");
  if (path.empty()) path = getAppPath();
  int loaded = !!loader.loadArchive(WideString::buildFullName(path, L"resources.mpq"));
  loaded += !!loader.loadArchive(WideString::buildFullName(path, L"d2data.mpq"));
  loaded += !!loader.loadArchive(WideString::buildFullName(path, L"d2exp.mpq"));
  loaded += !!loader.loadArchive(WideString::buildFullName(path, L"patch_d2.mpq"));
  if (!loaded)
  {
    path = getAppPath();
    loaded = !!loader.loadArchive(WideString::buildFullName(path, L"resources.mpq"));
  }
  if (!loaded) return;
  cfg.setwstr("d2path", path);

  for (int f = 0; f < 10; f++)
    for (int t = 0; t < 21; t++)
      for (int i = 0; i < 256; i++)
        tints[f][t][i] = i;
  TempFile(loader.load("data\\global\\items\\Palette\\grey.dat"))->read(tints[1], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\grey2.dat"))->read(tints[2], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\gold.dat"))->read(tints[3], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\brown.dat"))->read(tints[4], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\greybrown.dat"))->read(tints[5], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\invgrey.dat"))->read(tints[6], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\invgrey2.dat"))->read(tints[7], 256 * 21);
  TempFile(loader.load("data\\global\\items\\Palette\\invgreybrown.dat"))->read(tints[8], 256 * 21);
  LocalPtr<File> pal = loader.load("data\\global\\palette\\ACT1\\pal.dat");
  for (int i = 0; i < 256; i++)
  {
    int b = pal->getc(), g = pal->getc(), r = pal->getc();//, a = pal->getc();
    palette[i] = Image::clr(r, g, b);
  }

  memset(textColor, 0xFF, sizeof textColor);
  {
    LocalPtr<File> pl2 = loader.load("data\\global\\palette\\ACT1\\Pal.PL2");
    pl2->seek(1024 + 49 * 256, SEEK_SET);
    pl2->read(blendTable, sizeof blendTable);
    pl2->seek(1024 + 1714 * 256, SEEK_SET);
    for (int i = 0; i < 13; i++)
    {
      int r = pl2->getc(), g = pl2->getc(), b = pl2->getc();
      textColor[i] = Image::clr(r, g, b);
    }
    pl2->seek(256, SEEK_CUR);
    for (int i = 1; i < 13; i++)
      pl2->read(tints[9][i], 256);
  }

  strings.load(TempFile(loader.load("data\\local\\lng\\eng\\string.tbl")), 0);
  strings.load(TempFile(loader.load("data\\local\\lng\\eng\\expansionstring.tbl")), 20000);
  strings.load(TempFile(loader.load("data\\local\\lng\\eng\\patchstring.tbl")), 10000);

  rootType.name = "All Items";
  loadTypes(TempFile(loader.load("data\\global\\excel\\ItemTypes.txt")));
  loadBase(TempFile(loader.load("data\\global\\excel\\weapons.txt")));
  loadBase(TempFile(loader.load("data\\global\\excel\\armor.txt")));
  loadBase(TempFile(loader.load("data\\global\\excel\\misc.txt")));
  baseMatch.build();

  itemTypes.get("h2h2").bases = 0;
  itemTypes.get("mcha").name = strings.byIndex(20436);
  itemTypes.get("lcha").name = strings.byIndex(20437);
  itemTypes.get("ques").setType(D2Item::tMisc, 0, 0);
  itemTypes.get("key").setType(D2Item::tMisc, 0, 0);
  itemTypes.get("weap").setType(D2Item::tAuto, 0);
  itemTypes.get("armo").setType(D2Item::tAuto, 1);
  itemTypes.get("ring").setType(D2Item::tAuto, 2);
  itemTypes.get("amul").setType(D2Item::tAuto, 2);
  itemTypes.get("char").setType(D2Item::tCharm, 0);
  itemTypes.get("gem").setType(D2Item::tSocket, 0, 0);
  itemTypes.get("rune").setType(D2Item::tSocket, 1, 0);
  itemTypes.get("jewl").setType(D2Item::tSocket, 2);
  for (uint32 cur = baseItems.enumStart(); cur; cur = baseItems.enumNext(cur))
  {
    D2BaseItem* base = &baseItems.enumGetValue(cur);
    while (base->type && base->type->bases == 0)
      base->type = base->type->parent;
  }
  mergeType(&rootType);

  {
    D2Excel table(TempFile(loader.load("data\\global\\excel\\PlayerClass.txt")));
    int id = 0;
    for (int i = 0; i < table.rows(); i++)
    {
      if (!*table.value(i, 1))
        continue;
      charClass.set(table.value(i, 1), id);
      classNames[id] = strings.byName(table.value(i, 0));
      id++;
    }
  }
  statData = new D2StatData(this);

  loadUnique();
  loadGems();

  loadBackground();

  LocalPtr<mpq::ListFile> list = loader.buildListFile();
  list->sort();
  for (uint32 cur = baseItems.enumStart(); cur; cur = baseItems.enumNext(cur))
    unpack(&loader, list, baseItems.enumGetValue(cur).invfile);
  for (uint32 cur = itemTypes.enumStart(); cur; cur = itemTypes.enumNext(cur))
  {
    D2ItemType& type = itemTypes.enumGetValue(cur);
    for (int i = 0; i < type.invgfx.length(); i++)
      unpack(&loader, list, type.invgfx[i]);
  }
  for (int i = 0; i < uniqueItems.length(); i++)
    unpack(&loader, list, uniqueItems[i]->invfile);
}
 /**
 * Returns a KeyGenerator object that generates secret keys for the specified algorithm.
 */
 KeyGenerator KeyGenerator::getInstance(const WideString& algorithm)
 {
   ASSERT( !algorithm.empty() );
   return KeyGenerator::getInstance(TextConvert::WideToNarrow(algorithm));
 }
 /**
  * Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.
  */
 SecureRandom SecureRandom::getInstance(const WideString& algorithm)   
 {
     ASSERT( !algorithm.empty() );
     return getInstance(TextConvert::WideToNarrow(algorithm));
 }