Skip to content

Commit

Permalink
add variable referencing plugin DLL directory
Browse files Browse the repository at this point in the history
previously some code was implicitly assuming that the OS would treat the current directory
    (the root directory as far as relative paths are concerned)
    as the directory of the Notepad++ executable.
This works fine 99% of the time, but in some cases it stops working
    and then all the code that relies on that assumption stays broken
    until you start a new Notepad++ session.
  • Loading branch information
molsonkiko committed Mar 30, 2024
1 parent 7e8e03e commit 2bf4263
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

1. Fixed issue where clicking buttons on floating docking dialogs could sometimes cause Notepad++ to hang forever (see [CsvLint issue 83](https://github.com/BdR76/CSVLint/issues/83) for a detailed explanation).
2. Fix `SCNotification` byte alignment issue in 64-bit Notepad++ by making `annotationLinesAdded` field an `IntPtr`, which has been the correct type for that field since [between Notepad++ 7.6.6 and 7.7](https://github.com/notepad-plus-plus/notepad-plus-plus/blob/37c4b894cc247d1ee6976bc1a1b66cfed4b7774e/scintilla/include/Scintilla.h#L1227). Note that *this is a potentially breaking change for 64-bit Notepad++ 7.6.6 or older*, but there's a ton of other bit rot for such old Notepad++ anyway.
3. Fix error due to assuming that "." (the current directory according to the filesystem) will always point to the path to the Notepad++ executable; this is *almost always true*, but can be broken due to at least one known weird interaction (the one molsonkiko is familiar with concerns the `New script` functionality of the PythonScript plugin).

## [0.0.3] - 2024-02-26

Expand Down
6 changes: 1 addition & 5 deletions NppCSharpPluginPack/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ static internal void CommandMenuInit()

private static Assembly LoadDependency(object sender, ResolveEventArgs args)
{
// Path.GetFullPath(".") will return the path to the Notepad++ executable
// I have *very rarely* seen it instead return another path, but in general this should work properly.
// Unfortunately Npp.notepad.GetNppPath() cannot be used here for reasons discussed in this comment by rdipardo:
// https://github.com/molsonkiko/NppCSharpPluginPack/issues/5#issuecomment-1982167513
string assemblyFile = Path.Combine(Path.GetFullPath("."), "plugins", PluginName, new AssemblyName(args.Name).Name) + ".dll";
string assemblyFile = Path.Combine(Npp.pluginDllDirectory, new AssemblyName(args.Name).Name) + ".dll";
if (File.Exists(assemblyFile))
return Assembly.LoadFrom(assemblyFile);
return null;
Expand Down
4 changes: 2 additions & 2 deletions NppCSharpPluginPack/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.0.3.3")]
[assembly: AssemblyFileVersion("0.0.3.3")]
[assembly: AssemblyVersion("0.0.3.4")]
[assembly: AssemblyFileVersion("0.0.3.4")]
3 changes: 2 additions & 1 deletion NppCSharpPluginPack/Tests/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using NppDemo.Utils;
using Kbg.NppPluginNET;
using System.IO;

namespace NppDemo.Tests
{
Expand All @@ -21,7 +22,7 @@ public static void RunAll()
string header = $"Test results for {Main.PluginName} v{Npp.AssemblyVersionString()} on Notepad++ {Npp.nppVersionStr}\r\nNOTE: Ctrl-F (regular expressions *on*) for \"Failed [1-9]\\d*\" to find all failed tests";
Npp.AddLine(header);

string big_random_fname = $"plugins\\{Main.PluginName}\\testfiles\\big_silly_example.tsv";
string big_random_fname = Path.Combine(Npp.pluginDllDirectory, "testfiles", "big_silly_example.tsv");
var tests = new (Func<bool> tester, string name, bool onlyIfNpp8Plus)[]
{
(SliceTester.Test, "slice extension", false),
Expand Down
8 changes: 8 additions & 0 deletions NppCSharpPluginPack/Utils/Npp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public class Npp

public static readonly bool nppVersionAtLeast8 = nppVersion[0] >= 8;

/// <summary>
/// the directory containing of the plugin DLL (i.e., the DLL that this code compiles into)<br></br>
/// usually Path.Combine(notepad.GetNppPath(), "plugins", Main.PluginName) would work just as well,<br></br>
/// but under some weird circumstances (see this GitHub issue comment: https://github.com/molsonkiko/NppCSharpPluginPack/issues/5#issuecomment-1982167513)<br></br>
/// it can fail.
/// </summary>
public static readonly string pluginDllDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

/// <summary>
/// append text to current doc, then append newline and move cursor
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions most recent errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Test results for CSharpPluginPack v0.0.3.3 on Notepad++ 8.6.4 64bit
Test results for CSharpPluginPack v0.0.3.4 on Notepad++ 8.6.4 64bit
NOTE: Ctrl-F (regular expressions *on*) for "Failed [1-9]\d*" to find all failed tests
No tests failed
=========================
Expand All @@ -22,7 +22,7 @@ Performance tests for My benchmarks (test1)
=========================

To run query "foo" on file of size 7913 into took 0 +/- 0 ms over 32 trials
Query times (ms): 0.002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Query times (ms): 0.001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Preview of result: Preview of result
=========================
Performance tests for My benchmarks (test2)
Expand Down

0 comments on commit 2bf4263

Please sign in to comment.