Skip to content

Commit

Permalink
[PT Run] Localized file paths (Part 1): Update helper class and Progr…
Browse files Browse the repository at this point in the history
…am plugin (microsoft#20024)

* make helper non-static and add cache

* uwp app: add localized path

* Win32Program: Rename variable

* spell fix

* Win32Program: Localized paths

* fix invalid var name

* spell fix

* fix build

* test new shell localization helper

* fixes

* fix crash

* replace old helper class

* replace old helper class 2

* Helper improvements

* last changes

* add docs info

* remove left-over

* remove second left-over
  • Loading branch information
htcfreek authored Feb 13, 2023
1 parent 4c3b470 commit 6e4a289
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 93 deletions.
1 change: 1 addition & 0 deletions doc/devdocs/modules/launcher/plugins/program.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ There are broadly two different categories of applications:

### Additional Notes
- Arguments can be provided to the program plugin by entering them after `--` (a double dash).
- The localization is done using the `Localization Helper`from `Wox.Plugin.Common` hosted at runtime in a variable of plugin's main class.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Win32Tests
Name = "Imaging Devices",
ExecutableName = "imagingdevices.exe",
FullPath = "c:\\program files\\windows photo viewer\\imagingdevices.exe",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -31,7 +31,7 @@ public class Win32Tests
Name = "Notepad",
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
LnkFilePath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -40,7 +40,7 @@ public class Win32Tests
Name = "Notepad",
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -50,7 +50,7 @@ public class Win32Tests
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
Arguments = @"/E:ON /V:ON /K ""C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\\bin\setenv.cmd""",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -60,7 +60,7 @@ public class Win32Tests
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
Arguments = @"/k ""C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat""",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -69,7 +69,7 @@ public class Win32Tests
Name = "Command Prompt",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk",
LnkFilePath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -78,7 +78,7 @@ public class Win32Tests
Name = "File Explorer",
ExecutableName = "File Explorer.lnk",
FullPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\file explorer.lnk",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -87,7 +87,7 @@ public class Win32Tests
Name = "File Explorer",
ExecutableName = "explorer.exe",
FullPath = "c:\\windows\\explorer.exe",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -96,7 +96,7 @@ public class Win32Tests
Name = "Wordpad",
ExecutableName = "wordpad.exe",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -105,15 +105,15 @@ public class Win32Tests
Name = "WORDPAD",
ExecutableName = "WORDPAD.EXE",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.Win32Application,
};

private static readonly Win32Program _twitterChromePwa = new Win32Program
{
Name = "Twitter",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk",
LnkFilePath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk",
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi",
AppType = 0,
};
Expand All @@ -122,7 +122,7 @@ public class Win32Tests
{
Name = "Web page",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk",
LnkFilePath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk",
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd",
AppType = 0,
};
Expand All @@ -131,7 +131,7 @@ public class Win32Tests
{
Name = "edge - Bing",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk",
LnkFilePath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk",
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd",
AppType = 0,
};
Expand All @@ -141,7 +141,7 @@ public class Win32Tests
Name = "Microsoft Edge",
ExecutableName = "msedge.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -150,7 +150,7 @@ public class Win32Tests
Name = "Google Chrome",
ExecutableName = "chrome.exe",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -159,7 +159,7 @@ public class Win32Tests
Name = "Proxy App",
ExecutableName = "test_proxy.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\test_proxy.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk",
LnkFilePath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk",
AppType = Win32Program.ApplicationType.Win32Application,
};

Expand All @@ -168,7 +168,7 @@ public class Win32Tests
Name = "cmd",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.RunCommand, // Run command
};

Expand All @@ -178,7 +178,7 @@ public class Win32Tests
Description = "Cmder: Lovely Console Emulator",
ExecutableName = "Cmder.exe",
FullPath = "c:\\tools\\cmder\\cmder.exe",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.RunCommand, // Run command
};

Expand All @@ -188,7 +188,7 @@ public class Win32Tests
ExecutableName = "Shop Titans.url",
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.InternetShortcutApplication,
};

Expand All @@ -198,7 +198,7 @@ public class Win32Tests
ExecutableName = "Shop Titans.url",
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\Desktop",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.InternetShortcutApplication,
};

