static void SaveVersionHeader(GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wType, const wchar_t *key, void *value)
{
  WCToUTF16LEHlpr cnv;
  if (!cnv.Create(key)) throw std::runtime_error("Unicode conversion failed");
  SaveVersionHeaderUTF16LE(strm, wLength, wValueLength, wType, cnv.Get(), value);
  cnv.Destroy();
}
示例#2
0
int ExeHeadStringList::add(const TCHAR *str, WORD codepage, bool processed)
{
  char *p = (char*) m_gr.get();
  if (!p)
  {
    if (!*str) return 0; // Delay allocating the empty string
    char *&zero = p, cb = 1 + !!m_wide;
    unsigned int pos = m_gr.add(&zero,cb);
    assert(0 == pos);
  }

  char *bufMB = 0;
  unsigned int pos = find(str,codepage,processed,m_wide ? 0 : &bufMB);
  if ((unsigned)-1 != pos)
  {
    delete[] bufMB;
    return pos;
  }

  if (m_wide)
  {
    WCToUTF16LEHlpr cnv;
    if (!cnv.Create(str)) throw std::bad_alloc();
    pos = m_gr.add(cnv.Get(),cnv.GetSize()) / WIDEDIV;
    cnv.Destroy();
  }
  else
  {
    unsigned int cbMB = strlen(bufMB) + 1;
    pos = m_gr.add(bufMB,cbMB);
    delete[] bufMB;
  }
  return pos;
}
示例#3
0
WINWCHAR* WinWStrDupFromWC(const wchar_t *s)
{
#ifdef MAKENSIS
  WCToUTF16LEHlpr cnv;
  if (!cnv.Create(s)) throw runtime_error("Unicode conversion failed");
  return (WINWCHAR*) cnv.Detach();
#else
  // NOTE: Anything outside the ASCII range will not convert correctly!
  size_t cch = wcslen(s);
  WINWCHAR* p = (WINWCHAR*) malloc(++cch * 2);
  if (p) for (size_t i = 0; i < cch; ++i) p[i] = (unsigned char) s[i];
  return p;
#endif
}
示例#4
0
/*
 * find() finds the offset where the string is stored, returns -1 if not found.
 * It only compares raw byte values, there is no Unicode normalization handling.
 * If ppBufMB is non-null you must delete[] it (Only valid when m_wide is false)!
*/
unsigned int ExeHeadStringList::find(const TCHAR *str, WORD codepage, bool processed, char**ppBufMB) const
{
  if (m_wide && *str)
  {
    WCToUTF16LEHlpr cnv;
    if (!cnv.Create(str)) return -1;
    unsigned int pos = find(cnv.Get(),StrLenUTF16(cnv.Get()),codepage,processed,ppBufMB);
    cnv.Destroy();
    return pos;
  }
  else
  {
    return find(str,_tcslen(str),codepage,processed,ppBufMB);
  }
}
示例#5
0
static WINWCHAR* ResStringToUnicode(const TCHAR *s) {
  if (IS_INTRESOURCE(s)) return MAKEINTRESOURCEWINW((ULONG_PTR)s);
  WCToUTF16LEHlpr cnv;
  if (!cnv.Create(s)) throw std::runtime_error("Unicode conversion failed");
  return (WINWCHAR*) cnv.Detach();
}