mirror of
https://github.com/tribufu/tribufu-dotnet
synced 2025-06-15 09:54:18 +00:00
Rename Tribufu.Runtime to Tribufu.Platform
This commit is contained in:
@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Logging", "src\Trib
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Configuration", "src\Tribufu.Configuration\Tribufu.Configuration.csproj", "{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Configuration", "src\Tribufu.Configuration\Tribufu.Configuration.csproj", "{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Runtime", "src\Tribufu.Runtime\Tribufu.Runtime.csproj", "{26EEB407-733C-4383-9211-B083CD5F593B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Platform", "src\Tribufu.Platform\Tribufu.Platform.csproj", "{26EEB407-733C-4383-9211-B083CD5F593B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Database", "src\Tribufu.Database\Tribufu.Database.csproj", "{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Database", "src\Tribufu.Database\Tribufu.Database.csproj", "{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -5,7 +5,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Tomlyn.Extensions.Configuration;
|
using Tomlyn.Extensions.Configuration;
|
||||||
using Tribufu.Logging;
|
using Tribufu.Logging;
|
||||||
using Tribufu.Runtime;
|
using Tribufu.Platform;
|
||||||
|
|
||||||
namespace Tribufu.Configuration
|
namespace Tribufu.Configuration
|
||||||
{
|
{
|
||||||
@ -15,7 +15,7 @@ namespace Tribufu.Configuration
|
|||||||
|
|
||||||
public static IConfiguration Load(string[] fileNames)
|
public static IConfiguration Load(string[] fileNames)
|
||||||
{
|
{
|
||||||
var configDirectory = ApplicationContext.GetConfigDirectory();
|
var configDirectory = Paths.GetApplicationConfigDirectory();
|
||||||
var configurationBuilder = new ConfigurationBuilder();
|
var configurationBuilder = new ConfigurationBuilder();
|
||||||
configurationBuilder.AddEnvironmentVariables();
|
configurationBuilder.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<IsPublishable>false</IsPublishable>
|
<IsPublishable>false</IsPublishable>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
|
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
@ -26,6 +26,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
|
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
|
||||||
<ProjectReference Include="..\Tribufu.Runtime\Tribufu.Runtime.csproj" />
|
<ProjectReference Include="..\Tribufu.Platform\Tribufu.Platform.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -21,6 +21,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Tribufu.Configuration\Tribufu.Configuration.csproj" />
|
<ProjectReference Include="..\Tribufu.Configuration\Tribufu.Configuration.csproj" />
|
||||||
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
|
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
|
||||||
<ProjectReference Include="..\Tribufu.Runtime\Tribufu.Runtime.csproj" />
|
<ProjectReference Include="..\Tribufu.Platform\Tribufu.Platform.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -6,13 +6,13 @@ using System.IO;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Tribufu.Logging;
|
using Tribufu.Logging;
|
||||||
|
|
||||||
namespace Tribufu.Runtime
|
namespace Tribufu.Platform
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides standardized access to important application directories, such as config, saved data, logs, and platform-specific binaries.
|
/// Provides standardized access to important directories, such as config, saved data, logs, and platform-specific binaries.
|
||||||
/// This is especially useful for abstracting file path logic across environments (development, production, etc).
|
/// This is especially useful for abstracting file path logic across environments (development, production, etc).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ApplicationContext
|
public static class Paths
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the root base directory of the application.
|
/// Gets the root base directory of the application.
|
||||||
@ -23,7 +23,7 @@ namespace Tribufu.Runtime
|
|||||||
/// - It uses case-insensitive checks and runtime heuristics to improve accuracy.
|
/// - It uses case-insensitive checks and runtime heuristics to improve accuracy.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns>The absolute path to the base directory.</returns>
|
/// <returns>The absolute path to the base directory.</returns>
|
||||||
public static string GetBaseDirectory()
|
public static string GetApplicationDirectory()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ namespace Tribufu.Runtime
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Warn($"(ApplicationContext) Failed to resolve base directory: {ex.Message}");
|
Logger.Warn($"(Paths) Failed to resolve base directory: {ex.Message}");
|
||||||
return AppContext.BaseDirectory;
|
return AppContext.BaseDirectory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,22 +58,10 @@ namespace Tribufu.Runtime
|
|||||||
/// The absolute path to <c>bin/<runtime-identifier></c> if available,
|
/// The absolute path to <c>bin/<runtime-identifier></c> if available,
|
||||||
/// otherwise falls back to <c>bin/dotnet</c>.
|
/// otherwise falls back to <c>bin/dotnet</c>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static string GetBinDirectory()
|
public static string GetApplicationBinDirectory()
|
||||||
{
|
{
|
||||||
var binDirectory = Path.Combine(GetBaseDirectory(), "bin");
|
var binDirectory = Path.Combine(GetApplicationDirectory(), "bin");
|
||||||
|
|
||||||
#if NETSTANDARD
|
|
||||||
var runtimeIdentifier = GetRuntimeIdentifierLegacy();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(runtimeIdentifier))
|
|
||||||
{
|
|
||||||
binDirectory = Path.Combine(binDirectory, runtimeIdentifier);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
binDirectory = Path.Combine(binDirectory, "dotnet");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (!string.IsNullOrEmpty(RuntimeInformation.RuntimeIdentifier))
|
if (!string.IsNullOrEmpty(RuntimeInformation.RuntimeIdentifier))
|
||||||
{
|
{
|
||||||
binDirectory = Path.Combine(binDirectory, RuntimeInformation.RuntimeIdentifier);
|
binDirectory = Path.Combine(binDirectory, RuntimeInformation.RuntimeIdentifier);
|
||||||
@ -82,102 +70,53 @@ namespace Tribufu.Runtime
|
|||||||
{
|
{
|
||||||
binDirectory = Path.Combine(binDirectory, "dotnet");
|
binDirectory = Path.Combine(binDirectory, "dotnet");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return binDirectory;
|
return binDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetRuntimeIdentifierLegacy()
|
|
||||||
{
|
|
||||||
string osPart;
|
|
||||||
PlatformID platform = Environment.OSVersion.Platform;
|
|
||||||
|
|
||||||
switch (platform)
|
|
||||||
{
|
|
||||||
case PlatformID.Win32NT:
|
|
||||||
osPart = "win";
|
|
||||||
break;
|
|
||||||
case PlatformID.Unix:
|
|
||||||
if (IsMacOS())
|
|
||||||
osPart = "osx";
|
|
||||||
else
|
|
||||||
osPart = "linux";
|
|
||||||
break;
|
|
||||||
case PlatformID.MacOSX:
|
|
||||||
osPart = "osx";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
osPart = "unknown";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var archPart = Environment.Is64BitProcess ? "x64" : "x86";
|
|
||||||
if (osPart == "unknown")
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"{osPart}-{archPart}";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsMacOS()
|
|
||||||
{
|
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
|
||||||
{
|
|
||||||
Version version = Environment.OSVersion.Version;
|
|
||||||
|
|
||||||
if (version.Major >= 19)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the configuration directory.
|
/// Gets the path to the configuration directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The absolute path to the <c>config</c> directory.</returns>
|
/// <returns>The absolute path to the <c>config</c> directory.</returns>
|
||||||
public static string GetConfigDirectory()
|
public static string GetApplicationConfigDirectory()
|
||||||
{
|
{
|
||||||
return Path.Combine(GetBaseDirectory(), "config");
|
return Path.Combine(GetApplicationDirectory(), "config");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the assets directory.
|
/// Gets the path to the assets directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The absolute path to the <c>assets</c> directory.</returns>
|
/// <returns>The absolute path to the <c>assets</c> directory.</returns>
|
||||||
public static string GetAssetsDirectory()
|
public static string GetApplicationAssetsDirectory()
|
||||||
{
|
{
|
||||||
return Path.Combine(GetBaseDirectory(), "assets");
|
return Path.Combine(GetApplicationDirectory(), "assets");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the saved data directory.
|
/// Gets the path to the saved data directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The absolute path to the <c>saved</c> directory.</returns>
|
/// <returns>The absolute path to the <c>saved</c> directory.</returns>
|
||||||
public static string GetSavedDirectory()
|
public static string GetApplicationSavedDirectory()
|
||||||
{
|
{
|
||||||
return Path.Combine(GetBaseDirectory(), "saved");
|
return Path.Combine(GetApplicationDirectory(), "saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the cache directory inside <c>saved</c>.
|
/// Gets the path to the cache directory inside <c>saved</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The absolute path to the <c>saved/cache</c> directory.</returns>
|
/// <returns>The absolute path to the <c>saved/cache</c> directory.</returns>
|
||||||
public static string GetCacheDirectory()
|
public static string GetApplicationCacheDirectory()
|
||||||
{
|
{
|
||||||
return Path.Combine(GetSavedDirectory(), "cache");
|
return Path.Combine(GetApplicationSavedDirectory(), "cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the logs directory inside <c>saved</c>.
|
/// Gets the path to the logs directory inside <c>saved</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The absolute path to the <c>saved/logs</c> directory.</returns>
|
/// <returns>The absolute path to the <c>saved/logs</c> directory.</returns>
|
||||||
public static string GetLogsDirectory()
|
public static string GetApplicationLogsDirectory()
|
||||||
{
|
{
|
||||||
return Path.Combine(GetSavedDirectory(), "logs");
|
return Path.Combine(GetApplicationSavedDirectory(), "logs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackageId>Tribufu.Runtime</PackageId>
|
<PackageId>Tribufu.Platform</PackageId>
|
||||||
<Description>Tribufu Runtime Extensions</Description>
|
<Description>Tribufu Runtime Extensions</Description>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -9,12 +9,13 @@
|
|||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<IsPublishable>false</IsPublishable>
|
<IsPublishable>false</IsPublishable>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
|
<TargetFrameworks>net5.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Tribufu.ComponentModel\Tribufu.ComponentModel.csproj" />
|
||||||
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
|
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user