[Feature] Hide extensions for known file types, see folder options (#83), version 1.0.17.14

This commit is contained in:
Markus Hofknecht 2021-04-16 21:30:45 +02:00
parent 85fd0371b5
commit c1beb9ffa9
4 changed files with 75 additions and 30 deletions

View file

@ -15,10 +15,12 @@ namespace SystemTrayMenu
public static class Config
{
public const string Language = "en";
private static bool readDarkModeDone = false;
private static bool isDarkModeFromFirstCall = false;
private static bool isDarkMode = false;
private static bool readHideFileExtdone = false;
private static bool isHideFileExtension = false;
public static bool IsHideFileExtdone => IsHideFileExtension();
public static string Path => Properties.Settings.Default.PathDirectory;
@ -117,18 +119,21 @@ namespace SystemTrayMenu
}
}
/// <summary>
/// Read the OS setting whether dark mode is enabled.
/// </summary>
/// <returns>true = Dark mode; false = Light mode.</returns>
internal static bool IsDarkMode()
{
bool isDarkMode = false;
if (readDarkModeDone)
if (!readDarkModeDone)
{
isDarkMode = isDarkModeFromFirstCall;
}
else
{
if (Properties.Settings.Default.IsDarkModeAlwaysOn || IsDarkModeActive())
// 0 = Dark mode, 1 = Light mode
if (Properties.Settings.Default.IsDarkModeAlwaysOn ||
IsRegistryValueThisValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
"AppsUseLightTheme",
"0"))
{
isDarkModeFromFirstCall = true;
isDarkMode = true;
}
@ -139,26 +144,59 @@ namespace SystemTrayMenu
}
/// <summary>
/// Read the OS setting whether dark mode is enabled.
/// Read the OS setting whether HideFileExt enabled.
/// </summary>
/// <returns>true = Dark mode; false = Light mode.</returns>
private static bool IsDarkModeActive()
internal static bool IsHideFileExtension()
{
// Check: AppsUseLightTheme (REG_DWORD)
bool isDarkModeActive = false;
object registryValueAppsUseLightTheme = Registry.GetValue(
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
"AppsUseLightTheme",
1);
// 0 = Dark mode, 1 = Light mode
if (registryValueAppsUseLightTheme != null &&
registryValueAppsUseLightTheme.ToString() == "0")
if (!readHideFileExtdone)
{
isDarkModeActive = true;
// 0 = To show extensions, 1 = To hide extensions
if (IsRegistryValueThisValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced",
"HideFileExt",
"1"))
{
isHideFileExtension = true;
}
readHideFileExtdone = true;
}
return isDarkModeActive;
return isHideFileExtension;
}
private static bool IsRegistryValueThisValue(string keyName, string valueName, string value)
{
bool isRegistryValueThisValue = false;
try
{
object registryHideFileExt = Registry.GetValue(keyName, valueName, 1);
if (registryHideFileExt == null)
{
Log.Info($"Could not read registry keyName:{keyName} valueName:{valueName}");
}
else if (registryHideFileExt.ToString() == value)
{
isRegistryValueThisValue = true;
}
}
catch (Exception ex)
{
if (ex is System.Security.SecurityException ||
ex is IOException)
{
Log.Warn($"Could not read registry keyName:{keyName} valueName:{valueName}", ex);
}
else
{
throw;
}
}
return isRegistryValueThisValue;
}
}
}

View file

@ -90,7 +90,16 @@ namespace SystemTrayMenu.DataClasses
row[0] = data.icon;
}
row[1] = data.text;
if (!ContainsMenu &&
Config.IsHideFileExtension())
{
row[1] = Path.GetFileNameWithoutExtension(data.text);
}
else
{
row[1] = data.text;
}
row[2] = data;
}

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.17.13")]
[assembly: AssemblyFileVersion("1.0.17.13")]
[assembly: AssemblyVersion("1.0.17.14")]
[assembly: AssemblyFileVersion("1.0.17.14")]

View file

@ -43,9 +43,7 @@ namespace SystemTrayMenu.UserInterface
Visible = true;
isShowing = false;
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (ObjectDisposedException)
#pragma warning restore CA1031 // Do not catch general exception types
{
Visible = false;
isShowing = false;