Skip to content

Commit

Permalink
Fix implementation of GetFolderNative (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored May 11, 2019
1 parent bba7a1e commit d23b191
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,105 @@

static const CLR_RT_MethodHandler method_lookup[] =
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_Devices_SDCard::MountMMCNative___STATIC__VOID__BOOLEAN,
Library_win_storage_native_Windows_Storage_Devices_SDCard::MountSpiNative___STATIC__VOID__I4__I4,
Library_win_storage_native_Windows_Storage_Devices_SDCard::UnmountNative___STATIC__VOID,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1,
Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING,
Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1,
Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_StorageFile::DeleteFileNative___VOID,
Library_win_storage_native_Windows_Storage_StorageFile::RenameFileNative___VOID__STRING,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_StorageFile::CheckFileNative___STATIC__VOID__STRING,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder,
Library_win_storage_native_Windows_Storage_StorageFolder::GetInternalStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder,
Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder,
Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFilesNative___SZARRAY_WindowsStorageStorageFile__U4__U4,
Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNative___WindowsStorageStorageFile__STRING__U4,
Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNative___WindowsStorageStorageFolder__STRING__U4,
Library_win_storage_native_Windows_Storage_StorageFolder::DeleteFolderNative___VOID,
Library_win_storage_native_Windows_Storage_StorageFolder::RenameFolderNative___VOID__STRING,
Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNative___WindowsStorageStorageFolder__STRING,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_Devices_SDCard::MountMMCNative___STATIC__VOID__BOOLEAN,
Library_win_storage_native_Windows_Storage_Devices_SDCard::MountSpiNative___STATIC__VOID__I4__I4,
Library_win_storage_native_Windows_Storage_Devices_SDCard::UnmountNative___STATIC__VOID,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1,
Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING,
Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1,
Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_StorageFile::DeleteFileNative___VOID,
Library_win_storage_native_Windows_Storage_StorageFile::RenameFileNative___VOID__STRING,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_StorageFile::GetFileFromPathNative___STATIC__WindowsStorageStorageFile__STRING__STRING,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder,
Library_win_storage_native_Windows_Storage_StorageFolder::GetInternalStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder,
Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder,
Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFilesNative___SZARRAY_WindowsStorageStorageFile__U4__U4,
Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNative___WindowsStorageStorageFile__STRING__U4,
Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNative___WindowsStorageStorageFolder__STRING__U4,
Library_win_storage_native_Windows_Storage_StorageFolder::DeleteFolderNative___VOID,
Library_win_storage_native_Windows_Storage_StorageFolder::RenameFolderNative___VOID__STRING,
Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNative___WindowsStorageStorageFolder__STRING,
NULL,
NULL,
NULL,
};

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Storage =
{
"Windows.Storage",
0x3BE02CF0,
method_lookup,
{ 1, 0, 0, 0 }
};
"Windows.Storage",
0x53942C94,
method_lookup,
{ 1, 0, 0, 1 }
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ struct Library_win_storage_native_Windows_Storage_FileIO

struct Library_win_storage_native_Windows_Storage_StorageFile
{
static const int FIELD___dateCreated = 1;
static const int FIELD___name = 2;
static const int FIELD___path = 3;
static const int FIELD___dateCreated = 1;
static const int FIELD___name = 2;
static const int FIELD___path = 3;

NANOCLR_NATIVE_DECLARE(DeleteFileNative___VOID);
NANOCLR_NATIVE_DECLARE(RenameFileNative___VOID__STRING);
NANOCLR_NATIVE_DECLARE(CheckFileNative___STATIC__VOID__STRING);
NANOCLR_NATIVE_DECLARE(DeleteFileNative___VOID);
NANOCLR_NATIVE_DECLARE(RenameFileNative___VOID__STRING);
NANOCLR_NATIVE_DECLARE(GetFileFromPathNative___STATIC__WindowsStorageStorageFile__STRING__STRING);

//--//
//--//

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,7 @@
#include <ff.h>
#include "win_storage_native.h"


HRESULT Library_win_storage_native_Windows_Storage_StorageFile::CheckFileNative___STATIC__VOID__STRING(CLR_RT_StackFrame& stack)
{
NANOCLR_HEADER();

const char* filePath;
FRESULT fr;
FILINFO fileInfo;

// get a pointer to the file path
filePath = stack.Arg1().DereferenceString()->StringText();

fr = f_stat(filePath, &fileInfo);

if(fr == FR_OK)
{
// file exists, we are good
}
else if(fr == FR_NO_FILE)
{
// file doesn't exist
NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND);
}
else
{
// IO error
NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO);
}

NANOCLR_NOCLEANUP();
}

extern SYSTEMTIME GetDateTime(uint16_t date, uint16_t time);

HRESULT Library_win_storage_native_Windows_Storage_StorageFile::DeleteFileNative___VOID(CLR_RT_StackFrame& stack)
{
Expand Down Expand Up @@ -98,3 +67,75 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFile::RenameFileNative
NANOCLR_CLEANUP_END();
}

HRESULT Library_win_storage_native_Windows_Storage_StorageFile::GetFileFromPathNative___STATIC__WindowsStorageStorageFile__STRING__STRING( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();

CLR_RT_TypeDef_Index storageFileTypeDef;
CLR_RT_HeapBlock* storageFile;

const char* filePath;
const char* fileName;

FRESULT fr;
FILINFO fileInfo;
SYSTEMTIME fileInfoTime;

// get a pointer to the file path
filePath = stack.Arg0().DereferenceString()->StringText();

// get a pointer to the file name
fileName = stack.Arg1().DereferenceString()->StringText();

fr = f_stat(filePath, &fileInfo);
if(fr == FR_OK)
{
// is this a file?
if ( !(fileInfo.fattrib & AM_DIR) )
{
// path represents a file, we are good

// compose return object
// find <StorageFile> type, don't bother checking the result as it exists for sure
g_CLR_RT_TypeSystem.FindTypeDef("StorageFile", "Windows.Storage", storageFileTypeDef);

// create a <StorageFile>
NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(stack.PushValue(), storageFileTypeDef));

// get a handle to the storage file
storageFile = stack.TopValue().Dereference();

// file name
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___name], fileName));

NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___path], filePath));

// get the date time details and fill in the managed field
// compute directory date
fileInfoTime = GetDateTime(fileInfo.fdate, fileInfo.ftime);

// get a reference to the dateCreated managed field...
CLR_RT_HeapBlock& dateFieldRef = storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___dateCreated];
CLR_INT64* pRes = (CLR_INT64*)&dateFieldRef.NumericByRef().s8;
// ...and set it with the fileInfoTime
*pRes = HAL_Time_ConvertFromSystemTime( &fileInfoTime );
}
else
{
// path exists but it's a folder
NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND);
}
}
else if(fr == FR_NO_FILE)
{
// file doesn't exist
NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND);
}
else
{
// IO error
NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO);
}

NANOCLR_NOCLEANUP();
}
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::RenameFolderNa
NANOCLR_CLEANUP_END();
}

HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNative___WindowsStorageStorageFolder__STRING(CLR_RT_StackFrame& stack)
HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNative___WindowsStorageStorageFolder__STRING( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();

Expand Down
Loading

0 comments on commit d23b191

Please sign in to comment.