It is IMPOSSIBLE to achieve such thing!
According to @RobCaplan https://blogs.msdn.microsoft.com/wsdevsol/2012/12/04/skip-the-path-stick-to-the-storagefile/, the geniuses at Microsoft has invented a security storage solution that neither is secure nor backward compatible a.k.a. making developers' lives easier: Once the user grants an app the StorageFolder
, the app can wreak havoc on it using the supplied StorageFile
API. The following code
auto folderPicker = ref new Windows::Storage::Pickers::FolderPicker();
folderPicker->FileTypeFilter->Clear();
folderPicker->FileTypeFilter->Append("*");
create_task(folderPicker->PickSingleFolderAsync()).then([](Windows::Storage::StorageFolder^ folder)
{
if (folder == nullptr)
cancel_current_task();
Windows::Storage::AccessCache::StorageApplicationPermissions::FutureAccessList->Add(folder);
create_task(folder->GetItemsAsync()).then([](IVectorView<IStorageItem^>^ items)
{
// Delete the folder content or encrypt it and demand money
auto iter = items->First();
while (iter->HasCurrent)
{
create_task(iter->Current->DeleteAsync(StorageDeleteOption::PermanentDelete));
iter->MoveNext();
}
});
});
will happily clear out the folder an unlucky user picks. A malicious app doesn't even need to use Win32 API to do that. Logically, API is not the cause of security problem. The existing UWP Win32 API obviously handles correctly local storage access so it should take minimal effort to support FutureAccessList
in Win32 API; such desire to make UWP development difficult must be intentional. (There is no doubt that Centenial is NOT going to fly. Nobody wants to move from the great flexibility of Win32 to the UWP prison.)
EDIT: I should have written
It is IMPOSSIBLE to achieve such thing the way I wanted!
since the article does suggest a quick and very smart solution
If the library doesn’t have such an interface and you cannot add one then you will need to copy the StorageFile contents into the application data folder (likely in the TemporaryFolder) and then pass the path to the temporary copy to the library.
so in my situation, every time a user picks a repository folder, I can copy the whole folder to the local storage, operates on them and then copy the whole thing back to its original location. And of course "the way I wanted" above refers to the efficient one where you don't have to copy things back and forth.