mirror of
https://github.com/Tribufu/TribufuDotNet
synced 2026-08-09 21:01:07 +00:00
Migrate to new tribufu project structure
This commit is contained in:
parent
be25ee8fe3
commit
6ef2762a64
114 changed files with 35 additions and 26 deletions
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
using Tomlyn.Extensions.Configuration;
|
||||
using Tribufu.Logging;
|
||||
using Tribufu.Platform;
|
||||
|
||||
namespace Tribufu.Configuration
|
||||
{
|
||||
public static class ConfigurationLoader
|
||||
{
|
||||
public static IConfiguration Load(string[] fileNames)
|
||||
{
|
||||
var configDirectory = Paths.GetApplicationConfigDirectory();
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
configurationBuilder.AddEnvironmentVariables();
|
||||
|
||||
foreach (var fileName in fileNames)
|
||||
{
|
||||
var fullPath = Path.Combine(configDirectory, fileName);
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
Logger.Debug($"Config file '{fullPath}' not found, skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(fullPath).ToLowerInvariant();
|
||||
switch (extension)
|
||||
{
|
||||
case ".ini":
|
||||
configurationBuilder.AddIniFile(fullPath, true, false);
|
||||
break;
|
||||
case ".json":
|
||||
configurationBuilder.AddJsonFile(fullPath, true, false);
|
||||
break;
|
||||
case ".toml":
|
||||
configurationBuilder.AddTomlFile(fullPath, true, false);
|
||||
break;
|
||||
default:
|
||||
Logger.Warn($"Unsupported config file extension: {extension}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return configurationBuilder.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue