Integrer new Windows 11 Explorer Context Menu Entry "Edit with Notepad++"
This commit is contained in:
parent
9462238c0f
commit
5645ca150b
|
@ -111,6 +111,7 @@ InstType "Minimalist"
|
|||
Var diffArchDir2Remove
|
||||
Var noUpdater
|
||||
|
||||
|
||||
!ifdef ARCH64 || ARCHARM64
|
||||
; this is needed for the 64-bit InstallDirRegKey patch
|
||||
!include "StrFunc.nsh"
|
||||
|
@ -126,7 +127,7 @@ Function .onInit
|
|||
; so the InstallDirRegKey checks for the irrelevant HKLM\SOFTWARE\WOW6432Node\Notepad++, explanation:
|
||||
; https://nsis.sourceforge.io/Reference/SetRegView
|
||||
;
|
||||
!ifdef ARCH64 || ARCHARM64
|
||||
!ifdef ARCH64 || ARCHARM64
|
||||
${If} ${RunningX64}
|
||||
System::Call kernel32::GetCommandLine()t.r0 ; get the original cmdline (where a possible "/D=..." is not hidden from us by NSIS)
|
||||
${StrStr} $1 $0 "/D="
|
||||
|
@ -265,55 +266,54 @@ FunctionEnd
|
|||
${Using:StrFunc} StrStr
|
||||
|
||||
Var muiVerbStr
|
||||
Var nppSubStrRes
|
||||
Var editWithNppLocalStr
|
||||
Var nppSubStr
|
||||
|
||||
${MementoSection} "Context Menu Entry" explorerContextMenu
|
||||
|
||||
${If} $WinVer == "11"
|
||||
|
||||
; Clean up the hack of v8.5 installer
|
||||
ReadRegStr $muiVerbStr HKLM "SOFTWARE\Classes\*\shell\pintohome" MUIVerb
|
||||
|
||||
${StrStr} $nppSubStrRes $muiVerbStr "Notepad++"
|
||||
;MessageBox MB_OK "entry value: $muiVerbStr"
|
||||
;MessageBox MB_OK "result: $nppSubStrRes"
|
||||
|
||||
; Make sure there's no entry before creating it, so we won't override other application if present
|
||||
${If} $muiVerbStr == ""
|
||||
${OrIf} $nppSubStrRes != "" ; it contains "Notepad++"
|
||||
|
||||
ReadINIStr $editWithNppLocalStr "$PLUGINSDIR\nppLocalization\explorerContextMenuEntryLocal.ini" $(langFileName) "Edit_with_Notepad++"
|
||||
${If} $editWithNppLocalStr == ""
|
||||
StrCpy $editWithNppLocalStr "Edit with Notepad++"
|
||||
MessageBox MB_OK "translation: $editWithNppLocalStr"
|
||||
${EndIf}
|
||||
|
||||
WriteRegStr HKLM "SOFTWARE\Classes\*\shell\pintohome" 'MUIVerb' $editWithNppLocalStr
|
||||
WriteRegStr HKLM "SOFTWARE\Classes\*\shell\pintohome\command" "" '"$INSTDIR\notepad++.exe" "%1"'
|
||||
|
||||
${StrStr} $nppSubStr $muiVerbStr "Notepad++"
|
||||
; Make sure there's an entry, and the entry belong to Notepad++ before deleting it
|
||||
${If} $muiVerbStr != ""
|
||||
${AndIf} $nppSubStr != "" ; it contains "Notepad++"
|
||||
DeleteRegKey HKLM "SOFTWARE\Classes\*\shell\pintohome"
|
||||
${EndIf}
|
||||
|
||||
; Install the new Windows 11 "Edit with Notepad++" menu entry
|
||||
!ifdef ARCHARM64
|
||||
File /oname=$INSTDIR\NppModernShell.msix "..\binarm64\NppModernShell.msix"
|
||||
File /oname=$INSTDIR\NppModernShell.dll "..\binarm64\NppModernShell.dll"
|
||||
!else ; !ifdef ARCH64
|
||||
File /oname=$INSTDIR\NppModernShell.msix "..\bin64\NppModernShell.msix"
|
||||
File /oname=$INSTDIR\NppModernShell.dll "..\bin64\NppModernShell.dll"
|
||||
!endif
|
||||
Exec 'rundll32.exe"$INSTDIR\NppModernShell.dll,RegisterSparsePackage"'
|
||||
|
||||
${Else} ; the old "Edit with Notepad++" menu entry still works under Windows 10 and previous OS
|
||||
|
||||
SetOverwrite try
|
||||
SetOutPath "$INSTDIR\"
|
||||
|
||||
; There is no need to keep x86 NppShell_06.dll in 64 bit installer
|
||||
; But in 32bit installer both the Dlls are required
|
||||
; As user can install 32bit npp version on x64 bit machine, that time x64 bit NppShell is required.
|
||||
|
||||
!ifdef ARCH64
|
||||
File /oname=$INSTDIR\NppShell_06.dll "..\bin\NppShell64_06.dll"
|
||||
!else ifdef ARCHARM64
|
||||
File /oname=$INSTDIR\NppShell_06.dll "..\binarm64\NppShell64.dll"
|
||||
!else
|
||||
${If} ${RunningX64}
|
||||
File /oname=$INSTDIR\NppShell_06.dll "..\bin\NppShell64_06.dll"
|
||||
${Else}
|
||||
File "..\bin\NppShell_06.dll"
|
||||
${EndIf}
|
||||
!endif
|
||||
Exec 'regsvr32 /s "$INSTDIR\NppShell_06.dll"'
|
||||
|
||||
${EndIf}
|
||||
|
||||
SetOverwrite try
|
||||
SetOutPath "$INSTDIR\"
|
||||
|
||||
; There is no need to keep x86 NppShell_06.dll in 64 bit installer
|
||||
; But in 32bit installer both the Dlls are required
|
||||
; As user can install 32bit npp version on x64 bit machine, that time x64 bit NppShell is required.
|
||||
|
||||
!ifdef ARCH64
|
||||
File /oname=$INSTDIR\NppShell_06.dll "..\bin\NppShell64_06.dll"
|
||||
!else ifdef ARCHARM64
|
||||
File /oname=$INSTDIR\NppShell_06.dll "..\binarm64\NppShell64.dll"
|
||||
!else
|
||||
${If} ${RunningX64}
|
||||
File /oname=$INSTDIR\NppShell_06.dll "..\bin\NppShell64_06.dll"
|
||||
${Else}
|
||||
File "..\bin\NppShell_06.dll"
|
||||
${EndIf}
|
||||
!endif
|
||||
Exec 'regsvr32 /s "$INSTDIR\NppShell_06.dll"'
|
||||
|
||||
|
||||
${MementoSectionEnd}
|
||||
|
||||
|
|
|
@ -183,17 +183,17 @@ SectionGroup "Function List Files" functionListComponent
|
|||
File ".\functionList\typescript.xml"
|
||||
${MementoSectionEnd}
|
||||
|
||||
${MementoSection} "Pascal" Pascal
|
||||
${MementoSection} "Pascal" Pascal_FL
|
||||
SetOutPath "$INSTDIR\functionList"
|
||||
File ".\functionList\pascal.xml"
|
||||
${MementoSectionEnd}
|
||||
|
||||
${MementoSection} "GDScript" GDScript
|
||||
|
||||
${MementoSection} "GDScript" GDScript_FL
|
||||
SetOutPath "$INSTDIR\functionList"
|
||||
File ".\functionList\gdscript.xml"
|
||||
${MementoSectionEnd}
|
||||
|
||||
${MementoSection} "NppExecScript" NppExecScript
|
||||
${MementoSection} "NppExecScript" NppExecScript_FL
|
||||
SetOutPath "$INSTDIR\functionList"
|
||||
File ".\functionList\nppexec.xml"
|
||||
${MementoSectionEnd}
|
||||
|
@ -344,15 +344,15 @@ SectionGroup un.functionListComponent
|
|||
Delete "$INSTDIR\functionList\typescript.xml"
|
||||
SectionEnd
|
||||
|
||||
Section un.Pascal
|
||||
Section un.Pascal_FL
|
||||
Delete "$INSTDIR\functionList\pascal.xml"
|
||||
SectionEnd
|
||||
|
||||
Section un.GDScript
|
||||
Section un.GDScript_FL
|
||||
Delete "$INSTDIR\functionList\gdscript.xml"
|
||||
SectionEnd
|
||||
|
||||
Section un.NppExecScript
|
||||
Section un.NppExecScript_FL
|
||||
Delete "$INSTDIR\functionList\nppexec.xml"
|
||||
SectionEnd
|
||||
|
||||
|
|
|
@ -19,60 +19,76 @@ echo on
|
|||
|
||||
if %SIGN% == 0 goto NoSign
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\notepad++.exe
|
||||
set signtoolWin11="C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\signtool.exe"
|
||||
set signtoolWin10="C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe"
|
||||
|
||||
set signBinary=%signtoolWin11% sign /fd SHA256 /tr http://timestamp.digicert.com /td sha256 /a /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/
|
||||
|
||||
set signArmBinary=%signtoolWin10% sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/
|
||||
|
||||
%signBinary% ..\bin\notepad++.exe
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\notepad++.exe
|
||||
%signBinary% ..\bin64\notepad++.exe
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\notepad++.exe
|
||||
%signArmBinary% ..\binarm64\notepad++.exe
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\NppShell_06.dll
|
||||
%signBinary% ..\bin\NppShell_06.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\NppShell64_06.dll
|
||||
%signBinary% ..\bin\NppShell64_06.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\NppShell64.dll
|
||||
%signArmBinary% ..\binarm64\NppShell64.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\plugins\Config\nppPluginList.dll
|
||||
%signBinary% ..\bin64\NppModernShell.msix
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\plugins\Config\nppPluginList.dll
|
||||
%signBinary% ..\bin64\NppModernShell.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\plugins\Config\nppPluginList.dll
|
||||
%signBinary% ..\binarm64\NppModernShell.msix
|
||||
If ErrorLevel 1 goto End
|
||||
%signArmBinary% ..\binarm64\NppModernShell.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\updater\GUP.exe
|
||||
%signBinary% ..\bin\plugins\Config\nppPluginList.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\updater\GUP.exe
|
||||
%signBinary% ..\bin64\plugins\Config\nppPluginList.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\updater\GUP.exe
|
||||
%signArmBinary% ..\binarm64\plugins\Config\nppPluginList.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\updater\libcurl.dll
|
||||
%signBinary% ..\bin\updater\GUP.exe
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\updater\libcurl.dll
|
||||
%signBinary% ..\bin64\updater\GUP.exe
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\updater\libcurl.dll
|
||||
%signArmBinary% ..\binarm64\updater\GUP.exe
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\plugins\NppExport\NppExport.dll
|
||||
%signBinary% ..\bin\updater\libcurl.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\plugins\NppExport\NppExport.dll
|
||||
%signBinary% ..\bin64\updater\libcurl.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\plugins\NppExport\NppExport.dll
|
||||
%signArmBinary% ..\binarm64\updater\libcurl.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\plugins\mimeTools\mimeTools.dll
|
||||
%signBinary% ..\bin\plugins\NppExport\NppExport.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\plugins\mimeTools\mimeTools.dll
|
||||
%signBinary% ..\bin64\plugins\NppExport\NppExport.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\plugins\mimeTools\mimeTools.dll
|
||||
%signArmBinary% ..\binarm64\plugins\NppExport\NppExport.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\plugins\NppConverter\NppConverter.dll
|
||||
%signBinary% ..\bin\plugins\mimeTools\mimeTools.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\plugins\NppConverter\NppConverter.dll
|
||||
%signBinary% ..\bin64\plugins\mimeTools\mimeTools.dll
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\binarm64\plugins\NppConverter\NppConverter.dll
|
||||
%signArmBinary% ..\binarm64\plugins\mimeTools\mimeTools.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
%signBinary% ..\bin\plugins\NppConverter\NppConverter.dll
|
||||
If ErrorLevel 1 goto End
|
||||
%signBinary% ..\bin64\plugins\NppConverter\NppConverter.dll
|
||||
If ErrorLevel 1 goto End
|
||||
%signArmBinary% ..\binarm64\plugins\NppConverter\NppConverter.dll
|
||||
If ErrorLevel 1 goto End
|
||||
|
||||
:NoSign
|
||||
|
@ -532,11 +548,11 @@ ren npp.portable.minimalist.x64.7z !7zvarMin64!
|
|||
ren npp.portable.minimalist.arm64.7z !7zvarMinArm64!
|
||||
|
||||
if %SIGN% == 0 goto NoSignInstaller
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++ Installer" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ !nppInstallerVar!
|
||||
%signBinary% !nppInstallerVar!
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++ Installer" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ !nppInstallerVar64!
|
||||
%signBinary% !nppInstallerVar64!
|
||||
If ErrorLevel 1 goto End
|
||||
signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++ Installer" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ !nppInstallerVarArm64!
|
||||
%signArmBinary% !nppInstallerVarArm64!
|
||||
If ErrorLevel 1 goto End
|
||||
:NoSignInstaller
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
type="win32"
|
||||
/>
|
||||
<msix xmlns="urn:schemas-microsoft-com:msix.v1"
|
||||
publisher="CN=Notepad++, O=Notepad++, L=Saint Cloud, S=Ile-de-France, C=FR"
|
||||
publisher="CN=Notepad++"
|
||||
packageName="NotepadPlusPlus"
|
||||
applicationId="NotepadPlusPlus"
|
||||
/>
|
||||
|
|
|
@ -89,6 +89,9 @@
|
|||
<AdditionalDependencies>shlwapi.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>source.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>makeappx pack /d .\Packaging /p $(OutDir)NppModernShell.msix /nv</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<ClCompile>
|
||||
|
@ -109,6 +112,9 @@
|
|||
<AdditionalDependencies>shlwapi.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>source.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>makeappx pack /d .\Packaging /p $(OutDir)NppModernShell.msix /nv</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
|
@ -133,6 +139,9 @@
|
|||
<AdditionalDependencies>shlwapi.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>source.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>makeappx pack /d .\Packaging /p $(OutDir)NppModernShell.msix /nv</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<ClCompile>
|
||||
|
@ -157,6 +166,9 @@
|
|||
<AdditionalDependencies>shlwapi.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>source.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>makeappx pack /d .\Packaging /p $(OutDir)NppModernShell.msix /nv</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="EditWithNppExplorerCommandHandler.h" />
|
||||
|
|
|
@ -1,193 +0,0 @@
|
|||
// This file is part of Notepad++ project
|
||||
// Copyright (C)2021 Don HO <don.h@free.fr>
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// at your option any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "tinyxml.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct xmlname{
|
||||
TiXmlElement * node;
|
||||
const char * name;
|
||||
xmlname(TiXmlElement * n, const char * na) { node = n; name = na;}
|
||||
};
|
||||
|
||||
//true if x1 smaller
|
||||
bool sortXMLCase(const xmlname & x1, const xmlname & x2) {
|
||||
return (strcmp(x1.name, x2.name) < 0);
|
||||
}
|
||||
|
||||
inline bool lower(char c) {
|
||||
return (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
inline bool match(char c1, char c2) {
|
||||
if (c1 == c2) return true;
|
||||
if (lower(c1))
|
||||
return ((c1-32) == c2);
|
||||
if (lower(c2))
|
||||
return ((c2-32) == c1);
|
||||
return false;
|
||||
}
|
||||
|
||||
//true if x1 smaller
|
||||
bool sortXML(const xmlname & x1, const xmlname & x2) {
|
||||
|
||||
const char * n1 = x1.name, * n2 = x2.name;
|
||||
int i = 0;
|
||||
while(match(n2[i], n1[i])) {
|
||||
if (n1[i] == 0) {
|
||||
return true; //equal
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
int subs1 = lower(n1[i])?32:0;
|
||||
int subs2 = lower(n2[i])?32:0;
|
||||
|
||||
return ( (n1[i]-subs1) < (n2[i]-subs2) );
|
||||
|
||||
}
|
||||
|
||||
void merge(TiXmlElement * n1, TiXmlElement * n2);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char * file = NULL;
|
||||
|
||||
if (argc < 2) {
|
||||
cout << "Usage: sorter.exe xmlfile.xml" << endl;
|
||||
return 1;
|
||||
}
|
||||
file = argv[1];
|
||||
|
||||
TiXmlDocument *pXmlApi = NULL;
|
||||
pXmlApi = new TiXmlDocument(file);
|
||||
bool loadOkay = pXmlApi->LoadFile();
|
||||
if (!loadOkay) return 1;
|
||||
|
||||
TiXmlNode *root = pXmlApi->FirstChild("NotepadPlus");
|
||||
if (!root) {
|
||||
cout << "NotepadPlus node not found\n";
|
||||
return 1;
|
||||
}
|
||||
TiXmlElement *autoc = root->FirstChildElement("AutoComplete");
|
||||
if (!autoc) {
|
||||
cout << "AutoComplete node not found\n";
|
||||
return 1;
|
||||
}
|
||||
const char * langName = autoc->Attribute("language");
|
||||
|
||||
TiXmlElement *envNode = autoc->FirstChildElement("Environment");
|
||||
bool ignoreCase = false;
|
||||
if (envNode) {
|
||||
cout << "Found environment settings\n";
|
||||
const char * ignoreCaseText = envNode->Attribute("ignoreCase");
|
||||
if (ignoreCaseText) {
|
||||
ignoreCase = (strcmp(ignoreCaseText, "yes") == 0);
|
||||
if (ignoreCase) {
|
||||
cout << "Sorting case insensitive\n";
|
||||
} else {
|
||||
cout << "Sorting case sensitive\n";
|
||||
}
|
||||
} else {
|
||||
cout <<"Cannot find attribute \"ignoreCase\", defaulting to case sensitive sort\nConsider adding the node\n";
|
||||
}
|
||||
} else {
|
||||
cout << "No environment settings found, defaulting to case sensitive sort\nConsider adding the node\n";
|
||||
}
|
||||
|
||||
vector<xmlname> words;
|
||||
for (TiXmlElement *childNode = autoc->FirstChildElement("KeyWord");
|
||||
childNode ;
|
||||
childNode = childNode->NextSiblingElement("KeyWord") )
|
||||
{
|
||||
const char * name = childNode->Attribute("name");
|
||||
if (!name) {
|
||||
cout << "Warning: KeyWord without name!, skipping...\n";
|
||||
continue;
|
||||
} else {
|
||||
int i = 0;
|
||||
while(name[i] != 0) {
|
||||
if (!isalnum(name[i]) && name[i] != '_') {
|
||||
cout << "Warning, keyword " << name << " contains unsupported characters!\n";
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
words.push_back(xmlname(childNode, name));
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreCase)
|
||||
sort(words.begin(), words.end(), sortXML);
|
||||
else
|
||||
sort(words.begin(), words.end(), sortXMLCase);
|
||||
|
||||
for(size_t i = 1; i < words.size(); i++) {
|
||||
//merge duplicates
|
||||
if (!strcmp(words[i].name, words[i-1].name)) {
|
||||
merge(words[i-1].node, words[i].node);
|
||||
words.erase(words.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "Windows-1252", "" );
|
||||
doc.LinkEndChild( decl );
|
||||
TiXmlElement * element = new TiXmlElement( "NotepadPlus" );
|
||||
doc.LinkEndChild( element );
|
||||
TiXmlElement * element2 = new TiXmlElement( "AutoComplete" );
|
||||
element->LinkEndChild( element2 );
|
||||
|
||||
if (langName)
|
||||
element2->SetAttribute("language", langName);
|
||||
|
||||
if (envNode)
|
||||
element2->LinkEndChild(envNode);
|
||||
|
||||
for(size_t i = 0; i < words.size(); i++) {
|
||||
element2->LinkEndChild(words[i].node);
|
||||
}
|
||||
|
||||
doc.SaveFile( file );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void merge(TiXmlElement * n1, TiXmlElement * n2) {
|
||||
const char * funcAttr = NULL;
|
||||
funcAttr = n2->Attribute("func");
|
||||
if (!funcAttr || !strcmp(funcAttr, "yes")) {
|
||||
return;
|
||||
}
|
||||
|
||||
n1->SetAttribute("func", "yes");
|
||||
|
||||
for (TiXmlElement *childNode = n2->FirstChildElement("Overload");
|
||||
childNode ;
|
||||
childNode = childNode->NextSiblingElement("Overload") )
|
||||
{
|
||||
n1->LinkEndChild(childNode);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="sorter"
|
||||
ProjectGUID="{DC172735-2C6B-43D1-BDCD-C725B7ACCA96}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\TinyXml"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/../sorter.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/sorter.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\TinyXml"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="4"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/../sorter.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\sorter.cpp">
|
||||
</File>
|
||||
<Filter
|
||||
Name="TinyXml"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\..\TinyXml\tinystr.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\TinyXml\tinyxml.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\TinyXml\tinyxmlerror.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\TinyXml\tinyxmlparser.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<Filter
|
||||
Name="TinyXml"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\..\TinyXml\tinystr.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\TinyXml\tinyxml.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
Loading…
Reference in New Issue