Пример #1
0
bool CWINFileSMB::Exists(const CURL& url)
{
    CStdString strFile = GetLocal(url);
    URIUtils::RemoveSlashAtEnd(strFile);
    CStdStringW strWFile;
    g_charsetConverter.utf8ToW(strFile, strWFile, false);
    DWORD attributes = GetFileAttributesW(strWFile.c_str());
    if(attributes != INVALID_FILE_ATTRIBUTES)
        return true;

    DWORD err = GetLastError();
    if(err != ERROR_ACCESS_DENIED)
        return false;

    XFILE::CWINSMBDirectory smb;
    if(smb.ConnectToShare(url) == false)
        return false;

    attributes = GetFileAttributesW(strWFile.c_str());

    if(attributes == INVALID_FILE_ATTRIBUTES)
        return false;

    return true;
}
Пример #2
0
//*********************************************************************************************
bool CWINFileSMB::Open(const CURL& url)
{
    CStdString strFile = GetLocal(url);

    CStdStringW strWFile;
    g_charsetConverter.utf8ToW(strFile, strWFile, false);
    m_hFile.attach(CreateFileW(strWFile.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL));

    if (!m_hFile.isValid())
    {
        if(GetLastError() == ERROR_FILE_NOT_FOUND)
            return false;

        XFILE::CWINSMBDirectory smb;
        smb.ConnectToShare(url);
        m_hFile.attach(CreateFileW(strWFile.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL));
        if (!m_hFile.isValid())
        {
            CLog::Log(LOGERROR,"CWINFileSMB: Unable to open file %s Error: %d", strFile.c_str(), GetLastError());
            return false;
        }
    }

    m_i64FilePos = 0;
    Seek(0, SEEK_SET);

    return true;
}
Пример #3
0
void CCharsetConverter::utf16LEtoW(const char* strSource, CStdStringW &strDest)
{
  if (m_iconvUtf16LEtoW == (iconv_t) - 1)
    m_iconvUtf16LEtoW = iconv_open(WCHAR_CHARSET, "UTF-16LE");

  if (m_iconvUtf16LEtoW != (iconv_t) - 1)
  {
    size_t inBytes = 2;
    short* s = (short*) strSource;
    while (*s != 0)
    {
      s++;
      inBytes += 2;
    }
    size_t outBytes = (inBytes + 1)*sizeof(wchar_t);  // UTF-8 is up to 4 bytes/character  
    char *dst = (char*) strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvUtf16LEtoW, &strSource, &inBytes, &dst, &outBytes))
    { // failed :(
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
Пример #4
0
//*********************************************************************************************
bool CWINFileSMB::OpenForWrite(const CURL& url, bool bOverWrite)
{
    CStdString strPath = GetLocal(url);

    CStdStringW strWPath;
    g_charsetConverter.utf8ToW(strPath, strWPath, false);
    m_hFile.attach(CreateFileW(strWPath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, bOverWrite ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));

    if (!m_hFile.isValid())
    {
        if(GetLastError() == ERROR_FILE_NOT_FOUND)
            return false;

        XFILE::CWINSMBDirectory smb;
        smb.ConnectToShare(url);
        m_hFile.attach(CreateFileW(strWPath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, bOverWrite ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));
        if (!m_hFile.isValid())
        {
            CLog::Log(LOGERROR,"CWINFileSMB: Unable to open file for writing '%s' Error '%d%",strPath.c_str(), GetLastError());
            return false;
        }
    }

    m_i64FilePos = 0;
    Seek(0, SEEK_SET);

    return true;
}
Пример #5
0
bool Win32DllLoader::NeedsHooking(const char *dllName)
{
  LibraryLoader *loader = DllLoaderContainer::GetModule(dllName);
  if (loader)
  {
    // may have hooked this already (we can have repeats in the import table)
    for (unsigned int i = 0; i < m_referencedDlls.size(); i++)
    {
      if (loader->GetHModule() == m_referencedDlls[i])
        return false;
    }
  }
  CStdStringW strdllNameW;
  g_charsetConverter.utf8ToW(_P(dllName), strdllNameW, false);
  HMODULE hModule = GetModuleHandleW(strdllNameW.c_str());
  wchar_t filepathW[MAX_PATH];
  GetModuleFileNameW(hModule, filepathW, MAX_PATH);
  CStdString dllPath;
  g_charsetConverter.wToUTF8(filepathW, dllPath);

  // compare this filepath with some special directories
  CStdString xbmcPath = _P("special://xbmc");
  CStdString homePath = _P("special://home");
  CStdString tempPath = _P("special://temp");
  return ((strncmp(xbmcPath.c_str(), dllPath.c_str(), xbmcPath.GetLength()) == 0) ||
    (strncmp(homePath.c_str(), dllPath.c_str(), homePath.GetLength()) == 0) ||
    (strncmp(tempPath.c_str(), dllPath.c_str(), tempPath.GetLength()) == 0));
}
CStdStringW FacadeDocumentProviderImpl::GetDefaultSaveExtensionFromFormatString(const CStdStringW& sAvailableFormats, long lIndex)
{
	if(sAvailableFormats.IsEmpty())
		return _T("wdf");

	int iStartPos = -1;
	int lSkip = (lIndex-1)*2;
	for (int i=0; i<lSkip; i++)
	{
		iStartPos = sAvailableFormats.Find(_T('|'),iStartPos);
	}

	int iFirstDelimeterPos = sAvailableFormats.Find(_T('|'), iStartPos);
	if (iFirstDelimeterPos == iStartPos+1) // we've hit the "||" at the end ...
		iFirstDelimeterPos = sAvailableFormats.Find(_T('|')); // go back to default
	int iNextDelimeterPos = sAvailableFormats.Find(_T('|'),iFirstDelimeterPos);

	CStdStringW sExt = sAvailableFormats.Mid(iFirstDelimeterPos + 1 ,iNextDelimeterPos - iFirstDelimeterPos - 1  );

	int iPeriodPos = sExt.Find(_T('.'));
	sExt = sExt.Mid(iPeriodPos + 1, sExt.length() - iPeriodPos );

	return sExt;

}
Пример #7
0
CStdStringW DocReader::ReadWideString(int iOffset, int iCharCount)
{
	CStdStringW sResult;
	ReadIntoBufferIgnoringBitsInDeletedList(iOffset, iCharCount*2, sResult.GetBuffer(iCharCount + 1), iCharCount*2 + 2);
	sResult.ReleaseBuffer();
	return sResult;
}
Пример #8
0
void CGUIDialogKeyboardGeneric::UpdateLabel() // FIXME seems to be called twice for one USB SDL keyboard action/character
{
  CGUILabelControl* pEdit = ((CGUILabelControl*)GetControl(CTL_LABEL_EDIT));
  if (pEdit)
  {
    CStdStringW edit = m_strEdit;
    if (m_hiddenInput)
    { // convert to *'s
      edit.Empty();
      if (m_lastRemoteClickTime + REMOTE_SMS_DELAY > CTimeUtils::GetFrameTime() && m_strEdit.size())
      { // using the remove to input, so display the last key input
        edit.append(m_strEdit.size() - 1, L'*');
        edit.append(1, m_strEdit[m_strEdit.size() - 1]);
      }
      else
        edit.append(m_strEdit.size(), L'*');
    }
    // convert back to utf8
    CStdString utf8Edit;
    g_charsetConverter.wToUTF8(edit, utf8Edit);
    pEdit->SetLabel(utf8Edit);
    // Send off a search message
    unsigned int now = CTimeUtils::GetFrameTime();
    // don't send until the REMOTE_SMS_DELAY has passed
    if (m_lastRemoteClickTime && m_lastRemoteClickTime + REMOTE_SMS_DELAY >= now)
      return;

    if (m_pCharCallback)
      m_pCharCallback(this, utf8Edit);
  }
}
Пример #9
0
bool Win32DllLoader::Load()
{
  if (m_dllHandle != NULL)
    return true;

  CStdString strFileName = GetFileName();
  CLog::Log(LOGDEBUG, "%s(%s)\n", __FUNCTION__, strFileName.c_str());

  CStdStringW strDllW;
  g_charsetConverter.utf8ToW(_P(strFileName), strDllW);
  m_dllHandle = LoadLibraryExW(strDllW.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  if (!m_dllHandle)
  {
    CLog::Log(LOGERROR, "%s: Unable to load %s (%d)", __FUNCTION__, strFileName.c_str(), GetLastError());
    return false;
  }

  // handle functions that the dll imports
  if (NeedsHooking(strFileName.c_str()))
    OverrideImports(strFileName);
  else
    bIsSystemDll = true;

  return true;
}
Пример #10
0
//EnumWindows handler
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam)
{
    try
    {
        CMWDiscovery* mwd = reinterpret_cast<CMWDiscovery*>(lparam);
        IAccessiblePtr pAccessibleObject;
        HRESULT hr  = ::AccessibleObjectFromWindow( hwnd, OBJID_WINDOW, __uuidof(IAccessible), (void**)&pAccessibleObject );

        if( hr == S_OK )
        {
            if( pAccessibleObject )
            {
                _bstr_t bsName;
                VARIANT varChild;
                varChild.vt = VT_I4;
                varChild.lVal = CHILDID_SELF;
                if (SUCCEEDED(pAccessibleObject->get_accName(varChild, bsName.GetAddress())))
                {
                    CStdStringW name = bsName;
                    CStdString::size_type iFind = name.rfind(mwd->m_name);
                    if(iFind != CStdString::npos )
                    {
                        mwd->m_hwnd = hwnd;
                        return false;
                    }
                }
            }
        }
    }
    catch(...)
    {   //don't want this to stop the handler
        LOG_WS_ERROR(_T("Exception during EnumWindows"));
    }
    return true;
}
_bstr_t GetString(const OcText& value)
{
   if(!value.getBuffer() || (1 > value.getCharacterCount()))
      return _T("");
   
   switch(value.getCharacterEncoding())
   {
      case ENCODING_NONE:
      {
         CStdString val((const TCHAR*)value.getBuffer());
         val.Trim();
         val.ReleaseBuffer();
         return val.c_str();
      }   
      case ENCODING_UTF16:
      {
         CStdStringW wideVal((const wchar_t*)value.getBuffer());
         wideVal.Trim();
         wideVal.ReleaseBuffer();
         return wideVal.c_str();
      }
      default:
      {
         CStdStringA multiByteVal((LPSTR)value.getBuffer());
         multiByteVal.ReleaseBuffer();
         CStdStringW wideVal = MultiByteSupport::ACPToWide(multiByteVal);
         return wideVal.c_str();
      }
   }
}
Пример #12
0
void CCharsetConverter::subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest)
{
  CStdStringA strFlipped;

  // No need to flip hebrew/arabic as mplayer does the flipping

  if (m_iconvSubtitleCharsetToW == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetSubtitleCharSet();
    m_iconvSubtitleCharsetToW = iconv_open(WCHAR_CHARSET, strCharset.c_str());
  }

  if (m_iconvSubtitleCharsetToW != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;
    char *dst = (char*)strDest.GetBuffer(inBytes * sizeof(wchar_t));
    size_t outBytes = inBytes * sizeof(wchar_t);

    if (iconv_const(m_iconvSubtitleCharsetToW, &src, &inBytes, &dst, &outBytes))
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
Пример #13
0
void CCharsetConverter::utf16BEtoUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvUtf16BEtoUtf8 == (iconv_t) - 1)
    m_iconvUtf16BEtoUtf8 = iconv_open("UTF-8", "UTF-16BE");

  if (m_iconvUtf16BEtoUtf8 != (iconv_t) - 1)
  {
    size_t inBytes  = (strSource.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (strSource.length() + 1) * 4;
    const char *src = (const char*) strSource.c_str();
    char       *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(m_iconvUtf16BEtoUtf8, &src, &inBytes, &dst, &outBytes))
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv(m_iconvUtf16BEtoUtf8, NULL, NULL, &dst, &outBytes))
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
Пример #14
0
PerformanceMonitor::PerformanceMonitor(const wchar_t* function) :
	m_function(function)	
{	
	try
	{
		if(PerformanceMonitor::m_timer == PerformanceMonitor::UnknownTimer)
		{			
			DetermineTimer();							
			PerformanceMonitor::m_enableLogging = IsLoggingSystemEnabled();
		}

		if(!PerformanceMonitor::m_enableLogging)
			return;

		if(PerformanceMonitor::m_timer == PerformanceMonitor::HighResolutionTimer)
				QueryPerformanceCounter(&m_start);
		else
			m_startClock = clock();

		CStdStringW sFunction;
		sFunction.Format(_T("Starting %s"), m_function.c_str());
		LOG_WS_INFO(sFunction.c_str());		
	}
	catch(...)
	{
	}
}
Пример #15
0
bool Win32DllLoader::Load()
{
  if (m_dllHandle != NULL)
    return true;

  CStdString strFileName = GetFileName();

  CStdStringW strDllW;
  g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(strFileName), strDllW);
  m_dllHandle = LoadLibraryExW(strDllW.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  if (!m_dllHandle)
  {
    LPVOID lpMsgBuf;
    DWORD dw = GetLastError(); 

    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, 0, (LPTSTR) &lpMsgBuf, 0, NULL );
    CLog::Log(LOGERROR, "%s: Failed to load %s with error %d:%s", __FUNCTION__, CSpecialProtocol::TranslatePath(strFileName).c_str(), dw, lpMsgBuf);
    LocalFree(lpMsgBuf);
    return false;
  }

  // handle functions that the dll imports
  if (NeedsHooking(strFileName.c_str()))
    OverrideImports(strFileName);
  else
    bIsSystemDll = true;

  return true;
}
Пример #16
0
extern "C" HANDLE WINAPI dllFindFirstFileA(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData)
{
  char* p = strdup(lpFileName);
  CORRECT_SEP_STR(p);

  // change default \\*.* into \\* which the xbox is using
  char* e = strrchr(p, '.');
  if (e != NULL && strlen(e) > 1 && e[1] == '*')
  {
    e[0] = '\0';
  }

#ifdef TARGET_WINDOWS
  struct _WIN32_FIND_DATAW FindFileDataW;
  CStdStringW strwfile;
  g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(p), strwfile, false);
  HANDLE res = FindFirstFileW(strwfile.c_str(), &FindFileDataW);
  if (res != INVALID_HANDLE_VALUE)
    to_WIN32_FIND_DATA(&FindFileDataW, lpFindFileData);
