Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin release v0.7.2 searches help files in wrong directory #76

Closed
dinkumoil opened this issue Feb 11, 2023 · 7 comments
Closed

Plugin release v0.7.2 searches help files in wrong directory #76

dinkumoil opened this issue Feb 11, 2023 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@dinkumoil
Copy link

Description

Release v0.7.2 of the plugin searches help files in folder <Npp-folder>\plugins\MarkdownPanel instead of <Npp-folder>\plugins\NppMarkdownPanel.

Steps to Reproduce

  1. Navigate to (menu) Plugins -> MarkdownPanel and click on menu item Help.
  2. A message box with an error message appears:

grafik

  1. Afte creating folder <Npp-folder>\plugins\MarkdownPanel and moving folder help and file README.md from folder <Npp-folder>\plugins\NppMarkdownPanel to the new folder, help file is shown in Notepad++
@rdipardo
Copy link
Contributor

The installation folder depends on the JSON manifest bundled with Plugins Admin, so this issue really belongs here.

The help file path is built from the PluginName field; it's always in sync with the compiled assembly:

var helpFile = Path.Combine($"{sbPluginPath}", Main.PluginName, "README.md");

@dinkumoil
Copy link
Author

dinkumoil commented Feb 12, 2023

@rdipardo

this issue really belongs here.

I don't agree. The plugin's DLL name is NppMarkdownPanel.dll, thus the folder it is stored into must be <Npp-folder>\plugins\NppMarkdownPanel. This should also be the folder where plugin's companion files and folders are stored. It seems like function Main.PluginName returns the string MarkdownPanel instead of NppMarkdownPanel, so the plugin searches its help files in the wrong folder.

I guess the bug derives from recent renaming of the plugin's menu entry from NppMarkdownPanel to MarkdownPanel in commit 9872e9f. When installing a plugin, PluginAdmin generates the target folder name from the name of the DLL file it finds at the root level of the plugin's ZIP package, not from the return value of plugin interface's function getName, simply because the plugin is not (and can not be) loaded during its installation, so this function cannot be called.

@rdipardo
Copy link
Contributor

The plugin's DLL name is NppMarkdownPanel.dll

I stand corrected. It seems that 9872e9f just changed the value of an internal class member. To really keep the help file path in sync, you would have to extract the directory name from the assembly's binary file information; something like this:

diff --git a/NppMarkdownPanel/MarkdownPanelController.cs b/NppMarkdownPanel/MarkdownPanelController.cs
index 5e37268..57c600f 100644
--- a/NppMarkdownPanel/MarkdownPanelController.cs
+++ b/NppMarkdownPanel/MarkdownPanelController.cs
@@ -8,6 +8,7 @@ using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
 using System.Runtime.InteropServices;
+using System.Diagnostics;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
@@ -209,9 +210,12 @@ namespace NppMarkdownPanel

         private void ShowHelp()
         {
+            var dll = (typeof(Main)).Assembly;
+            var dllVersionInfo = FileVersionInfo.GetVersionInfo(dll.Location);
+            string dllDir = Path.GetFileNameWithoutExtension(dllVersionInfo.OriginalFilename);
             StringBuilder sbPluginPath = new StringBuilder(Win32.MAX_PATH);
             Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETPLUGINHOMEPATH, Win32.MAX_PATH, sbPluginPath);
-            var helpFile = Path.Combine($"{sbPluginPath}", Main.PluginName, "README.md");
+            var helpFile = Path.Combine($"{sbPluginPath}", dllDir, "README.md");
             Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DOOPEN, 0, helpFile);
             if (!isPanelVisible)
                 TogglePanelVisible();

@mohzy83 mohzy83 added the bug Something isn't working label Feb 12, 2023
@mohzy83
Copy link
Owner

mohzy83 commented Feb 12, 2023

Like @rdipardo said, the const Main.PluginName is used to construct the path to the help file.
It's much safer to use the directory of the executing assembly and dont rely on that constant.
I will change the implementation accordingly.

@mohzy83
Copy link
Owner

mohzy83 commented Feb 19, 2023

fixed in version 0.7.3. @dinkumoil please verify. Thanks.

@rdipardo
Copy link
Contributor

It works.

nppMrkdPnl-2023-02-19-152121

@dinkumoil
Copy link
Author

It works.

Confirmed.

@mohzy83 mohzy83 closed this as completed Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants