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

Code before:
        return false;
      }

      return (searchErr == ERROR_FILE_NOT_FOUND) ? RealExists(url, false) : false;
    }
  }

  std::string pathWithSlash(authUrl.Get());
  assert(!pathWithSlash.empty());
  if (pathWithSlash.back() != '/')
    pathWithSlash.push_back('/');

  std::vector<std::shared_ptr<CFileItem>> fileItems;
  do
  {
    std::wstring itemNameW(findData.cFileName);
    if (itemNameW == L"." || itemNameW == L".." || itemNameW.empty())
      continue;

    std::string itemName;
    if (!g_charsetConverter.wToUTF8(itemNameW, itemName, true) || itemName.empty())
    {
      CLog::LogF(LOGERROR, "Can't convert wide string item name to UTF-8");
      continue;
    }

    const bool isDir = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
    const bool isHidden =
        (findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0 ||
        itemName.front() == '.'; // mark files starting from dot as hidden

    std::string itemPath(pathWithSlash + itemName);
    if (isDir)
      itemPath += '/';

    // calculation of size and date costs a little on win32
    // so DIR_FLAG_NO_FILE_INFO flag is ignored
    std::shared_ptr<CFileItem>& item =
        fileItems.emplace_back(std::make_shared<CFileItem>(itemName));
    item->SetFolder(isDir);
    item->SetPath(itemPath);
    if (auto entryTime = GetEntryTime(findData); entryTime)
      item->SetDateTime(std::move(*entryTime));
    else
    {
      CDateTime dt{item->GetDateTime()};
      dt.SetValid(false);
      item->SetDateTime(std::move(dt));
    }
    if (!isDir)
      item->SetSize(GetEntrySize(findData));

Review comment (refactor):
For me this needs to go, it accomplishes nothing and complicates this PR.
The code before the last refactor was:
    if (KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime) == TRUE)
      pItem->m_dateTime = localTime;
    else
      pItem->m_dateTime.SetValid(false);
which already did nothing, since pItem is new and its m_dateTime is default, which is in invalid status. And I think that can be relied on.

Code after:
    }

    CFileItemPtr pItem(new CFileItem(itemName));

    pItem->SetFolder((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
    if (pItem->IsFolder())
      pItem->SetPath(pathWithSlash + itemName + '/');
    else
      pItem->SetPath(pathWithSlash + itemName);

    if ((findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0
          || itemName.front() == '.') // mark files starting from dot as hidden
      pItem->SetProperty("file:hidden", true);

    // calculation of size and date costs a little on win32
    // so DIR_FLAG_NO_FILE_INFO flag is ignored
    FileTime localTime{};
    if (FileTimeToLocalFileTime(reinterpret_cast<FileTime*>(&findData.ftLastWriteTime),
                                &localTime) == TRUE)
      pItem->SetDateTime(localTime);
    else
    {
      CDateTime dt{pItem->GetDateTime()};
      dt.SetValid(false);
      pItem->SetDateTime(dt);
    }
    if (!pItem->IsFolder())
      pItem->SetSize((__int64(findData.nFileSizeHigh) << 32) + findData.nFileSizeLow);

    items.Add(pItem);
  } while (FindNextFileW(hSearch, &findData));

  FindClose(hSearch);

  return true;
}

bool CWin32SMBDirectory::Create(const CURL& url)
{
  return RealCreate(url, true);
}

bool CWin32SMBDirectory::RealCreate(const CURL& url, bool tryToConnect)
{
  assert(url.IsProtocol("smb"));
  if (url.GetHostName().empty() || url.GetShareName().empty() || url.GetFileName() == url.GetShareName())
    return false; // can't create new hosts or shares

  std::wstring nameW(prepareWin32SMBDirectoryName(url));
  if (nameW.empty())
    return false;