#else
  HANDLE res = FindFirstFile(CSpecialProtocol::TranslatePath(p).c_str(), lpFindFileData);
#endif
  free(p);
  return res;
}
Пример #17
0
void CKeyboardLayoutConfiguration::readByteMapFromXML(const TiXmlElement* pXMLMap, map<BYTE, WCHAR>& charToCharMap, const char* mapRootElement)
{
  if (pXMLMap && !pXMLMap->NoChildren())
  { // map keys
    const TiXmlElement* pEntry = pXMLMap->FirstChildElement();
    while (pEntry)
    {
      CStdString strInHex = XMLUtils::GetAttribute(pEntry, "inhex");
      CStdString strOutChar = XMLUtils::GetAttribute(pEntry, "outchar");
      if (!strInHex.empty() && !strOutChar.empty())
      {
        CStdString hexValue = strInHex;
        CStdStringW toStr;
        g_charsetConverter.utf8ToW(strOutChar, toStr);

        int from;
        if (sscanf(hexValue.c_str(), "%x", (unsigned int *)&from))
        {
          if (from != 0) // eats nearly any typing error as 0: catch it:
          {
            if (from < 256)
            {
              if (toStr.size()==1)
              {
                    charToCharMap.insert(pair<BYTE, WCHAR>(from, toStr[0]));
                    CLog::Log(LOGDEBUG, "insert map entry from %d to %c ", from, toStr[0]);
              }
              else
              {
                CLog::Log(LOGERROR, "String to %ls does not have the expected length of >=1", toStr.c_str());
              }
            }
            else
            {
              CLog::Log(LOGERROR, "From value %d was greater than 255! ", from);
            }
          }
          else
          {
            CLog::Log(LOGERROR, "Scanned from-value %d as 0 probably a (typing?) error! ", from);
          }
        }
        else
        {
            CLog::Log(LOGERROR, "Could not scan from-value %s (was no valid hex value) ", hexValue.c_str());
        }
      }
      else
      {
        CLog::Log(LOGERROR, "map entry misses attribute <inhex> or <outchar> or content of them");
      }
      pEntry = pEntry->NextSiblingElement();
    }
  }
  else
  {
    CLog::Log(LOGERROR, "XML-Configuration doesn't contain expected map root element %s", mapRootElement);
  }
}
Пример #18
0
	CStdStringW CFilename::MakePath()
	{
		CStdStringW res;
		_wmakepath(res.GetBuffer(MAX_PATH),
			drive.c_str(), dir.c_str(), fname.c_str(), ext.c_str());
		res.ReleaseBuffer();
		return res;
	}
