public SettingsHandler(SettingFileTypes settingType) { SettingsFile = GetSettingsPath(settingType); if (!Directory.Exists(Path.GetDirectoryName(SettingsFile))) { Directory.CreateDirectory(Path.GetDirectoryName(SettingsFile)); } }
private string GetSettingsPath(SettingFileTypes settingType) { // Application Settings if (settingType == SettingFileTypes.Application) { string executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName); return(Regex.Replace(executablePath, @"\.exe\z", ".xml", RegexOptions.IgnoreCase)); } // User Settings AssemblyDetails assemblyInfo = AssemblyInformation.GetAssemblyDetails(); string retval = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); if (!string.IsNullOrEmpty(assemblyInfo.Company)) { retval = Path.Combine(retval, assemblyInfo.Company); } if (!string.IsNullOrEmpty(assemblyInfo.Name)) { retval = Path.Combine(retval, assemblyInfo.Name); } else if (!string.IsNullOrEmpty(assemblyInfo.Title)) { retval = Path.Combine(retval, assemblyInfo.Title); } if (!string.IsNullOrEmpty(assemblyInfo.Version)) { retval = Path.Combine(retval, assemblyInfo.Version); } #if DEBUG retval = Path.Combine(retval, "Debug"); #endif retval = Path.Combine(retval, AppDomain.CurrentDomain.FriendlyName); return(Regex.Replace(retval, @"\.exe\z", ".xml", RegexOptions.IgnoreCase));; }