@@ -177,15 +177,15 @@ namespace
177177 }
178178 catch (Platform::AccessDeniedException^ e)
179179 {
180- Windows::UI::Popups::MessageDialog^ dialog =
181- ref new Windows::UI::Popups::MessageDialog (" Path \" " + path + " \" is not currently accessible. Please open any containing directory to access it." );
180+ // for some reason the path is inaccessible from within here???
181+ Windows::UI::Popups::MessageDialog^ dialog = ref new Windows::UI::Popups::MessageDialog (" Path is not currently accessible. Please open any containing directory to access it." );
182182 dialog->Commands ->Append (ref new Windows::UI::Popups::UICommand (" Open file picker" ));
183183 dialog->Commands ->Append (ref new Windows::UI::Popups::UICommand (" Cancel" ));
184184 return concurrency::create_task (dialog->ShowAsync ()).then ([path](Windows::UI::Popups::IUICommand^ cmd) {
185185 if (cmd->Label == " Open file picker" )
186186 {
187187 return TriggerPickerAddDialog ().then ([path](Platform::String^ added_path) {
188- /* Retry */
188+ // Retry
189189 return LocateStorageItem<T>(path);
190190 });
191191 }
@@ -403,7 +403,7 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(
403403 creationDisposition = (mode & RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING) != 0 ?
404404 OPEN_ALWAYS : CREATE_ALWAYS;
405405 }
406-
406+ path_str = " \\\\ ? \\ " + path_str;
407407 file_handle = CreateFile2FromAppW (path_str->Data (), desireAccess, FILE_SHARE_READ, creationDisposition, NULL );
408408
409409 if (file_handle != INVALID_HANDLE_VALUE)
@@ -991,7 +991,7 @@ int uwp_move_path(std::filesystem::path old_path, std::filesystem::path new_path
991991 bool fail = false ;
992992 do
993993 {
994- if (findDataResult.cFileName != L" ." && findDataResult.cFileName != L" .." )
994+ if (wcscmp ( findDataResult.cFileName , L" ." ) != 0 && wcscmp ( findDataResult.cFileName , L" .." ) != 0 )
995995 {
996996 std::filesystem::path temp_old = old_path;
997997 std::filesystem::path temp_new = new_path;
@@ -1113,30 +1113,93 @@ struct libretro_vfs_implementation_dir
11131113 char *entry_name;
11141114};
11151115
1116- libretro_vfs_implementation_dir * retro_vfs_opendir_impl (const char * name, bool include_hidden)
1116+ libretro_vfs_implementation_dir* retro_vfs_opendir_impl (const char * name, bool include_hidden)
11171117{
1118- wchar_t * name_wide;
1119- Platform::String^ name_str;
1120- libretro_vfs_implementation_dir * rdir;
1118+ wchar_t * name_wide;
1119+ Platform::String^ name_str;
1120+ libretro_vfs_implementation_dir* rdir;
11211121
1122- if (!name || !*name)
1123- return NULL ;
1122+ if (!name || !*name)
1123+ return NULL ;
11241124
1125- rdir = (libretro_vfs_implementation_dir*)calloc (1 , sizeof (*rdir));
1126- if (!rdir)
1127- return NULL ;
1125+ rdir = (libretro_vfs_implementation_dir*)calloc (1 , sizeof (*rdir));
1126+ if (!rdir)
1127+ return NULL ;
11281128
1129- name_wide = utf8_to_utf16_string_alloc (name);
1130- windowsize_path (name_wide);
1131- name_str = ref new Platform::String (name_wide);
1132- free (name_wide);
1129+ name_wide = utf8_to_utf16_string_alloc (name);
1130+ windowsize_path (name_wide);
1131+ name_str = ref new Platform::String (name_wide);
1132+ free (name_wide);
11331133
1134- rdir->directory = RunAsyncAndCatchErrors<IVectorView<IStorageItem^>^>([&]() {
1135- return concurrency::create_task (LocateStorageItem<StorageFolder>(name_str)).then ([&](StorageFolder^ folder) {
1136- return folder->GetItemsAsync ();
1137- });
1138- }, nullptr );
11391134
1135+ WIN32_FILE_ATTRIBUTE_DATA lpFileInfo;
1136+ std::filesystem::path dir (name);
1137+
1138+ if (dir.empty ())
1139+ return NULL ;
1140+
1141+ if (!(rdir->directory ))
1142+ {
1143+ // check if file attributes can be gotten successfully
1144+ if (GetFileAttributesExFromAppW (dir.parent_path ().wstring ().c_str (), GetFileExInfoStandard, &lpFileInfo))
1145+ {
1146+ // check that the files attributes are not null or empty
1147+ if (lpFileInfo.dwFileAttributes != INVALID_FILE_ATTRIBUTES && lpFileInfo.dwFileAttributes != 0 )
1148+ {
1149+ if (lpFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1150+ {
1151+ std::wstring filteredPath (dir.wstring ().c_str ());
1152+ WIN32_FIND_DATA findDataResult;
1153+ if (filteredPath[filteredPath.size () - 1 ] == ' \\ ' )
1154+ filteredPath.erase (filteredPath.size () - 1 );
1155+ filteredPath += L" \\ *.*" ;
1156+ HANDLE searchResults = FindFirstFileExFromAppW (filteredPath.c_str (), FindExInfoBasic, &findDataResult, FindExSearchNameMatch, nullptr , FIND_FIRST_EX_LARGE_FETCH);
1157+ if (searchResults != INVALID_HANDLE_VALUE)
1158+ {
1159+ Platform::Collections::Vector<IStorageItem^>^ result = ref new Platform::Collections::Vector<IStorageItem^>();
1160+ do
1161+ {
1162+ if (wcscmp (findDataResult.cFileName , L" ." ) != 0 && wcscmp (findDataResult.cFileName , L" .." ) != 0 )
1163+ {
1164+ if (!((findDataResult.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (findDataResult.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)))
1165+ {
1166+ std::filesystem::path temp_new = dir;
1167+ temp_new /= findDataResult.cFileName ;
1168+
1169+ std::wstring temp_path = temp_new.generic_wstring ();
1170+ while (true ) {
1171+ size_t p = temp_path.find (L" /" );
1172+ if (p == std::wstring::npos) break ;
1173+ temp_path.replace (p, 1 , L" \\ " );
1174+ }
1175+ IStorageItem^ item;
1176+ if (findDataResult.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1177+ {
1178+ item = RunAsyncAndCatchErrors<StorageFolder^>([&]() {
1179+ return concurrency::create_task (LocateStorageItem<StorageFolder>(ref new Platform::String (temp_path.c_str ())));
1180+ }, nullptr );
1181+ }
1182+ else
1183+ {
1184+ item = RunAsyncAndCatchErrors<StorageFile^>([&]() {
1185+ return concurrency::create_task (LocateStorageItem<StorageFile>(ref new Platform::String (temp_path.c_str ())));
1186+ }, nullptr );
1187+ }
1188+
1189+ if (item)
1190+ if (result)
1191+ result->Append (item);
1192+ }
1193+ }
1194+ } while (FindNextFile (searchResults, &findDataResult));
1195+ FindClose (searchResults);
1196+ if (result)
1197+ rdir->directory = result->GetView ();
1198+ }
1199+ }
1200+ }
1201+ }
1202+ }
11401203 if (rdir->directory )
11411204 return rdir;
11421205
0 commit comments