示例#1
0
bool CWINSMBDirectory::GetDirectory(const CStdString& strPath1, CFileItemList &items)
{
  WIN32_FIND_DATAW wfd;

  CStdString strPath=strPath1;

  CURL url(strPath);

  if(url.GetShareName().empty())
  {
    LPNETRESOURCEW lpnr = NULL;
    bool ret;
    if(!url.GetHostName().empty())
    {
      lpnr = (LPNETRESOURCEW) GlobalAlloc(GPTR, 16384);
      if(lpnr == NULL)
        return false;

      ConnectToShare(url);
      CStdString strHost = "\\\\" + url.GetHostName();
      CStdStringW strHostW;
      g_charsetConverter.utf8ToW(strHost,strHostW);
      lpnr->lpRemoteName = (LPWSTR)strHostW.c_str();
      m_bHost = true;
      ret = EnumerateFunc(lpnr, items);
      GlobalFree((HGLOBAL) lpnr);
      m_bHost = false;
    }
    else
      ret = EnumerateFunc(lpnr, items);

    return ret;
  }

  memset(&wfd, 0, sizeof(wfd));
  //rebuild the URL
  CStdString strUNCShare = "\\\\" + url.GetHostName() + "\\" + url.GetFileName();
  strUNCShare.Replace("/", "\\");
  if(!URIUtils::HasSlashAtEnd(strUNCShare))
    strUNCShare.append("\\");

  CStdStringW strSearchMask;
  g_charsetConverter.utf8ToW(strUNCShare, strSearchMask, false);
  strSearchMask += "*";

  FILETIME localTime;
  CAutoPtrFind hFind ( FindFirstFileW(strSearchMask.c_str(), &wfd));

  // on error, check if path exists at all, this will return true if empty folder
  if (!hFind.isValid())
  {
    DWORD ret = GetLastError();
    if(ret == ERROR_INVALID_PASSWORD || ret == ERROR_LOGON_FAILURE || ret == ERROR_ACCESS_DENIED || ret == ERROR_INVALID_HANDLE)
    {
      if(ConnectToShare(url) == false)
        return false;
      hFind.attach(FindFirstFileW(strSearchMask.c_str(), &wfd));
    }
    else
      return Exists(strPath1);
  }

  if (hFind.isValid())
  {
    do
    {
      if (wfd.cFileName[0] != 0)
      {
        CStdString strLabel;
        g_charsetConverter.wToUTF8(wfd.cFileName,strLabel);
        if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
        {
          if (strLabel != "." && strLabel != "..")
          {
            CFileItemPtr pItem(new CFileItem(strLabel));
            CStdString path = URIUtils::AddFileToFolder(strPath, strLabel);
            URIUtils::AddSlashAtEnd(path);
            pItem->SetPath(path);
            pItem->m_bIsFolder = true;
            FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
            pItem->m_dateTime=localTime;

            if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
              pItem->SetProperty("file:hidden", true);

            items.Add(pItem);
          }
        }
        else
        {
          CFileItemPtr pItem(new CFileItem(strLabel));
          pItem->SetPath(URIUtils::AddFileToFolder(strPath, strLabel));
          pItem->m_bIsFolder = false;
          pItem->m_dwSize = CUtil::ToInt64(wfd.nFileSizeHigh, wfd.nFileSizeLow);
          FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
          pItem->m_dateTime=localTime;

          if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
            pItem->SetProperty("file:hidden", true);
          items.Add(pItem);
        }
      }
    }
    while (FindNextFileW((HANDLE)hFind, &wfd));
  }
  return true;
}
示例#2
0
bool CHDDirectory::GetDirectory(const CStdString& strPath1, CFileItemList &items)
{
  LOCAL_WIN32_FIND_DATA wfd;
  memset(&wfd, 0, sizeof(wfd));

  CStdString strPath=strPath1;

  if (IsAliasShortcut(strPath))
    TranslateAliasShortcut(strPath);

  CStdString strRoot = strPath;
  CURL url(strPath);

  URIUtils::AddSlashAtEnd(strRoot);
  if (URIUtils::IsDVD(strRoot) && m_isoReader.IsScanned())
  {
    // Reset iso reader and remount or
    // we can't access the dvd-rom
    m_isoReader.Reset();
  }

#ifdef TARGET_WINDOWS
  std::wstring strSearchMask(CWIN32Util::ConvertPathToWin32Form(strRoot));
  strSearchMask += L"*.*";
#else
  CStdString strSearchMask(strRoot);
#endif

  FILETIME localTime;
  CAutoPtrFind hFind ( LocalFindFirstFile(strSearchMask.c_str(), &wfd));

  // on error, check if path exists at all, this will return true if empty folder
  if (!hFind.isValid())
      return Exists(strPath1);

  if (hFind.isValid())
  {
    do
    {
      if (wfd.cFileName[0] != 0)
      {
        CStdString strLabel;
#ifdef TARGET_WINDOWS
        g_charsetConverter.wToUTF8(wfd.cFileName,strLabel, true);
#else
        strLabel = wfd.cFileName;
#endif
        if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
        {
          if (strLabel != "." && strLabel != "..")
          {
            CFileItemPtr pItem(new CFileItem(strLabel));
            CStdString itemPath(URIUtils::AddFileToFolder(strRoot, strLabel));
            URIUtils::AddSlashAtEnd(itemPath);
            pItem->SetPath(itemPath);
            pItem->m_bIsFolder = true;
            FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
            pItem->m_dateTime=localTime;

            if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
              pItem->SetProperty("file:hidden", true);
            items.Add(pItem);
          }
        }
        else
        {
          CFileItemPtr pItem(new CFileItem(strLabel));
          pItem->SetPath(URIUtils::AddFileToFolder(strRoot, strLabel));
          pItem->m_bIsFolder = false;
          pItem->m_dwSize = CUtil::ToInt64(wfd.nFileSizeHigh, wfd.nFileSizeLow);
          FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
          pItem->m_dateTime=localTime;

          if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
            pItem->SetProperty("file:hidden", true);

          items.Add(pItem);
        }
      }
    }
    while (LocalFindNextFile((HANDLE)hFind, &wfd));
  }
  return true;
}
示例#3
0
bool CHDDirectory::GetDirectory(const CStdString& strPath1, CFileItemList &items)
{
    WIN32_FIND_DATA wfd;

    CStdString strPath=strPath1;
#ifndef _LINUX
    g_charsetConverter.utf8ToStringCharset(strPath);
#endif

    CFileItemList vecCacheItems;
    g_directoryCache.ClearDirectory(strPath1);


    CStdString strRoot = strPath;
    CURL url(strPath);

    memset(&wfd, 0, sizeof(wfd));
    if (!CUtil::HasSlashAtEnd(strPath) )
#ifndef _LINUX
        strRoot += "\\";
    strRoot.Replace("/", "\\");
#else
        strRoot += "/";
#endif
    if (CUtil::IsDVD(strRoot) && m_isoReader.IsScanned())
    {
        // Reset iso reader and remount or
        // we can't access the dvd-rom
        m_isoReader.Reset();

        CIoSupport::Dismount("Cdrom0");
        CIoSupport::RemapDriveLetter('D', "Cdrom0");
    }

    CStdString strSearchMask = strRoot;
#ifndef _LINUX
    strSearchMask += "*.*";
#else
    strSearchMask += "*";
#endif

    FILETIME localTime;
    CAutoPtrFind hFind ( FindFirstFile(strSearchMask.c_str(), &wfd));

    // on error, check if path exists at all, this will return true if empty folder
    if (!hFind.isValid())
        return Exists(strPath1);

    if (hFind.isValid())
    {
        do
        {
            if (wfd.cFileName[0] != 0)
            {
#ifdef __APPLE__
                // Attempt to resolve aliases.
                FSRef   fsRef;
                Boolean isDir;
                Boolean isAlias;
                char    resolvedAliasPath[MAX_PATH];
                bool    useAlias = false;

                // Convert to FSRef.
                CStdString strFile = strRoot + wfd.cFileName;
                if (FSPathMakeRef((const UInt8* )strFile.c_str(), &fsRef, &isDir) == noErr)
                {
                    if (FSResolveAliasFileWithMountFlags(&fsRef, TRUE, &isDir, &isAlias, kResolveAliasFileNoUI) == noErr)
                    {
                        // If it was an alias, use the reference instead.
                        if (isAlias)
                        {
                            if (FSRefMakePath(&fsRef, (UInt8* )resolvedAliasPath, MAX_PATH) == noErr)
                                useAlias = true;
                        }
                    }
                }

                if (useAlias)
                {
                    // Add the alias.
                    CFileItem *pItem = new CFileItem(wfd.cFileName);
                    pItem->m_strPath = resolvedAliasPath;
                    pItem->m_bIsFolder = isDir ? true : false;

                    if (isDir == false)
                    {
                        // Get the size of the file.
                        struct stat64 statInfo;
                        stat64(resolvedAliasPath, &statInfo);
                        pItem->m_dwSize = statInfo.st_size;
                    }

                    FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
                    pItem->m_dateTime=localTime;

                    vecCacheItems.Add(pItem);
                    items.Add(new CFileItem(*pItem));
                }
                else
#endif
                    if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
                    {
                        CStdString strDir = wfd.cFileName;
                        if (strDir != "." && strDir != "..")
                        {
                            CStdString strLabel=wfd.cFileName;
#ifndef _LINUX
                            g_charsetConverter.stringCharsetToUtf8(strLabel);
#endif

                            CFileItem *pItem = new CFileItem(strLabel);
                            pItem->m_strPath = strRoot;
                            pItem->m_strPath += wfd.cFileName;

#ifndef _LINUX
                            g_charsetConverter.stringCharsetToUtf8(pItem->m_strPath);
#endif
                            pItem->m_bIsFolder = true;
                            CUtil::AddSlashAtEnd(pItem->m_strPath);
                            FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
                            pItem->m_dateTime=localTime;

                            vecCacheItems.Add(pItem);
#ifdef _LINUX
                            /* Checks if the file is hidden. If it is then we don't really need to add it */
                            if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || g_guiSettings.GetBool("filelists.showhidden"))
                                items.Add(new CFileItem(*pItem));
#else
                            items.Add(new CFileItem(*pItem));
#endif
                        }
                    }
                    else
                    {
                        CStdString strLabel=wfd.cFileName;
#ifndef _LINUX
                        g_charsetConverter.stringCharsetToUtf8(strLabel);
#endif
                        CFileItem *pItem = new CFileItem(strLabel);
                        pItem->m_strPath = strRoot;
                        pItem->m_strPath += wfd.cFileName;
#ifndef _LINUX
                        g_charsetConverter.stringCharsetToUtf8(pItem->m_strPath);
#endif
                        pItem->m_bIsFolder = false;
                        pItem->m_dwSize = CUtil::ToInt64(wfd.nFileSizeHigh, wfd.nFileSizeLow);
                        FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
                        pItem->m_dateTime=localTime;
#ifdef _LINUX
                        /* Checks if the file is hidden. If it is then we don't really need to add it */
                        if ((!(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || g_guiSettings.GetBool("filelists.showhidden")) && IsAllowed(wfd.cFileName))
#else
                        if ( IsAllowed( wfd.cFileName) )
#endif
                        {
                            vecCacheItems.Add(pItem);
                            items.Add(new CFileItem(*pItem));
                        }
                        else
                            vecCacheItems.Add(pItem);
                    }
            }
        }
        while (FindNextFile((HANDLE)hFind, &wfd));
#ifdef _XBOX
        // if we use AutoPtrHandle, this auto-closes
        FindClose((HANDLE)hFind); //should be closed
#endif
    }
    if (m_cacheDirectory)
        g_directoryCache.SetDirectory(strPath1, vecCacheItems);
    return true;
}
示例#4
0
bool CHDDirectory::GetDirectory(const CStdString& strPath1, CFileItemList &items)
{
  LOCAL_WIN32_FIND_DATA wfd;

  CStdString strPath=strPath1;

  if (IsAliasShortcut(strPath))
    TranslateAliasShortcut(strPath);

  CStdString strRoot = strPath;
  CURL url(strPath);

  memset(&wfd, 0, sizeof(wfd));
  if (!CUtil::HasSlashAtEnd(strPath) )
#ifndef _LINUX
    strRoot += "\\";
  strRoot.Replace("/", "\\");
#else
    strRoot += "/";
#endif
  if (CUtil::IsDVD(strRoot) && m_isoReader.IsScanned())
  {
    // Reset iso reader and remount or
    // we can't access the dvd-rom
    m_isoReader.Reset();

    CIoSupport::Dismount("Cdrom0");
    CIoSupport::RemapDriveLetter('D', "Cdrom0");
  }

#ifndef _LINUX
  CStdStringW strSearchMask;
  g_charsetConverter.utf8ToW(strRoot, strSearchMask, false);
  strSearchMask += "*.*";
#else
  CStdString strSearchMask = strRoot;
#endif

  FILETIME localTime;
  CAutoPtrFind hFind ( LocalFindFirstFile(strSearchMask.c_str(), &wfd));

  // on error, check if path exists at all, this will return true if empty folder
  if (!hFind.isValid())
      return Exists(strPath1);

  if (hFind.isValid())
  {
    do
    {
      if (wfd.cFileName[0] != 0)
      {
        CStdString strLabel;
#ifndef _LINUX
        g_charsetConverter.wToUTF8(wfd.cFileName,strLabel);
#else
        strLabel = wfd.cFileName;
#endif
        if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
        {
          if (strLabel != "." && strLabel != "..")
          {
            CFileItemPtr pItem(new CFileItem(strLabel));
            pItem->m_strPath = strRoot;
            pItem->m_strPath += strLabel;
            pItem->m_bIsFolder = true;
            CUtil::AddSlashAtEnd(pItem->m_strPath);
            FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
            pItem->m_dateTime=localTime;

            if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
              pItem->SetProperty("file:hidden", true);
            items.Add(pItem);
          }
        }
        else
        {
          CFileItemPtr pItem(new CFileItem(strLabel));
          pItem->m_strPath = strRoot;
          pItem->m_strPath += strLabel;
          pItem->m_bIsFolder = false;
          pItem->m_dwSize = CUtil::ToInt64(wfd.nFileSizeHigh, wfd.nFileSizeLow);
          FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
          pItem->m_dateTime=localTime;

          if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
            pItem->SetProperty("file:hidden", true);

          items.Add(pItem);
        }
      }
    }
    while (LocalFindNextFile((HANDLE)hFind, &wfd));
  }
  return true;
}