Skip to content

Commit

Permalink
Merge pull request #17335 from lrusak/systemtime-defines-part2
Browse files Browse the repository at this point in the history
PlatformDefs.h: move WIN32_FIND_DATA to iso9660.h
  • Loading branch information
lrusak committed Feb 10, 2020
2 parents b1547ab + 48e6c76 commit 4123ff4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 70 deletions.
24 changes: 8 additions & 16 deletions xbmc/filesystem/ISO9660Directory.cpp
Expand Up @@ -35,7 +35,7 @@ bool CISO9660Directory::GetDirectory(const CURL& url, CFileItemList &items)
if (!m_isoReader.IsScanned())
m_isoReader.Scan();

WIN32_FIND_DATA wfd;
Win32FindData wfd;
HANDLE hFind;

memset(&wfd, 0, sizeof(wfd));
Expand All @@ -61,15 +61,11 @@ bool CISO9660Directory::GetDirectory(const CURL& url, CFileItemList &items)

do
{
if (wfd.cFileName[0] != 0)
if (wfd.fileName[0] != 0)
{
if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
if ((wfd.fileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
#ifdef TARGET_WINDOWS
auto strDir = KODI::PLATFORM::WINDOWS::FromW(wfd.cFileName);
#else
std::string strDir = wfd.cFileName;
#endif
std::string strDir = wfd.fileName;
if (strDir != "." && strDir != "..")
{
CFileItemPtr pItem(new CFileItem(strDir));
Expand All @@ -78,24 +74,20 @@ bool CISO9660Directory::GetDirectory(const CURL& url, CFileItemList &items)
pItem->SetPath(path);
pItem->m_bIsFolder = true;
FILETIME localTime;
KODI::TIME::FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
KODI::TIME::FileTimeToLocalFileTime(&wfd.lastWriteTime, &localTime);
pItem->m_dateTime=localTime;
items.Add(pItem);
}
}
else
{
#ifdef TARGET_WINDOWS
auto strDir = KODI::PLATFORM::WINDOWS::FromW(wfd.cFileName);
#else
std::string strDir = wfd.cFileName;
#endif
std::string strDir = wfd.fileName;
CFileItemPtr pItem(new CFileItem(strDir));
pItem->SetPath(strRoot + strDir);
pItem->m_bIsFolder = false;
pItem->m_dwSize = CUtil::ToInt64(wfd.nFileSizeHigh, wfd.nFileSizeLow);
pItem->m_dwSize = CUtil::ToInt64(wfd.fileSizeHigh, wfd.fileSizeLow);
FILETIME localTime;
KODI::TIME::FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
KODI::TIME::FileTimeToLocalFileTime(&wfd.lastWriteTime, &localTime);
pItem->m_dateTime=localTime;
items.Add(pItem);
}
Expand Down
67 changes: 29 additions & 38 deletions xbmc/filesystem/iso9660.cpp
Expand Up @@ -27,6 +27,7 @@ ISO9660
*/

#include "iso9660.h"

#include "IFile.h"
Expand All @@ -42,8 +43,11 @@ ISO9660
#else
#include "platform/win32/CharsetConverter.h"
#endif
#include <stdlib.h>

#include <algorithm>
#include <cstring>
#include <stdlib.h>

#include <cdio/bytesex.h>
//#define _DEBUG_OUTPUT 1

Expand Down Expand Up @@ -619,10 +623,12 @@ struct iso_dirtree *iso9660::FindFolder(const char *Folder )
}

//******************************************************************************************************************
HANDLE iso9660::FindFirstFile9660(const char *szLocalFolder, WIN32_FIND_DATA *wfdFile)
HANDLE iso9660::FindFirstFile9660(const char* szLocalFolder, Win32FindData* wfdFile)
{
if (m_info.ISO_HANDLE == nullptr) return static_cast<HANDLE>(nullptr);
memset( wfdFile, 0, sizeof(WIN32_FIND_DATA));
if (!m_info.ISO_HANDLE)
return static_cast<HANDLE>(nullptr);

memset(wfdFile, 0, sizeof(Win32FindData));

m_searchpointer = FindFolder( szLocalFolder );

Expand All @@ -632,52 +638,44 @@ HANDLE iso9660::FindFirstFile9660(const char *szLocalFolder, WIN32_FIND_DATA *wf

if ( m_searchpointer )
{
#ifdef TARGET_WINDOWS
wcscpy_s(wfdFile->cFileName, MAX_PATH, KODI::PLATFORM::WINDOWS::ToW(m_searchpointer->name).c_str());
#else
strncpy(wfdFile->cFileName, m_searchpointer->name, sizeof(wfdFile->cFileName) - 1);
wfdFile->cFileName[sizeof(wfdFile->cFileName) - 1] = '\0';
#endif
std::strncpy(wfdFile->fileName, m_searchpointer->name, sizeof(wfdFile->fileName) - 1);
wfdFile->fileName[sizeof(wfdFile->fileName) - 1] = '\0';

if ( m_searchpointer->type == 2 )
wfdFile->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
wfdFile->fileAttributes |= FILE_ATTRIBUTE_DIRECTORY;

wfdFile->ftLastWriteTime = m_searchpointer->filetime;
wfdFile->ftLastAccessTime = m_searchpointer->filetime;
wfdFile->ftCreationTime = m_searchpointer->filetime;
wfdFile->lastWriteTime = m_searchpointer->filetime;
wfdFile->lastAccessTime = m_searchpointer->filetime;
wfdFile->creationTime = m_searchpointer->filetime;

wfdFile->nFileSizeLow = m_searchpointer->Length;
wfdFile->fileSizeLow = m_searchpointer->Length;
return reinterpret_cast<HANDLE>(1);
}
}
return static_cast<HANDLE>(nullptr);
}

//******************************************************************************************************************
int iso9660::FindNextFile( HANDLE szLocalFolder, WIN32_FIND_DATA *wfdFile )
int iso9660::FindNextFile(HANDLE szLocalFolder, Win32FindData* wfdFile)
{
memset( wfdFile, 0, sizeof(WIN32_FIND_DATA));
memset(wfdFile, 0, sizeof(Win32FindData));

if ( m_searchpointer )
m_searchpointer = m_searchpointer->next;

if ( m_searchpointer )
{
#ifdef TARGET_WINDOWS
wcscpy_s(wfdFile->cFileName, MAX_PATH, KODI::PLATFORM::WINDOWS::ToW(m_searchpointer->name).c_str());
#else
strncpy(wfdFile->cFileName, m_searchpointer->name, sizeof(wfdFile->cFileName) - 1);
wfdFile->cFileName[sizeof(wfdFile->cFileName) - 1] = '\0';
#endif
std::strncpy(wfdFile->fileName, m_searchpointer->name, sizeof(wfdFile->fileName) - 1);
wfdFile->fileName[sizeof(wfdFile->fileName) - 1] = '\0';

if ( m_searchpointer->type == 2 )
wfdFile->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
wfdFile->fileAttributes |= FILE_ATTRIBUTE_DIRECTORY;

wfdFile->ftLastWriteTime = m_searchpointer->filetime;
wfdFile->ftLastAccessTime = m_searchpointer->filetime;
wfdFile->ftCreationTime = m_searchpointer->filetime;
wfdFile->lastWriteTime = m_searchpointer->filetime;
wfdFile->lastAccessTime = m_searchpointer->filetime;
wfdFile->creationTime = m_searchpointer->filetime;

wfdFile->nFileSizeLow = m_searchpointer->Length;
wfdFile->fileSizeLow = m_searchpointer->Length;
return 1;
}

Expand Down Expand Up @@ -718,7 +716,7 @@ HANDLE iso9660::OpenFile(const char *filename)
if (!pContext)
return INVALID_HANDLE_VALUE;

WIN32_FIND_DATA fileinfo;
Win32FindData fileinfo;
char *pointer, *pointer2;
char work[512];
pContext->m_bUseMode2 = false;
Expand All @@ -739,16 +737,9 @@ HANDLE iso9660::OpenFile(const char *filename)

intptr_t loop = (intptr_t)FindFirstFile9660( work, &fileinfo );

#ifdef TARGET_WINDOWS
auto wpointer = KODI::PLATFORM::WINDOWS::ToW(pointer);
#endif
while ( loop > 0)
{
#ifdef TARGET_WINDOWS
if (!_wcsicmp(fileinfo.cFileName, wpointer.c_str()))
#else
if ( !stricmp(fileinfo.cFileName, pointer ) )
#endif
if (!std::strcmp(fileinfo.fileName, pointer))
loop = -1;
else
loop = FindNextFile( NULL, &fileinfo );
Expand All @@ -760,7 +751,7 @@ HANDLE iso9660::OpenFile(const char *filename)
}

pContext->m_dwCurrentBlock = m_searchpointer->Location;
pContext->m_dwFileSize = m_info.curr_filesize = fileinfo.nFileSizeLow;
pContext->m_dwFileSize = m_info.curr_filesize = fileinfo.fileSizeLow;
pContext->m_pBuffer = new uint8_t[CIRC_BUFFER_SIZE * BUFFER_SIZE];
pContext->m_dwStartBlock = pContext->m_dwCurrentBlock;
pContext->m_dwFilePos = 0;
Expand Down
18 changes: 16 additions & 2 deletions xbmc/filesystem/iso9660.h
Expand Up @@ -145,6 +145,20 @@ struct iso_directories
};
#define MAX_ISO_FILES 30

struct Win32FindData
{
unsigned int fileAttributes;
FILETIME creationTime;
FILETIME lastAccessTime;
FILETIME lastWriteTime;
unsigned int fileSizeHigh;
unsigned int fileSizeLow;
unsigned int reserved0;
unsigned int reserved1;
char fileName[260];
char alternateFileName[14];
};

class iso9660
{
public:
Expand All @@ -165,8 +179,8 @@ class iso9660
iso9660( );
virtual ~iso9660( );

HANDLE FindFirstFile9660(const char *szLocalFolder, WIN32_FIND_DATA *wfdFile );
int FindNextFile( HANDLE szLocalFolder, WIN32_FIND_DATA *wfdFile );
HANDLE FindFirstFile9660(const char* szLocalFolder, Win32FindData* wfdFile);
int FindNextFile(HANDLE szLocalFolder, Win32FindData* wfdFile);
bool FindClose( HANDLE szLocalFolder );
DWORD SetFilePointer(HANDLE hFile, long lDistanceToMove, long* lpDistanceToMoveHigh, DWORD dwMoveMethod );
int64_t GetFileSize(HANDLE hFile);
Expand Down
14 changes: 0 additions & 14 deletions xbmc/platform/posix/PlatformDefs.h
Expand Up @@ -171,20 +171,6 @@ typedef struct _FILETIME
DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;

typedef struct _WIN32_FIND_DATA
{
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
char cFileName[260];
char cAlternateFileName[14];
} WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA;

#define FILE_ATTRIBUTE_DIRECTORY 0x00000010

#define FILE_BEGIN 0
Expand Down

0 comments on commit 4123ff4

Please sign in to comment.