Skip to content

Commit

Permalink
Refactor of legacy check code
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Wennergren committed Feb 18, 2022
1 parent b2de6f1 commit f1634c5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CsvQuery/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static void ParseWithManualSettings()

public static void SetToolBarIcon()
{
if (NotepadPPGateway.GetNppMajorVersion() < 8)
if (LegacyCheck.OldIconCode)
{
// Old way - for backwards compatibility to Npp before 8.0
var icons = new toolbarIcons { hToolbarBmp = Resources.cq.GetHbitmap() };
Expand Down
48 changes: 48 additions & 0 deletions CsvQuery/PluginInfrastructure/GatewayDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,44 @@

namespace CsvQuery.PluginInfrastructure
{
public static class LegacyCheck
{
private static int _version = -1;
private static int _majorVersion = -1;
private static int _minorVersion = -1;


private static void Init()
{
int Unused = 0;
_version = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNPPVERSION, Unused, Unused).ToInt32();
_majorVersion = _version >> 16;

// Minor version is stored really strange in Npp, e.g. 8.1 has lower bits = 1, but 8.1.9.3 has lower bits = 193
var minorBits = _version & 0xffff;
var firstDigit = minorBits.ToString().Substring(0,1);
if (!int.TryParse(firstDigit, out _version)) _minorVersion = -1;
}

public static bool OldIconCode
{
get
{
if(_version==-1)Init();
return _majorVersion < 8;
}
}

public static bool Old64BitScintilla
{
get
{
if (_version == -1) Init();
return (_majorVersion < 8) || (_majorVersion == 8 && _minorVersion < 3);
}
}
}

/// <summary>
/// Colours are set using the RGB format (Red, Green, Blue). The intensity of each colour is set in the range 0 to 255.
/// If you have three such intensities, they are combined as: red | (green &lt;&lt; 8) | (blue &lt;&lt; 16).
Expand Down Expand Up @@ -180,6 +218,16 @@ public struct CharacterRange
public IntPtr cpMax;
}

/// <summary>
/// This is used before N++ 8.3
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct CharacterRangeLegacy
{
public int cpMin;
public int cpMax;
}

public class Cells
{
public Cells(char[] charactersAndStyles)
Expand Down

0 comments on commit f1634c5

Please sign in to comment.