mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bnhtrade.Core
|
|
{
|
|
public class Config
|
|
{
|
|
public string GetAppDataPath()
|
|
{
|
|
string path = null;
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
|
+ @"\bnhtrade\";
|
|
}
|
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
|
{
|
|
path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
|
+ "/.bnhtrade/";
|
|
}
|
|
else
|
|
{
|
|
throw new PlatformNotSupportedException("Unsupported operating system");
|
|
}
|
|
return path;
|
|
}
|
|
|
|
/// <summary>
|
|
/// return the directory path for temp files, just add file name onto end
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetTempFileDirectoryPath()
|
|
{
|
|
string directoryPath = Path.GetTempPath()
|
|
+ "_" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
|
System.IO.Directory.CreateDirectory(directoryPath);
|
|
return directoryPath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns configuration file from local users directory
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal Configuration GetConfiguration()
|
|
{
|
|
string path = new bnhtrade.Core.Config().GetAppDataPath();
|
|
string configFileName = "app.local.config";
|
|
|
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
|
configMap.ExeConfigFilename = path + configFileName;
|
|
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
|
|
|
return config;
|
|
}
|
|
}
|
|
}
|