Repository: xbmc/xbmc
File: xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp (C++)

Code before:
#include <cassert>

using namespace XFILE;

using KODI::PLATFORM::WINDOWS::FromW;

namespace
{

uint64_t GetEntrySize(const WIN32_FIND_DATAW& findData)
{
  return (__int64(findData.nFileSizeHigh) << 32) + findData.nFileSizeLow;
}

KODI::TIME::FileTime GetEntryTime(CFileItemPtr& item, const WIN32_FIND_DATAW& findData)
{
  KODI::TIME::FileTime fileTime{};
  fileTime.lowDateTime = findData.ftLastWriteTime.dwLowDateTime;
  fileTime.highDateTime = findData.ftLastWriteTime.dwHighDateTime;

  KODI::TIME::FileTime localTime{};
  KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime);

  if (KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime) == TRUE)
    return localTime;
  else
  {
    CDateTime dt{item->GetDateTime()};
    dt.SetValid(false);
    return dt;
  }
}

} // Unnamed namespace

// local helper
static inline bool worthTryToConnect(const DWORD lastErr)
{
  return lastErr != ERROR_FILE_NOT_FOUND      && lastErr != ERROR_BAD_NET_NAME  &&
         lastErr != ERROR_NO_NET_OR_BAD_PATH  && lastErr != ERROR_NO_NETWORK    &&
         lastErr != ERROR_BAD_NETPATH;
}

/**
* Get servers recursively or get shares from specific server
* @param basePathToScanPtr the pointer to start point for scan
* @param urlPrefixForItems path prefix to be putted into list items
* @param items             the list of the collected items
* @param getShares         set to true to get shares, set for false to get servers
* @return true if succeed, false otherwise
*/

Review comment (suggestion):
This `else` is redundant because the if condition return (if if is true). Remove `else`.

Code after:
#include <cassert>

using namespace XFILE;

using KODI::PLATFORM::WINDOWS::FromW;
using KODI::TIME::FileTime;

// local helper
static inline bool worthTryToConnect(const DWORD lastErr)
{
  return lastErr != ERROR_FILE_NOT_FOUND      && lastErr != ERROR_BAD_NET_NAME  &&
         lastErr != ERROR_NO_NET_OR_BAD_PATH  && lastErr != ERROR_NO_NETWORK    &&
         lastErr != ERROR_BAD_NETPATH;
}

/**
* Get servers recursively or get shares from specific server
* @param basePathToScanPtr the pointer to start point for scan
* @param urlPrefixForItems path prefix to be putted into list items
* @param items             the list of the collected items
* @param getShares         set to true to get shares, set for false to get servers
* @return true if succeed, false otherwise
*/
static bool localGetNetworkResources(struct _NETRESOURCEW* basePathToScanPtr, const std::string& urlPrefixForItems, CFileItemList& items, bool getShares);
static bool localGetShares(const std::wstring& serverNameToScan, const std::string& urlPrefixForItems, CFileItemList& items);
static bool localGetServers(const std::string& urlPrefixForItems, CFileItemList& items);

// check for empty string, remove trailing slash if any, convert to win32 form
inline static std::wstring prepareWin32SMBDirectoryName(const CURL& url)
{
  assert(url.IsProtocol("smb"));

  if (url.GetHostName().empty() || url.GetShareName().empty())
    return std::wstring(); // can't use win32 standard file API, return empty string

  std::wstring nameW(CWIN32Util::ConvertPathToWin32Form("\\\\?\\UNC\\" + url.GetHostName() + '\\' + url.GetFileName()));
  if (!nameW.empty() && nameW.back() == L'\\')
    nameW.pop_back(); // remove slash at the end if any

  return nameW;
}

CWin32SMBDirectory::CWin32SMBDirectory(void)
{}

CWin32SMBDirectory::~CWin32SMBDirectory(void)
{}

bool CWin32SMBDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
  assert(url.IsProtocol("smb"));