Skip to content

Commit f1634c5

Browse files
author
Joakim Wennergren
committed
Refactor of legacy check code
1 parent b2de6f1 commit f1634c5

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

CsvQuery/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static void ParseWithManualSettings()
155155

156156
public static void SetToolBarIcon()
157157
{
158-
if (NotepadPPGateway.GetNppMajorVersion() < 8)
158+
if (LegacyCheck.OldIconCode)
159159
{
160160
// Old way - for backwards compatibility to Npp before 8.0
161161
var icons = new toolbarIcons { hToolbarBmp = Resources.cq.GetHbitmap() };

CsvQuery/PluginInfrastructure/GatewayDomain.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@
66

77
namespace CsvQuery.PluginInfrastructure
88
{
9+
public static class LegacyCheck
10+
{
11+
private static int _version = -1;
12+
private static int _majorVersion = -1;
13+
private static int _minorVersion = -1;
14+
15+
16+
private static void Init()
17+
{
18+
int Unused = 0;
19+
_version = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNPPVERSION, Unused, Unused).ToInt32();
20+
_majorVersion = _version >> 16;
21+
22+
// 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
23+
var minorBits = _version & 0xffff;
24+
var firstDigit = minorBits.ToString().Substring(0,1);
25+
if (!int.TryParse(firstDigit, out _version)) _minorVersion = -1;
26+
}
27+
28+
public static bool OldIconCode
29+
{
30+
get
31+
{
32+
if(_version==-1)Init();
33+
return _majorVersion < 8;
34+
}
35+
}
36+
37+
public static bool Old64BitScintilla
38+
{
39+
get
40+
{
41+
if (_version == -1) Init();
42+
return (_majorVersion < 8) || (_majorVersion == 8 && _minorVersion < 3);
43+
}
44+
}
45+
}
46+
947
/// <summary>
1048
/// Colours are set using the RGB format (Red, Green, Blue). The intensity of each colour is set in the range 0 to 255.
1149
/// If you have three such intensities, they are combined as: red | (green &lt;&lt; 8) | (blue &lt;&lt; 16).
@@ -180,6 +218,16 @@ public struct CharacterRange
180218
public IntPtr cpMax;
181219
}
182220

221+
/// <summary>
222+
/// This is used before N++ 8.3
223+
/// </summary>
224+
[StructLayout(LayoutKind.Sequential)]
225+
public struct CharacterRangeLegacy
226+
{
227+
public int cpMin;
228+
public int cpMax;
229+
}
230+
183231
public class Cells
184232
{
185233
public Cells(char[] charactersAndStyles)

0 commit comments

Comments
 (0)