Skip to content

Commit

Permalink
Get full path for Special Folders names
Browse files Browse the repository at this point in the history
  • Loading branch information
w4po committed Nov 29, 2023
1 parent 31a7b98 commit cb0aa58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ExplorerTabUtility/ExplorerTabUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net7.0-windows;net48</TargetFrameworks>
<TargetFrameworks>net7.0-windows;net481</TargetFrameworks>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<UseWindowsForms>True</UseWindowsForms>
Expand Down
18 changes: 18 additions & 0 deletions ExplorerTabUtility/Helpers/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;

namespace ExplorerTabUtility.Helpers;
Expand Down Expand Up @@ -58,4 +59,21 @@ public static TimeSpan GetElapsedTime(long startTicks)

return Icon.ExtractAssociatedIcon(location);
}

public static string GetFullPath(string path)
{
// Check if the path contains environment variables
if (path.StartsWith("%") && path.EndsWith("%"))
{
// Replace environment variables with their values
path = Environment.ExpandEnvironmentVariables(path);
}

// If it has : or \, assume it's a regular path
if (path.Contains(":") || path.Contains("\\")) return path;

// Check if the path is a special folder
var fullPath = $"{Environment.GetEnvironmentVariable("USERPROFILE")}\\{path}";
return Directory.Exists(fullPath) ? fullPath : path;
}
}
1 change: 1 addition & 0 deletions ExplorerTabUtility/Hooks/UiAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void OnWindowOpened(AutomationElement element, EventId _)
location = addressBar.Patterns.Value.Pattern.Value.Value;
if (string.IsNullOrWhiteSpace(location)) return;
}
location = Helper.GetFullPath(location);

var tab = element.FindFirstChild(c => c.ByClassName("ShellTabWindowClass"));

Expand Down

0 comments on commit cb0aa58

Please sign in to comment.