Skip to content

Commit

Permalink
chore: Do not allow setting application data path overrides after the…
Browse files Browse the repository at this point in the history
… application is initialized
  • Loading branch information
MartinZikmund committed Jul 27, 2023
1 parent cb19c32 commit a079700
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Uno.UWP/Storage/ApplicationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma warning disable 114 // new keyword hiding
#pragma warning disable 67 // new keyword hiding
using System;
using Uno;

namespace Windows.Storage;

Expand Down Expand Up @@ -38,6 +39,8 @@ private ApplicationData()
_roamingSettingsLazy = new(() => new ApplicationDataContainer(this, "Roaming", ApplicationDataLocality.Roaming));

InitializePartial();

WinRTFeatureConfiguration.ApplicationData.IsApplicationDataInitialized = true;
}

partial void InitializePartial();
Expand Down
48 changes: 45 additions & 3 deletions src/Uno.UWP/WinRTFeatureConfiguration.ApplicationData.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,75 @@
#nullable enable

using System;

namespace Uno;

partial class WinRTFeatureConfiguration
{
public static class ApplicationData
{
#if __SKIA__
private static string? _temporaryFolderPathOverride;
private static string? _localCacheFolderPathOverride;
private static string? _applicationDataPathOverride;

/// <summary>
/// Allows overriding the root folder path that the application will use
/// to store its TempState folder.
/// </summary>
/// <remarks>Only applies to Skia targets.</remarks>
public static string? TemporaryFolderPathOverride { get; set; }
public static string? TemporaryFolderPathOverride
{
get => _temporaryFolderPathOverride;
set
{
EnsureApplicationDataNotInitialized();
_temporaryFolderPathOverride = value;
}
}

/// <summary>
/// Allows overriding the root folder path that the application will use
/// to store its LocalCache folder.
/// </summary>
/// <remarks>Only applies to Skia targets.</remarks>
public static string? LocalCacheFolderPathOverride { get; set; }
public static string? LocalCacheFolderPathOverride
{
get => _localCacheFolderPathOverride;
set
{
EnsureApplicationDataNotInitialized();
_localCacheFolderPathOverride = value;
}
}

/// <summary>
/// Allows overriding the root folder that the application will use
/// to store its application data folders (LocalFolder, RoamingFolder, etc.).
/// Only applies to Skia targets.
/// </summary>
/// <remarks>Only applies to Skia targets.</remarks>
public static string? ApplicationDataPathOverride { get; set; }
public static string? ApplicationDataPathOverride
{
get => _applicationDataPathOverride;
set
{
EnsureApplicationDataNotInitialized();
_applicationDataPathOverride = value;
}
}

internal static bool IsApplicationDataInitialized { get; set; }

private static void EnsureApplicationDataNotInitialized()
{
if (IsApplicationDataInitialized)
{
throw new InvalidOperationException(
"The property was set too late in the application lifecycle." +
"Set it in Program.cs, so it is applied before ApplicationData is initialized.");
}
}
#endif
}
}

0 comments on commit a079700

Please sign in to comment.