private bool TryGetSettingsLocationInfoFromEntryAssembly(out string settingsLocation, out string softwareName)
{
settingsLocation = null;
softwareName = null;
var entryAssembly = Assembly.GetEntryAssembly(); // the main exe assembly
if (entryAssembly == null) // Called from unmanaged code?
return false;
softwareName = Path.GetFileNameWithoutExtension(entryAssembly.Location);
AssemblyCompanyAttribute companyAttribute = Attribute.GetCustomAttribute(entryAssembly, typeof(AssemblyCompanyAttribute)) as AssemblyCompanyAttribute;
if (companyAttribute == null || string.IsNullOrEmpty(softwareName))
return false;
string companyName = companyAttribute.Company;
if (companyName == null)
return false;
settingsLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
companyName);
return true;
}