This documentation does not mention about enumerating the LocalCache\Local folder under the package data folder.
When enumerating that folder, it seems to return all the folders (but curiously no files) under %localappdata%, which is extremely confusing and unexpected, and is documented nowhere.
To reproduce:
- Create a new packaged winui3 app (C++ in my case)
- Add a
ListView and add a Loaded handler in the GUI
- Use this code
static std::filesystem::path GetLocalDataFolder()
{
wil::unique_cotaskmem_string localAppData;
SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, localAppData.put());
std::array<wchar_t, PACKAGE_FAMILY_NAME_MAX_LENGTH + 1> familyName;
UINT32 bufferSize = familyName.size();
GetCurrentPackageFamilyName(&bufferSize, familyName.data());
return std::filesystem::path{ localAppData.get() } / std::format(LR"(packages\{}\LocalCache\Local)", familyName.data());
}
void MainWindow::Files_Loaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
std::vector<winrt::Windows::Foundation::IInspectable> result;
for (auto file : std::filesystem::directory_iterator{ GetLocalDataFolder2() })
{
result.push_back(winrt::box_value(file.path().wstring()));
}
sender.as<winrt::Microsoft::UI::Xaml::Controls::ListView>().ItemsSource(winrt::single_threaded_vector(std::move(result)));
}
Using the ApplicationData winrt api gets the same result:
static std::filesystem::path GetLocalDataFolder2()
{
return std::filesystem::path{ winrt::Windows::Storage::ApplicationData::Current().LocalCacheFolder().Path().c_str() } / L"Local";
}
Repro project here
Additional context: The exact behavior can also be reproduced with a packaged console application. It really is caused by msix virtualization, not winui3
This documentation does not mention about enumerating the
LocalCache\Localfolder under the package data folder.When enumerating that folder, it seems to return all the folders (but curiously no files) under
%localappdata%, which is extremely confusing and unexpected, and is documented nowhere.To reproduce:
ListViewand add aLoadedhandler in the GUIUsing the
ApplicationDatawinrt api gets the same result:Repro project here
Additional context: The exact behavior can also be reproduced with a packaged console application. It really is caused by msix virtualization, not winui3