Expand All @@ -208,7 +208,7 @@ public class Win32Tests
ExecutableName = "dummy.appref-ms",
FullPath = "C:\\dummy.appref-ms",
ParentDirectory = "C:\\",
LnkResolvedPath = null,
LnkFilePath = null,
AppType = Win32Program.ApplicationType.ApprefApplication,
};

Expand All @@ -218,7 +218,7 @@ public class Win32Tests
ExecutableName = "application.lnk",
FullPath = "C:\\application.lnk",
ParentDirectory = "C:\\",
LnkResolvedPath = "C:\\application.lnk",
LnkFilePath = "C:\\application.lnk",
AppType = Win32Program.ApplicationType.ShortcutApplication,
};

Expand All @@ -228,7 +228,7 @@ public class Win32Tests
ExecutableName = "application.lnk",
FullPath = "C:\\dummy\\folder",
ParentDirectory = "C:\\dummy\\",
LnkResolvedPath = "C:\\tools\\application.lnk",
LnkFilePath = "C:\\tools\\application.lnk",
AppType = Win32Program.ApplicationType.Folder,
};

Expand All @@ -238,7 +238,7 @@ public class Win32Tests
ExecutableName = "application.lnk",
FullPath = "C:\\dummy\\file.pdf",
ParentDirectory = "C:\\dummy\\",
LnkResolvedPath = "C:\\tools\\application.lnk",
LnkFilePath = "C:\\tools\\application.lnk",
AppType = Win32Program.ApplicationType.GenericFile,
};

Expand Down Expand Up @@ -303,7 +303,7 @@ public void DedupFunctionWhenCalledMustNotRemovelnkWhichDoesNotHaveExe()
}

[TestMethod]
public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkResolvedPath()
public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkFilePath()
{
// Arrange
List<Win32Program> prgms = new List<Win32Program>
Expand All @@ -317,7 +317,7 @@ public void DedupFunctionMustRemoveDuplicatesForExeExtensionsWithoutLnkResolvedP

// Assert
Assert.AreEqual(1, apps.Count);
Assert.IsTrue(!string.IsNullOrEmpty(apps[0].LnkResolvedPath));
Assert.IsTrue(!string.IsNullOrEmpty(apps[0].LnkFilePath));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void Win32ProgramRepositoryMustCallOnAppDeletedForLnkAppsWhenDeletedEvent
ExecutableName = "path.exe",
ParentDirectory = "directory",
FullPath = "directory\\path.exe",
LnkResolvedPath = "directory\\path.lnk", // This must be equal for lnk applications
LnkFilePath = "directory\\path.lnk", // This must be equal for lnk applications
};
win32ProgramRepository.Add(item);

Expand Down
3 changes: 3 additions & 0 deletions src/modules/launcher/Plugins/Microsoft.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Plugin.Program.Storage;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Wox.Plugin.Common;
using Stopwatch = Wox.Infrastructure.Stopwatch;

namespace Microsoft.Plugin.Program
Expand All @@ -30,6 +31,8 @@ public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IDisposable

internal static ProgramPluginSettings Settings { get; set; }

internal static readonly ShellLocalization ShellLocalizationHelper = new();

public string Name => Properties.Resources.wox_plugin_program_plugin_name;

public string Description => Properties.Resources.wox_plugin_program_plugin_description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public partial class UWP

public string Location { get; set; }

// Localized path based on windows display language
public string LocationLocalized { get; set; }

public IList<UWPApplication> Apps { get; private set; }

public PackageVersion Version { get; set; }
Expand All @@ -57,6 +60,7 @@ public UWP(IPackage package)
public void InitializeAppInfo(string installedLocation)
{
Location = installedLocation;
LocationLocalized = Main.ShellLocalizationHelper.GetLocalizedPath(installedLocation);
var path = Path.Combine(installedLocation, "AppxManifest.xml");

var namespaces = XmlNamespaces(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class UWPApplication : IProgram

public string Location => Package.Location;

// Localized path based on windows display language
public string LocationLocalized => Package.LocationLocalized;

public bool Enabled { get; set; }

public bool CanRunElevated { get; set; }
Expand Down Expand Up @@ -119,7 +122,7 @@ public Result Result(string query, string queryArguments, IPublicAPI api)

// Using CurrentCulture since this is user facing
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_path, Package.Location);
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_path, LocationLocalized);
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);

return result;
Expand Down
Loading

0 comments on commit 6e4a289

Please sign in to comment.