Пример #19
0
bool CWINFileSMB::Delete(const CURI& url)
{
  CStdString strFile=GetLocal(url);

  CStdStringW strWFile;
  g_charsetConverter.utf8ToW(strFile, strWFile, false);
  return ::DeleteFileW(strWFile.c_str()) ? true : false;
}
Пример #20
0
int CWINFileSMB::Stat(const CURI& url, struct __stat64* buffer)
{
  CStdString strFile = GetLocal(url);

  CStdStringW strWFile;
  g_charsetConverter.utf8ToW(strFile, strWFile, false);
  return _wstat64(strWFile.c_str(), buffer);
}
Пример #21
0
void DocReader::StripFieldContents(CStdStringW& sText)
{
	int iPos = -1;
	while ((iPos = sText.Find(19)) != -1)
	{
		int iEndPos = sText.Find(21, iPos);
		sText.erase(iPos, iEndPos - iPos);
	}
}
Пример #22
0
bool CWINFileSMB::SetHidden(const CURL &url, bool hidden)
{
    CStdStringW path;
    g_charsetConverter.utf8ToW(GetLocal(url), path, false);
    DWORD attributes = hidden ? FILE_ATTRIBUTE_HIDDEN : FILE_ATTRIBUTE_NORMAL;
    if (SetFileAttributesW(path.c_str(), attributes))
        return true;
    return false;
}
CStdStringW CompressedRedlineBuilder::BuildOmissionString()
{
	CStdStringW sText;
	CStdStringW sNumber;
 	sNumber.Format(L"%d", m_iOmittedChars); /* TXTEX_IGNORE */

	sText = CStdString::FormatMessage(CStdString::LoadResource(IDS_TXTEX_omittedCharactersWithNoChanges5002,"[omitted %1 characters with no changes]"), sNumber);
	return sText;
}
Пример #24
0
void DominoDocArtifact::Download()
{
   DominoDoc::IDocumentPtr spDocument = GetDocument();   
   CStdStringW workingFileName = CTempFileManager::GetTempFileName();
   spDocument->GetContents(workingFileName.c_str());
   m_workingFileName = workingFileName.c_str();

   Log(_T("The working file [%S] was downloaded from the Domino.Doc library [%S] as document [%S]"), m_workingFileName.c_str(), m_libraryUrl.c_str(), m_documentId.c_str());
}
Пример #25
0
CStdStringW CGUIEditControl::GetDisplayedText() const
{
  if (m_inputType == INPUT_TYPE_PASSWORD || m_inputType == INPUT_TYPE_PASSWORD_MD5 || m_inputType == INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW)
  {
    CStdStringW text;
    text.append(m_text2.size(), L'*');
    return text;
  }
  return m_text2;
}
Пример #26
0
bool CWINFileSMB::Exists(const CURI& url)
{
  struct __stat64 buffer;
  if(url.GetFileName() == url.GetShareName())
    return false;
  CStdString strFile = GetLocal(url);
  CStdStringW strWFile;
  g_charsetConverter.utf8ToW(strFile, strWFile, false);
  return (_wstat64(strWFile.c_str(), &buffer)==0);
}
Пример #27
0
void TestDocReader::TestTableChanges()
{
	DocReader dr;
	dr.OpenFile(TEST_TABLE_TC_DOC);

	CStdStringW sGot = dr.GetMainDocumentText();
	CStdStringW sExp = L"Some stuff before the table\r\rA\07e\07d\07d\07c\07B\07C";


	assertTest(sGot.Left(sExp.length()) == sExp);
}
Пример #28
0
bool CWINFileSMB::Rename(const CURI& url, const CURI& urlnew)
{
  CStdString strFile=GetLocal(url);
  CStdString strNewFile=GetLocal(urlnew);

  CStdStringW strWFile;
  CStdStringW strWNewFile;
  g_charsetConverter.utf8ToW(strFile, strWFile, false);
  g_charsetConverter.utf8ToW(strNewFile, strWNewFile, false);
  return ::MoveFileW(strWFile.c_str(), strWNewFile.c_str()) ? true : false;
}
Пример #29
0
bool CHDFile::Delete(const CURL& url)
{
    CStdString strFile=GetLocal(url);

#ifdef _WIN32
    CStdStringW strWFile;
    g_charsetConverter.utf8ToW(strFile, strWFile, false);
    return ::DeleteFileW(strWFile.c_str()) ? true : false;
#else
    return ::DeleteFile(strFile.c_str()) ? true : false;
#endif
}
Пример #30
0
void CGUILabelControl::SetCursorPos(int iPos)
{
  CStdString labelUTF8 = m_infoLabel.GetLabel(m_parentID);
  CStdStringW label;
  g_charsetConverter.utf8ToW(labelUTF8, label);
  if (iPos > (int)label.length()) iPos = label.length();
  if (iPos < 0) iPos = 0;

  if (m_iCursorPos != iPos)
    MarkDirtyRegion();

  m_iCursorPos = iPos;
}