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; } /// /// return the directory path for temp files, just add file name onto end /// /// public static string GetTempFileDirectoryPath() { string directoryPath = Path.GetTempPath() + "_" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; System.IO.Directory.CreateDirectory(directoryPath); return directoryPath; } /// /// Returns configuration file from local users directory /// /// 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; } } }