Skip to content

Commit

Permalink
[Feature] Hide extensions for known file types, see folder options (#83
Browse files Browse the repository at this point in the history
…), version 1.0.17.14
  • Loading branch information
Hofknecht committed Apr 16, 2021
1 parent 85fd037 commit c1beb9f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 30 deletions.
88 changes: 63 additions & 25 deletions Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -117,18 +119,21 @@ internal static void ShowHelpFAQ()
}
}

/// <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)
{
isDarkMode = isDarkModeFromFirstCall;
}
else
if (!readDarkModeDone)
{
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;
}

Expand All @@ -139,26 +144,59 @@ internal static bool IsDarkMode()
}

/// <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()
{
if (!readHideFileExtdone)
{
// 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 isHideFileExtension;
}

private static bool IsRegistryValueThisValue(string keyName, string valueName, string value)
{
// 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")
bool isRegistryValueThisValue = false;

try
{
isDarkModeActive = true;
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 isDarkModeActive;
return isRegistryValueThisValue;
}
}
}
11 changes: 10 additions & 1 deletion DataClasses/RowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ internal void SetData(RowData data, DataTable dataTable)
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;
}

Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
// 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")]
2 changes: 0 additions & 2 deletions UserInterface/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ void Fading_Show()
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;
Expand Down

0 comments on commit c1beb9f

Please sign in to comment.