Example #1
0
//*********************************************************************************************
bool CWINFileSMB::OpenForWrite(const CURL& url, bool bOverWrite)
{
  std::wstring strWPath(CWIN32Util::ConvertPathToWin32Form(GetLocal(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())
  {
    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, "%s: Unable to open file for writing '%s' Error '%d%", __FUNCTION__, url.Get().c_str(), GetLastError());
      return false;
    }
  }

  m_i64FilePos = 0;
  Seek(0, SEEK_SET);

  return true;
}
Example #2
0
//*********************************************************************************************
bool CWINFileSMB::Open(const CURL& url)
{
  std::wstring wfilename(CWIN32Util::ConvertPathToWin32Form(GetLocal(url)));

  m_hFile.attach(CreateFileW(wfilename.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(wfilename.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL));
    if (!m_hFile.isValid())
    {
      CLog::Log(LOGERROR, "%s: Unable to open file %s Error: %d", __FUNCTION__, url.Get().c_str(), GetLastError());
      return false;
    }
  }

  m_i64FilePos = 0;
  Seek(0, SEEK_SET);

  return true;
}
Example #3
0
int CWINFileSMB::Stat(const CURL& url, struct __stat64* buffer)
{
  std::wstring strWFile(CWIN32Util::ConvertPathToWin32Form(GetLocal(url)));

  /* _wstat64 can't handle long paths therefore we remove the \\?\UNC\ */
  if (strWFile.compare(0, 8, L"\\\\?\\UNC\\", 8) == 0)
    strWFile.erase(2, 6);

  /* _wstat64 calls FindFirstFileEx. According to MSDN, the path should not end in a trailing backslash.
    Remove it before calling _wstat64 */
  if (strWFile[strWFile.length()-1] == L'\\')
    strWFile.pop_back();

  if(_wstat64(strWFile.c_str(), buffer) == 0)
    return 0;

  if(errno == ENOENT)
    return -1;

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

  return _wstat64(strWFile.c_str(), buffer);
}
Example #4
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;
}
Example #5
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;
}
Example #6
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;
}
Example #7
0
int CWINFileSMB::Stat(const CURL& url, struct __stat64* buffer)
{
    CStdString strFile = GetLocal(url);
    /* _wstat64 calls FindFirstFileEx. According to MSDN, the path should not end in a trailing backslash.
      Remove it before calling _wstat64 */
    if (strFile.length() > 3 && URIUtils::HasSlashAtEnd(strFile))
        URIUtils::RemoveSlashAtEnd(strFile);
    CStdStringW strWFile;
    g_charsetConverter.utf8ToW(strFile, strWFile, false);
    if(_wstat64(strWFile.c_str(), buffer) == 0)
        return 0;

    if(errno == ENOENT)
        return -1;

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

    return _wstat64(strWFile.c_str(), buffer);
}
Example #8
0
bool CWINFileSMB::Exists(const CURL& url)
{
  std::wstring strWFile(CWIN32Util::ConvertPathToWin32Form(GetLocal(url)));

  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;
}