Skip to content

Microsoft.Storage.ApplicationData #2639

Open
@DrusTheAxe

Description

@DrusTheAxe

Proposal: Microsoft.Storage.ApplicationData

Summary

Provide a modern enhanced version of Windows.Storage.ApplicationData and Windows.Management.Core.ApplicationDataManager

Microsoft-internal task 40050113

Rationale

  • Windows.Storage.ApplicationData.Current only works if you have package identity AND running in AppContainer
  • Windows.Management.Core.ApplicationDataManager.CreateForPackageFamily is equivalent but requires you have package identity AND running MediumIL or higher
  • Unpackaged apps have long been advised to use %LOCALAPPDATA%\publisher\product, %LOCALAPPDATA%\Temp and HKCU\SOFTWARE\publisher\product but ApplicationData doesn't support that
  • Windows.Storage.ApplicationData has several deprecated and obsolete features (e.g. .RoamingFolder)
  • ApplicationData.*Folder only provide access to the filesystem via StorageFolder. There's no way to get their .Path without going thrug a StorageFolder incurring significant performance overhead
  • ApplicationData has async methods which should be available synchronously e.g. ClearAsync() should offer `Clear() as a synchronous variant (or replacement?)

Windows App SDK can and should provide a modern revision of the ApplicationData API, addressing the issues above (one API supporting both packaged and unpackaged apps).

Scope

Capability Priority
APIs equivalent to Windows.Storage.ApplicationData (minus deprecated APIs) Must
APIs available to packaged and unpackaged applications Must
APIs offer filesystem access without requiring use of StorageFolder Must
Synchronous equivalents to Windows.Storage.ApplicationData.*Async() APIs Must
WinRT API Must

Important Notes

Microsoft.Storage.ApplicationData supports packaged and unpackaged apps. The underlying data stores are different but equivalent(ish):

Packaged Unpackaged
ApplicationData.LocalCacheFolder %LOCALAPPDATA%\<publisher>\<product>
ApplicationData.LocalFolder %LOCALAPPDATA%\<publisher>\<product>
ApplicationData.MachineFolder %ProgramData%\<publisher>\<product>
ApplicationData.RoamingFolder %LOCALAPPDATA%\Roaming
ApplicationData.TemporaryFolder %LOCALAPPDATA%\Temp
ApplicationData.LocalSettings HKCU\SOFTWARE\<publisher>\<product>

WinRT API

Here's a sketch of the general shape of the API to express the intent of the ask. The actual API when designed/spec'd/reviewed/approved may differ.

Microsoft.Storage.ApplicationData.idl

namespace Microsoft.Storage.ApplicationData
{
[contract(ApplicationData, 1)]
enum ApplicationDataLocality
{
    // NOTE: Values compatible with Windows.Storage.ApplicationDataLocality
    Local = 0,
    LocalCache = 3,
    SharedLocal = 4,
    Temporary = 2,
}

[contract(ApplicationData, 1)]
runtimeclass ApplicationData
{
    /// Return an ApplicationData object if the current process has package identity
    /// NOTE: This is equivalent to `ApplicationData.ForPackageFamily(Windows.ApplicationModel.Package.Current.Id.FamilyName)`
    static ApplicationData GetDefault();

    /// NOTE: Requires MediumIL (or higher) if the process lacks package identity.
    /// NOTE: Requires MediumIL (or higher) if the process has package identity but different from the packageFamilyName parameer.
    /// NOTE: GetForPackageFamily(Windows.ApplicationModel.Package.Current.Id.FamilyName) is equivalent to GetDefault()
    static ApplicationData GetForPackageFamily(String packageFamilyName);

    /// NOTE: Requires admin privilege if user != current user
    /// NOTE: GetForUser(Window.System.User.GetDefault) is equivalent to GetDefault()
    static ApplicationData GetForUser(Windows.System.User user);

    /// NOTE: Requires admin privilege if user != current user
    /// NOTE: GetForUser(Window.System.User.GetDefault, packageFamilyName) is equivalent to GetForPackageFamily(packageFamilyName)
    static ApplicationData GetForUser(Windows.System.User user, String packageFamilyName);

    StorageFolder LocalCacheFolder;
    StorageFolder LocalFolder;
    StorageFolder TemporaryFolder;
    StorageFolder SharedLocalFolder;    //NOTE: Returns NULL if process lacks package identity

    String LocalCachePath;
    String LocalPath;
    String TemporaryPath;
    String SharedLocalPath; //NOTE: Returns NULL if process lacks package identity

    ApplicationDataContainer LocalSettings;

    void Clear();
    void Clear(ApplicationDataLocality locality);

    AsyncAction ClearAsync();
    AsyncAction ClearAsync(ApplicationDataLocality locality);
}
}

Open Questions

Q: Is there an unpackaged equivalent to GetPublisherCacheFolder()?

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions