Skip to content

Commit 899f618

Browse files
committed
Add Context.ApplicationDataDirectory
1 parent 022432f commit 899f618

File tree

5 files changed

+82
-336
lines changed

5 files changed

+82
-336
lines changed

src/CommonTK.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net461;net6.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
55
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
66
<Deterministic>True</Deterministic>
77
<AssemblyName>SAPTeam.CommonTK</AssemblyName>
@@ -46,11 +46,10 @@ For Getting started with this library you can visit our github page.</Descriptio
4646
<ItemGroup>
4747
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
4848
<PrivateAssets>all</PrivateAssets>
49-
<Version>3.6.143</Version>
49+
<Version>3.7.115</Version>
5050
</PackageReference>
51-
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All" />
52-
<PackageReference Include="System.Text.Json" Version="8.0.4" Condition=" '$(TargetFramework)' == 'netstandard2.0'" />
53-
<PackageReference Include="System.Text.Json" Version="6.0.9" Condition=" '$(TargetFramework)' == 'net461'" />
51+
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.25" PrivateAssets="All" />
52+
<PackageReference Include="System.Text.Json" Version="9.0.4" Condition=" '$(TargetFramework)' == 'netstandard2.0'" />
5453
</ItemGroup>
5554

5655
<ItemGroup>

src/Environment.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,35 @@ public static string ExecutablePath
9090
/// Gets the root application directory.
9191
/// </summary>
9292
public static string ApplicationDirectory => AppDomain.CurrentDomain.BaseDirectory;
93+
94+
/// <summary>
95+
/// Gets the path to the application data directory based on the operating system.
96+
/// </summary>
97+
/// <param name="appName">
98+
/// The name of the application. If not provided, the default application name will be used.
99+
/// </param>
100+
/// <returns>
101+
/// The path to the application data directory based on the operating system.
102+
/// </returns>
103+
public static string ApplicationDataDirectory(string appName = null)
104+
{
105+
if (string.IsNullOrEmpty(appName))
106+
{
107+
appName = ApplicationTitle;
108+
}
109+
110+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
111+
{
112+
appName = appName.ToLowerInvariant();
113+
}
114+
115+
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
116+
string unixHome = Environment.GetEnvironmentVariable("HOME") ?? Path.GetFullPath(".");
117+
string altAppData = Path.Combine(unixHome, ".config");
118+
119+
var path = Path.Combine(string.IsNullOrEmpty(localAppData) ? altAppData : localAppData, appName);
120+
121+
return path;
122+
}
93123
}
94124
}

src/JsonWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class JsonWorker
1818
/// Initializes a new instance of the <see cref="JsonWorker"/> class.
1919
/// </summary>
2020
/// <param name="options">
21-
/// The serializer options. (used in netstandard2.0 or net461 targets)
21+
/// The serializer options. (used in netstandard2.0 targets)
2222
/// </param>
2323
/// <param name="context">
2424
/// The source-generated serializer context. (used in net6.0+ targets)

0 commit comments

Comments
 (0)