mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-26 10:24:27 +01:00
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using BTCPayServer.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
using NBitcoin;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace BTCPayServer.Configuration
|
|
{
|
|
public class DefaultDataDirectory
|
|
{
|
|
public static string GetDefaultDirectory(string appName, Network network, bool createDirectory)
|
|
{
|
|
string directory = null;
|
|
var home = Environment.GetEnvironmentVariable("HOME");
|
|
if(!string.IsNullOrEmpty(home))
|
|
{
|
|
if(createDirectory)
|
|
Logs.Configuration.LogInformation("Using HOME environment variable for initializing application data");
|
|
directory = home;
|
|
directory = Path.Combine(directory, "." + appName.ToLowerInvariant());
|
|
}
|
|
else
|
|
{
|
|
var localAppData = Environment.GetEnvironmentVariable("APPDATA");
|
|
if(!string.IsNullOrEmpty(localAppData))
|
|
{
|
|
if(createDirectory)
|
|
Logs.Configuration.LogInformation("Using APPDATA environment variable for initializing application data");
|
|
directory = localAppData;
|
|
directory = Path.Combine(directory, appName);
|
|
}
|
|
else
|
|
{
|
|
throw new DirectoryNotFoundException("Could not find suitable datadir");
|
|
}
|
|
}
|
|
if(!Directory.Exists(directory) && createDirectory)
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
directory = Path.Combine(directory, network.Name);
|
|
if(!Directory.Exists(directory) && createDirectory)
|
|
{
|
|
Logs.Configuration.LogInformation("Creating data directory");
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
return directory;
|
|
}
|
|
}
|
|
}
|