mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-16 02:13:39 +12:00
[Feature] Hide extensions for known file types, see folder options (#83), version 1.0.17.14
This commit is contained in:
parent
85fd0371b5
commit
c1beb9ffa9
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue