예제 #1
0
void CCharsetConverter::utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest)
{
  if (m_iconvUtf8ToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUtf8ToStringCharset = iconv_open(strCharset.c_str(), UTF8_SOURCE);
  }

  if (m_iconvUtf8ToStringCharset != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;

    char *dst = strDest.GetBuffer(inBytes);
    size_t outBytes = inBytes - 1;

    if (iconv_const(m_iconvUtf8ToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #2
0
void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest)
{
  iconv_t iconvString=iconv_open("UTF-8", strSourceCharset.c_str());

  if (iconvString != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;

    size_t outBytes = (inBytes * 4) + 1;
    char *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(iconvString, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
      return ;
    }

    strDest.ReleaseBuffer();

    iconv_close(iconvString);
  }
}
예제 #3
0
void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest)
{
  iconv_t iconvString=iconv_open("UTF-8", strSourceCharset.c_str());

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

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

    if (iconv(iconvString, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();

    iconv_close(iconvString);
  }
}
예제 #4
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();
  }
}
예제 #5
0
void CCharsetConverter::utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest)
{
  if (m_iconvUtf8ToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUtf8ToStringCharset = iconv_open(strCharset.c_str(), UTF8_SOURCE);
  }

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

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

    if (iconv_const(m_iconvUtf8ToStringCharset, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();
  }
}
예제 #6
0
bool NetworkDriveHelper::ShareTestFolder()
{
	NET_API_STATUS	res;
	DWORD			parm_err = 0;
	wchar_t			netName[MAX_PATH];
	wchar_t			path[MAX_PATH];
	wchar_t			remarks[MAX_PATH];

	CStdStringA		sTestPath = ResolveSubstDriveInPath(GET_TEST_TEMP_PATH(_T("")));
	if (sTestPath.Right(1) == "\\")
		sTestPath	= sTestPath.Left( sTestPath.length() -1 );	// Remove last backslash.

	mbstowcs( netName, TESTSHARE, MAX_PATH );
	mbstowcs( path,    sTestPath, MAX_PATH );
	mbstowcs( remarks, "Workshare Local File Store testing share", MAX_PATH );

	SHARE_INFO_2	p;
	memset(&p, 0, sizeof(SHARE_INFO_2));
	p.shi2_netname		= netName;    
	p.shi2_type			= STYPE_DISKTREE;
	p.shi2_remark		= NULL;
	p.shi2_permissions	= 0;    
	p.shi2_max_uses		= -1;
	p.shi2_current_uses = 0;    
	p.shi2_path			= path;
	p.shi2_passwd		= NULL;

	res = NetShareAdd(NULL, 2, (LPBYTE) &p, &parm_err);

	if (res == NERR_DuplicateShare)	// Already shared.
		return true;

	ASSERT(res != NERR_UnknownDevDir);
	return res == 0;
}
예제 #7
0
// The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
// of the string is already made or the string is not displayed in the GUI
void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/)
{
  CStdStringA strFlipped;
  const char* src;
  size_t inBytes;
  
  // Try to flip hebrew/arabic characters, if any
  if (bVisualBiDiFlip)
  {
    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_CHAR_SET_UTF8);
    src = strFlipped.c_str();
    inBytes = strFlipped.length() + 1;
  }
  else
  {
    src = utf8String.c_str();
    inBytes = utf8String.length() + 1;
  }

  if (m_iconvUtf8toW == (iconv_t) - 1)
    m_iconvUtf8toW = iconv_open(WCHAR_CHARSET, UTF8_SOURCE);

  if (m_iconvUtf8toW != (iconv_t) - 1)
  {
    size_t outBytes = inBytes * sizeof(wchar_t);
    char      * dst = (char*)wString.GetBuffer(outBytes);

    if (iconv_const(m_iconvUtf8toW, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      wString.ReleaseBuffer();
      wString = utf8String;
      return;
    }

    if (iconv(m_iconvUtf8toW, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      wString.ReleaseBuffer();
      wString = utf8String;
      return;
    }
    wString.ReleaseBuffer();
  }
}
예제 #8
0
// The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
// of the string is already made or the string is not displayed in the GUI
void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/)
{
  CStdStringA strFlipped;
  const char* src;
  size_t inBytes;
  
  // Try to flip hebrew/arabic characters, if any
  if (bVisualBiDiFlip)
  {
    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_CHAR_SET_UTF8);
    src = strFlipped.c_str();
    inBytes = strFlipped.length() + 1;
  }
  else
  {
    src = utf8String.c_str();
    inBytes = utf8String.length() + 1;
  }

  if (m_iconvUtf8toW == (iconv_t) - 1)
    m_iconvUtf8toW = iconv_open(WCHAR_CHARSET, UTF8_SOURCE);

  if (m_iconvUtf8toW != (iconv_t) - 1)
  {
    char *dst = new char[inBytes * sizeof(wchar_t)];
    size_t outBytes = inBytes * sizeof(wchar_t);
    char *outdst = dst;
    if (iconv_const(m_iconvUtf8toW, &src, &inBytes, &outdst, &outBytes))
    {
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      wString = utf8String;
    }
    else
    {
      wString = (WCHAR *)dst;
    }
    delete[] dst;
  }
}
예제 #9
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)
  {
    size_t inBytes  = (strSource.length() + 1);
    size_t outBytes = (strSource.length() + 1) * sizeof(wchar_t);
    const char *src = strSource.c_str();
    char       *dst = (char*)strDest.GetBuffer(outBytes);

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

    if (iconv_const(m_iconvSubtitleCharsetToW, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #10
0
long PASCAL CchFetchLpszError(long fce, char FAR *lpszError, long cb)
{
	CStdStringA sErrorMessage;

	switch( fce )
	{
	default:
		{
			int nSolidError = -( fce - fceWorkshareLastDefined );
			switch( nSolidError )
			{
			default:
				return 0;
			case Solid::Canceled:
				sErrorMessage = "Pdf conversion cancelled\0";
				break;
			case Solid::BadData:
				sErrorMessage = "The Pdf document may be corrupt\0";
				break;
			case Solid::IOError:
				sErrorMessage = "Pdf conversion IO error\0";
				break;
			case Solid::IOFileLocked:
				sErrorMessage = "Pdf conversion IO file locked\0";
				break;
			case Solid::ProtectedFile:
				sErrorMessage = "Workshare is unable to open Pdf files with copy protection\0";
				break;
			case Solid::InternalError:
				sErrorMessage = "Pdf conversion internal error\0";
				break;
			case Solid::InvalidPagesRange:
				sErrorMessage = "Pdf conversion invalid page range\0";
				break;
			case Solid::NoBppConversion:
				sErrorMessage = "Pdf bits per pixel conversion failed\0";
				break;
			case Solid::NoGrayScale:
				sErrorMessage = "Pdf gray scale conversion failed\0";
				break;
			case Solid::PSDUnsupportedMode:
				sErrorMessage = "Pdf is password protected, unable to convert\0";
				break;
			case Solid::TablesNotFound:
				sErrorMessage = "Pdf conversion found no tables to extract\0";
				break;
			case Solid::ImagesNotFound:
				sErrorMessage = "Pdf conversion found no images to extract\0";
				break;
			case Solid::UnsupportedEncryptionHandler:
				sErrorMessage = "Pdf has unsupported encryption\0";
				break;
			case Solid::MissingCertificate:
				sErrorMessage = "Pdf has missing certifucate\0";
				break;
			case Solid::Unknown:
				sErrorMessage = "An unknown error has occured\0";
				break;
			}
			break;
		}
	case fceOpenInFileErr:
		sErrorMessage = "Could not open input file\0";
		break;
	case fceReadErr:
		sErrorMessage = "Error during read\0";
		break;
	case fceWriteErr:
		sErrorMessage = "Error during write\0";
		break;
	case fceInvalidFile:
		sErrorMessage = "Invalid data in conversion file\0";
		break;
	case fceNoMemory:
		sErrorMessage = "Out of memory\0";
		break;
	case fceOpenOutFileErr:
		sErrorMessage = "Could not open output file\0";
		break;
	case fceUserCancel:
		sErrorMessage = "Conversion cancelled by user\0";
		break;
	case fceWrongFileType:
		sErrorMessage = "Wrong file type for this converter\0";
		break;
	case fceWorkshareNotLicensed:
		sErrorMessage = "Workshare needs to be licensed for Protect to enable this functionality\0";
		break;
	case fceWorkshareExportNotImplimented:
		sErrorMessage = "Workshare does not provide save functionality for Pdf files\0";
		break;
	case fceWorkshareNoConcurrentConversions:
		sErrorMessage = "Conversions cannot run concurrently\0";
		break;
	}

	if( cb > (long)sErrorMessage.length() )
	{
		strcpy_s( lpszError, cb, sErrorMessage.c_str() );
		return (long)sErrorMessage.length();
	}

	return 0;
}