Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
1522 lines (1192 loc) · 42.6 KB

File metadata and controls

1522 lines (1192 loc) · 42.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Plugin Manager Plugin for Notepad++
Copyright (C)2009-2010 Dave Brotherstone <davegb@pobox.com>
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "precompiled_headers.h"
#include "PluginList.h"
#include "PluginManager.h"
#include "tinyxml/tinyxml.h"
#include "libinstall/InstallStep.h"
#include "libinstall/DownloadStep.h"
#include "libinstall/InstallStepFactory.h"
#include "libinstall/md5.h"
#include "libinstall/DownloadManager.h"
#include "libinstall/Decompress.h"
#include "libinstall/DirectoryUtil.h"
#include "Utility.h"
#include "WcharMbcsConverter.h"
using namespace std;
using namespace std::placeholders;
typedef BOOL (__cdecl * PFUNCISUNICODE)();
PluginList::PluginList(void)
: _nppData(nullptr),
_variableHandler(nullptr)
{
_hListsAvailableEvent = CreateEvent(
NULL, // LPSECURITY_ATTRIBUTES
TRUE, // bManualReset
FALSE, // Initial state
NULL); // Event name
}
PluginList::~PluginList(void)
{
if (_variableHandler)
delete _variableHandler;
clearPluginList();
}
void PluginList::init(NppData *nppData)
{
_nppData = nppData;
TCHAR configDir[MAX_PATH];
TCHAR nppDir[MAX_PATH];
TCHAR allUsersPluginDir[MAX_PATH];
::SendMessage(nppData->_nppHandle, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH, reinterpret_cast<LPARAM>(configDir));
::SendMessage(nppData->_nppHandle, NPPM_GETNPPDIRECTORY, MAX_PATH, reinterpret_cast<LPARAM>(nppDir));
LPARAM nppVersion = ::SendMessage(nppData->_nppHandle, NPPM_GETNPPVERSION, 0, 0);
int majorVersion = HIWORD(nppVersion);
int minorVersion = LOWORD(nppVersion);
TCHAR tmp[10];
_itot_s(majorVersion, tmp, 10, 10);
tstring versionString(tmp);
_itot_s(minorVersion, tmp, 10, 10);
for(int i = 0; tmp[i]; i++)
{
versionString.push_back(_T('.'));
versionString.push_back(tmp[i]);
}
_nppVersion = versionString;
_tcscpy_s(allUsersPluginDir, MAX_PATH, nppDir);
::PathAppend(allUsersPluginDir, _T("plugins"));
_variableHandler = new VariableHandler();
_variableHandler->setVariable(_T("NPPDIR"), nppDir);
_variableHandler->setVariable(_T("ALLUSERSPLUGINDIR"), allUsersPluginDir);
_variableHandler->setVariable(VALIDATE_BASE_URL_VAR, getValidateUrl());
ITEMIDLIST *pidl;
HRESULT result = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl);
if (result == S_OK)
{
TCHAR appDataPluginDir[MAX_PATH];
if (SHGetPathFromIDList(pidl, appDataPluginDir))
{
PathAppend(appDataPluginDir, _T("Notepad++\\plugins"));
_variableHandler->setVariable(_T("USERPLUGINDIR"), appDataPluginDir);
}
else
{
_variableHandler->setVariable(_T("USERPLUGINDIR"), allUsersPluginDir);
}
}
else
{
_variableHandler->setVariable(_T("USERPLUGINDIR"), allUsersPluginDir);
}
if (g_options.installLocation == INSTALLLOC_APPDATA)
{
_variableHandler->setVariable(_T("PLUGINDIR"), _variableHandler->getVariable(_T("USERPLUGINDIR")).c_str());
}
else
{
_variableHandler->setVariable(_T("PLUGINDIR"), _variableHandler->getVariable(_T("ALLUSERSPLUGINDIR")).c_str());
}
_variableHandler->setVariable(_T("CONFIGDIR"), configDir);
}
void PluginList::addPluginNames(TiXmlElement* pluginNamesElement)
{
TiXmlElement *pluginNameNode = pluginNamesElement->FirstChildElement();
while(pluginNameNode)
{
if (pluginNameNode->Attribute(_T("md5")) && pluginNameNode->Attribute(_T("name")))
{
_pluginRealNames[pluginNameNode->Attribute(_T("md5"))] = pluginNameNode->Attribute(_T("name"));
}
pluginNameNode = (TiXmlElement*)pluginNamesElement->IterateChildren(pluginNameNode);
}
}
BOOL PluginList::parsePluginFile(CONST TCHAR *filename)
{
clearPluginList();
TiXmlDocument doc(filename);
doc.LoadFile();
if (doc.Error())
{
#ifdef ALLOW_OVERRIDE_XML_URL
tstring error = doc.ErrorDesc();
error += _T(" at row ");
TCHAR tmp[10];
tmp[0] = '\0';
if (!_itot_s(doc.ErrorRow(), tmp, 10, 10))
error += tmp;
error += _T(", col ");
if (!_itot_s(doc.ErrorCol(), tmp, 10, 10))
error += tmp;
::MessageBox(_nppData->_nppHandle, error.c_str(), _T("Error parsing XML File"), 0);
#endif
return FALSE;
}
TiXmlNode *pluginsDoc = doc.FirstChildElement(_T("plugins"));
if (pluginsDoc)
{
TiXmlElement *pluginNode = pluginsDoc->FirstChildElement();
Plugin *plugin;
while(pluginNode)
{
if (!_tcscmp(pluginNode->Value(), _T("pluginNames")))
{
addPluginNames(pluginNode);
}
else if (!_tcscmp(pluginNode->Value(), _T("plugin")))
{
plugin = new Plugin();
plugin->setName(pluginNode->Attribute(_T("name")));
BOOL available = FALSE;
if (g_isUnicode)
{
if (g_isX64)
{
TiXmlElement *versionUrlElement = pluginNode->FirstChildElement(_T("x64Version"));
if (versionUrlElement && versionUrlElement->FirstChild())
{
plugin->setVersion(PluginVersion(versionUrlElement->FirstChild()->Value()));
available = TRUE;
}
}
else
{
TiXmlElement *versionUrlElement = pluginNode->FirstChildElement(_T("unicodeVersion"));
if (versionUrlElement && versionUrlElement->FirstChild())
{
plugin->setVersion(PluginVersion(versionUrlElement->FirstChild()->Value()));
available = TRUE;
}
}
}
else
{
TiXmlElement *versionUrlElement = pluginNode->FirstChildElement(_T("ansiVersion"));
if (versionUrlElement && versionUrlElement->FirstChild())
{
plugin->setVersion(PluginVersion(versionUrlElement->FirstChild()->Value()));
available = TRUE;
}
}
/* Notepad++ Version checks */
TiXmlElement *minVersionElement = pluginNode->FirstChildElement(_T("minNotepadVersion"));
if (minVersionElement && minVersionElement->FirstChild())
{
if (_nppVersion < PluginVersion(minVersionElement->FirstChild()->Value()))
available = FALSE;
}
TiXmlElement *maxVersionElement = pluginNode->FirstChildElement(_T("maxNotepadVersion"));
if (maxVersionElement && maxVersionElement->FirstChild())
{
if (_nppVersion > PluginVersion(maxVersionElement->FirstChild()->Value()))
available = FALSE;
}
/* Plugin attributes - description, author etc */
TiXmlElement *descriptionUrlElement = pluginNode->FirstChildElement(_T("description"));
if (descriptionUrlElement && descriptionUrlElement->FirstChild())
plugin->setDescription(descriptionUrlElement->FirstChild()->Value());
TiXmlElement *filenameUrlElement = pluginNode->FirstChildElement(_T("filename"));
if (filenameUrlElement && filenameUrlElement->FirstChild())
plugin->setFilename(filenameUrlElement->FirstChild()->Value());
TiXmlElement *versionsUrlElement = pluginNode->FirstChildElement(_T("versions"));
if (versionsUrlElement)
{
TiXmlElement *versionUrlElement = versionsUrlElement->FirstChildElement(_T("version"));
while(versionUrlElement)
{
plugin->addVersion(versionUrlElement->Attribute(_T("md5")), PluginVersion(versionUrlElement->Attribute(_T("number"))));
versionUrlElement = (TiXmlElement *)versionsUrlElement->IterateChildren(versionUrlElement);
}
}
TiXmlElement *badVersionsElement = pluginNode->FirstChildElement(_T("badVersions"));
if (badVersionsElement)
{
TiXmlElement *versionElement = badVersionsElement->FirstChildElement(_T("version"));
while(versionElement)
{
plugin->addBadVersion(PluginVersion(versionElement->Attribute(_T("number"))), versionElement->Attribute(_T("report")));
versionElement = (TiXmlElement *)badVersionsElement->IterateChildren(versionElement);
}
}
TiXmlElement *aliasesElement = pluginNode->FirstChildElement(_T("aliases"));
if (aliasesElement)
{
TiXmlElement *aliasElement = aliasesElement->FirstChildElement(_T("alias"));
while(aliasElement)
{
_aliases[tstring(aliasElement->Attribute(_T("name")))] = plugin->getName();
aliasElement = (TiXmlElement *)aliasesElement->IterateChildren(aliasElement);
}
}
/* Installation / Removal */
TiXmlElement *installElement = pluginNode->FirstChildElement(_T("install"));
addSteps(plugin, installElement, INSTALL);
TiXmlElement *removeElement = pluginNode->FirstChildElement(_T("remove"));
if (NULL != removeElement)
{
addSteps(plugin, removeElement, REMOVE);
}
TiXmlElement *dependencies = pluginNode->FirstChildElement(_T("dependencies"));
if (dependencies && !dependencies->NoChildren())
{
TiXmlElement *dependency = dependencies->FirstChildElement();
while (dependency)
{
// If dependency is another plugin (currently the only supported dependency)
if (!_tcscmp(dependency->Value(), _T("plugin")))
{
const TCHAR* dependencyName = dependency->Attribute(_T("name"));
if (dependencyName)
plugin->addDependency(dependencyName);
}
dependency = reinterpret_cast<TiXmlElement*>(dependencies->IterateChildren(dependency));
}
}
TiXmlElement *authorElement = pluginNode->FirstChildElement(_T("author"));
if (authorElement && authorElement->FirstChild())
plugin->setAuthor(authorElement->FirstChild()->Value());
TiXmlElement *sourceElement = pluginNode->FirstChildElement(_T("sourceUrl"));
if (sourceElement && sourceElement->FirstChild())
plugin->setSourceUrl(sourceElement->FirstChild()->Value());
TiXmlElement *homepageElement = pluginNode->FirstChildElement(_T("homepage"));
if (homepageElement && homepageElement->FirstChild())
plugin->setHomepage(homepageElement->FirstChild()->Value());
TiXmlElement *categoryElement = pluginNode->FirstChildElement(_T("category"));
if (categoryElement && categoryElement->FirstChild())
plugin->setCategory(categoryElement->FirstChild()->Value());
else
plugin->setCategory(_T("Others"));
TiXmlElement *latestUpdateElement = pluginNode->FirstChildElement(_T("latestUpdate"));
if (latestUpdateElement && latestUpdateElement->FirstChild())
plugin->setLatestUpdate(latestUpdateElement->FirstChild()->Value());
// Check stability, default to "Good"
TiXmlElement *stabilityElement = pluginNode->FirstChildElement(_T("stability"));
if (stabilityElement && stabilityElement->FirstChild())
plugin->setStability(stabilityElement->FirstChild()->Value());
else
plugin->setStability(_T("Good"));
TiXmlElement *isLibraryElement = pluginNode->FirstChildElement(_T("isLibrary"));
if (isLibraryElement && isLibraryElement->FirstChild())
{
tstring isLibrary(isLibraryElement->FirstChild()->Value());
if (isLibrary == _T("true"))
{
_libraries[plugin->getName()] = plugin;
plugin->setIsLibrary(true);
}
}
if (available)
_plugins[plugin->getName()] = plugin;
}
pluginNode = (TiXmlElement *)pluginsDoc->IterateChildren(pluginNode);
}
}
return TRUE;
}
void PluginList::addSteps(Plugin* plugin, TiXmlElement* installElement, InstallOrRemove ior)
{
if (!installElement)
return;
TiXmlElement *installStepElement = installElement->FirstChildElement();
InstallStepFactory installStepFactory(_variableHandler);
while (installStepElement)
{
// If it is a unicode tag and build for x64, then only process the contents if it's a x64 N++, which is just available for unicode
// or if it's an unicode tag and build for x86, then only process the contents if it's an unicode N++
// or if it's an ansi tag, then only process the contents if it's an ansi N++
if ((g_isUnicode && g_isX64
&& !_tcscmp(installStepElement->Value(), _T("x64"))
&& installStepElement->FirstChild())
||
(g_isUnicode
&& !_tcscmp(installStepElement->Value(), _T("unicode"))
&& installStepElement->FirstChild())
||
(!g_isUnicode
&& !_tcscmp(installStepElement->Value(), _T("ansi"))
&& installStepElement->FirstChild()))
{
addSteps(plugin, installStepElement, ior);
}
else
{
std::shared_ptr<InstallStep> installStep = installStepFactory.create(installStepElement);
if (installStep.get())
{
if (INSTALL == ior)
plugin->addInstallStep(installStep);
else if (REMOVE == ior)
plugin->addRemoveStep(installStep);
}
}
installStepElement = (TiXmlElement *)installElement->IterateChildren(installStepElement);
}
}
BOOL PluginList::checkInstalledPlugins()
{
const tstring& nppDirectory = _variableHandler->getVariable(_T("ALLUSERSPLUGINDIR"));
_installedPlugins.clear();
_availablePlugins.clear();
_updateablePlugins.clear();
// Check in the default location
checkInstalledPlugins(nppDirectory.c_str(), TRUE);
if (g_options.appDataPluginsSupported)
{
const tstring& appDataPluginDir = _variableHandler->getVariable(_T("USERPLUGINDIR"));
if (!::PathFileExists(appDataPluginDir.c_str()))
{
DirectoryUtil::createDirectories(appDataPluginDir.c_str());
}
else
{
// No point checking what's installed if we've just created the directory!
checkInstalledPlugins(appDataPluginDir.c_str(), FALSE);
}
}
addAvailablePlugins();
return TRUE;
}
BOOL PluginList::checkInstalledPlugins(const TCHAR *pluginPath, BOOL allUsers)
{
tstring pluginsFullPathFilter(pluginPath);
pluginsFullPathFilter += _T("\\*.dll");
WIN32_FIND_DATA foundData;
HANDLE hFindFile = ::FindFirstFile(pluginsFullPathFilter.c_str(), &foundData);
if (hFindFile != INVALID_HANDLE_VALUE)
{
do
{
tstring pluginFilename(pluginPath);
pluginFilename += _T("\\");
pluginFilename += foundData.cFileName;
BOOL pluginOK = false;
tstring pluginName;
try
{
pluginName = getPluginName(pluginFilename);
pluginOK = true;
}
catch (...)
{
pluginOK = false;
}
if (pluginOK)
{
PluginContainer::iterator knownPlugin = _plugins.find(pluginName);
if (knownPlugin == _plugins.end())
{
// plugin name is not known, so see if we recognise the hash
// i.e. is it export plugin which renames itself
// (or some other plugin that does the same thing)
TCHAR hash[(MD5::HASH_LENGTH * 2) + 1];
if (MD5::hash(pluginFilename.c_str(), hash, (MD5::HASH_LENGTH * 2) + 1))
{
tstring hashString(hash);
map<tstring, tstring>::iterator realNameIter = _pluginRealNames.find(hashString);
if (realNameIter != _pluginRealNames.end())
{
knownPlugin = _plugins.find(realNameIter->second);
}
}
}
// If still unknown, check the aliases
if (knownPlugin == _plugins.end())
{
map<tstring, tstring>::iterator aliasIter = _aliases.find(pluginName);
if (aliasIter != _aliases.end())
{
knownPlugin = _plugins.find(aliasIter->second);
}
}
// Check if plugin known now
if (knownPlugin != _plugins.end())
{
Plugin* plugin = knownPlugin->second;
// If the plugin is already installed, then make a copy for the list
if (plugin->isInstalled())
{
plugin = new Plugin(*plugin);
}
plugin->setFilename(foundData.cFileName);
setInstalledVersion(pluginFilename, plugin);
plugin->setInstalledForAllUsers(allUsers);
TCHAR hashBuffer[(MD5LEN * 2) + 1];
if (MD5::hash(pluginFilename.c_str(), hashBuffer, (MD5LEN * 2) + 1))
{
tstring hash = hashBuffer;
plugin->setInstalledVersionFromHash(hash);
}
// If this is a user's plugin (in AppData), and there's already a version
// for all users, and AppData plugins are supported, then remove the
// allusers version of the plugin, as the appdata one will take precedence
if (g_options.appDataPluginsSupported && FALSE == allUsers)
{
list<Plugin*>::iterator it = _installedPlugins.begin();
while (it != _installedPlugins.end())
{
if (plugin->getName() == (*it)->getName()
&& (*it)->getInstalledForAllUsers())
{
it = _installedPlugins.erase(it);
}
else
{
++it;
}
}
// Remove the plugin from updateable plugins too, as whether or not it can be
// updated depends on THIS version, not the all users version
it = _updateablePlugins.begin();
while (it != _updateablePlugins.end())
{
if (plugin->getName() == (*it)->getName()
&& (*it)->getInstalledForAllUsers())
{
it = _updateablePlugins.erase(it);
}
else
{
++it;
}
}
// Also update the registered plugin version to the installed version
Plugin* registeredPlugin = getPlugin(plugin->getName());
if (registeredPlugin) {
registeredPlugin->setInstalledVersion(plugin->getInstalledVersion());
}
}
if (plugin->getInstalledVersion().getIsBad()
|| plugin->getVersion() > plugin->getInstalledVersion())
_updateablePlugins.push_back(plugin);
else
_installedPlugins.push_back(plugin);
}
else
{
// Plugin is still not known, so create an empty stub for it
Plugin* plugin = new Plugin();
plugin->setName(pluginName);
plugin->setFilename(foundData.cFileName);
setInstalledVersion(pluginFilename, plugin);
plugin->setDescription(_T("Unknown plugin - please let us know about this plugin on the forums"));
_installedPlugins.push_back(plugin);
}
}
} while(::FindNextFile(hFindFile, &foundData));
FindClose(hFindFile);
}
return TRUE;
}
void PluginList::addAvailablePlugins()
{
PluginContainer::iterator iter = _plugins.begin();
while (iter != _plugins.end())
{
if (!iter->second->isInstalled())
{
if (g_options.showUnstable || iter->second->getStability() == _T("Good"))
_availablePlugins.push_back(iter->second);
}
++iter;
}
}
tstring PluginList::getPluginName(tstring pluginFilename)
{
HINSTANCE pluginInstance = ::LoadLibrary(pluginFilename.c_str());
if (pluginInstance)
{
PFUNCISUNICODE pFuncIsUnicode = (PFUNCISUNICODE)GetProcAddress(pluginInstance, "isUnicode");
BOOL isUnicode;
if (!pFuncIsUnicode || !pFuncIsUnicode())
isUnicode = FALSE;
else
isUnicode = TRUE;
PFUNCGETNAME pFuncGetName = (PFUNCGETNAME)GetProcAddress(pluginInstance, "getName");
if (pFuncGetName)
{
CONST TCHAR* pluginName = pFuncGetName();
if (pluginName)
{
tstring tpluginName = pluginName;
tstring::size_type ampPosition = tpluginName.find(_T("&"));
while(ampPosition != tstring::npos)
{
tpluginName.replace(ampPosition, 1, _T(""));
ampPosition = tpluginName.find(_T("&"));
}
::FreeLibrary(pluginInstance);
return tpluginName;
}
else
{
::FreeLibrary(pluginInstance);
return _T("");
}
}
else
{
::FreeLibrary(pluginInstance);
throw tstring(_T("Plugin name call not defined"));
}
}
else
{
throw tstring(_T("Load library failed"));
}
}
BOOL PluginList::setInstalledVersion(tstring pluginFilename, Plugin* plugin)
{
DWORD handle;
DWORD bufferSize = ::GetFileVersionInfoSize(pluginFilename.c_str(), &handle);
if (bufferSize <= 0)
return FALSE;
unsigned char* buffer = new unsigned char[bufferSize];
::GetFileVersionInfo(pluginFilename.c_str(), handle, bufferSize, buffer);
/*struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;*/
VS_FIXEDFILEINFO* lpFileInfo;
UINT cbFileInfo;
VerQueryValue(buffer,
_T("\\"),
(LPVOID*)&lpFileInfo,
&cbFileInfo);
if (cbFileInfo)
{
plugin->setInstalledVersion(PluginVersion((lpFileInfo->dwFileVersionMS & 0xFFFF0000) >> 16,
lpFileInfo->dwFileVersionMS & 0x0000FFFF,
(lpFileInfo->dwFileVersionLS & 0xFFFF0000) >> 16,
lpFileInfo->dwFileVersionLS & 0x0000FFFF));
/*
HRESULT hr;
TCHAR subBlock[50];
hr = StringCchPrintf(subBlock, 50,
_T("\\StringFileInfo\\%04x%04x\\FileVersion"),
lpTranslate[0].wLanguage,
lpTranslate[0].wCodePage);
if (FAILED(hr))
{
return FALSE;
}
else
{
TCHAR *fileVersion;
UINT fileVersionLength;
if(::VerQueryValue(buffer, subBlock, reinterpret_cast<LPVOID *>(&fileVersion), &fileVersionLength))
{
if (fileVersion)
plugin->setInstalledVersion(PluginVersion(fileVersion));
}
}
*/
}
else
{
delete[] buffer;
return FALSE;
}
delete[] buffer;
return TRUE;
}
void PluginList::waitForListsAvailable()
{
::WaitForSingleObject(_hListsAvailableEvent, INFINITE);
}
BOOL PluginList::listsAvailable()
{
DWORD result = ::WaitForSingleObject(_hListsAvailableEvent, 0);
if (result == WAIT_OBJECT_0)
return TRUE;
else
return FALSE;
}
PluginListContainer& PluginList::getInstalledPlugins()
{
return _installedPlugins;
}
PluginListContainer& PluginList::getAvailablePlugins()
{
return _availablePlugins;
}
PluginListContainer& PluginList::getUpdateablePlugins()
{
return _updateablePlugins;
}
VariableHandler* PluginList::getVariableHandler()
{
return _variableHandler;
}
Plugin* PluginList::getPlugin(tstring name)
{
Plugin* plugin = _plugins[name];
if (NULL == plugin)
{
plugin = _libraries[name];
}
return plugin;
}
BOOL PluginList::isInstallOrUpgrade(const tstring& name)
{
Plugin* plugin = _plugins[name];
if (NULL == plugin)
{
plugin = _libraries[name];
}
if (!plugin || (plugin->isInstalled() && plugin->getVersion() <= plugin->getInstalledVersion()))
return FALSE;
else
return TRUE;
}
std::shared_ptr< list<tstring> > PluginList::calculateDependencies(std::shared_ptr< list<Plugin*> > selectedPlugins)
{
set<tstring> toBeInstalled;
std::shared_ptr< list<tstring> > installDueToDepends(new list<tstring>);
// First add all selected plugins to a name map
list<Plugin*>::iterator pluginIter = selectedPlugins->begin();
while (pluginIter != selectedPlugins->end())
{
toBeInstalled.insert((*pluginIter)->getName());
++pluginIter;
}
// Now check all dependencies are in the name map
pluginIter = selectedPlugins->begin();
while(pluginIter != selectedPlugins->end())
{
if ((*pluginIter)->hasDependencies())
{
list<tstring> dependencies = (*pluginIter)->getDependencies();
list<tstring>::iterator depIter = dependencies.begin();
while(depIter != dependencies.end())
{
if (toBeInstalled.count(*depIter) == 0)
{
// if not already selected to be installed, then add it to the list
if (isInstallOrUpgrade(*depIter))
{
Plugin* dependsPlugin = getPlugin(*depIter);
if (NULL != dependsPlugin)
{
toBeInstalled.insert(*depIter);
selectedPlugins->push_back(dependsPlugin);
// Add the name to the list to show the message
installDueToDepends->push_back(*depIter);
}
}
}
++depIter;
}
}
++pluginIter;
}
return installDueToDepends;
}
void PluginList::downloadList()
{
// Work out the path of the Plugins.xml destination (in config dir)
TCHAR pluginConfig[MAX_PATH];
::SendMessage(_nppData->_nppHandle, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH - 26, reinterpret_cast<LPARAM>(pluginConfig));
if (!::PathFileExists(pluginConfig))
{
DirectoryUtil::createDirectories(pluginConfig);
}
tstring pluginsListFilename(pluginConfig);
tstring pluginsListZipFilename(pluginConfig);
pluginsListFilename.append(_T("\\PluginManagerPlugins.xml"));
pluginsListZipFilename.append(_T("\\PluginManagerPlugins.zip"));
// Download the plugins.xml from the repository
CancelToken cancelToken;
DownloadManager downloadManager(cancelToken);
tstring contentType;
TCHAR hashBuffer[(MD5LEN * 2) + 1];
MD5::hash(pluginsListFilename.c_str(), hashBuffer, (MD5LEN * 2) + 1);
string serverMD5;
BOOL downloadSuccess = FALSE;
downloadManager.disableCache();
#ifdef ALLOW_OVERRIDE_XML_URL
BOOL downloadResult;
if (!g_options.downloadMD5Url.empty())
{
downloadResult = downloadManager.getUrl(g_options.downloadMD5Url.c_str(), serverMD5, &g_options.moduleInfo);
}
else
{
TCHAR *md5Url = getPluginsMd5Url();
downloadResult = downloadManager.getUrl(md5Url, serverMD5, &g_options.moduleInfo);
}
#else
TCHAR *md5Url = getPluginsMd5Url();
BOOL downloadResult = downloadManager.getUrl(md5Url, serverMD5, &g_options.moduleInfo);
#endif
std::shared_ptr<char> cHashBuffer = WcharMbcsConverter::tchar2char(hashBuffer);
if (downloadResult && serverMD5 == cHashBuffer.get()) {
// Server hash matches local hash, so we're ok to continue
downloadSuccess = TRUE;
}
else if (downloadResult && serverMD5 != cHashBuffer.get())
{
// If the build is allowing to override the download URL, then use the one from options
// Also, don't unzip it - assume if it's overridden, it's a test version and hence easier to treat it
// as a plain xml file
#ifdef ALLOW_OVERRIDE_XML_URL
if (!g_options.downloadUrl.empty())
{
downloadSuccess = downloadManager.getUrl(g_options.downloadUrl.c_str(), pluginsListFilename, contentType, &g_options.moduleInfo);
/*
tstring unzipPath(pluginConfig);
unzipPath.append(_T("\\"));
Decompress::unzip(pluginsListZipFilename, unzipPath);
*/
}
else
#endif
{
// OSes less than vista don't support SNI, which cloudflare uses to support HTTPS, so we have to use HTTP on old OSes
TCHAR *pluginsUrl = getPluginsUrl();
downloadSuccess = downloadManager.getUrl(pluginsUrl, pluginsListZipFilename, contentType, &g_options.moduleInfo);
if (downloadSuccess) {
// Unzip the plugins.zip to PluginManagerPlugins.xml
tstring unzipPath(pluginConfig);
unzipPath.append(_T("\\"));
Decompress::unzip(pluginsListZipFilename, unzipPath);
}
}
}
if (downloadSuccess) {
// Parse it
parsePluginFile(pluginsListFilename.c_str());
// Check for what is installed
checkInstalledPlugins();
::SetEvent(_hListsAvailableEvent);
} else {
MessageBox(_nppData->_nppHandle, _T("There was an error downloading the plugin list. Please check your internet connection, and your proxy settings in Internet Explorer, Edge or Chrome"),
_T("Download Error"), MB_ICONERROR);
}
}
TCHAR* PluginList::getPluginsMd5Url() {
if (g_options.useDevPluginList) {
return DEV_PLUGINS_MD5_URL;
}
if (g_options.forceHttp || g_winVer < WV_VISTA) {
return PLUGINS_HTTP_MD5_URL;
}
return PLUGINS_MD5_URL;
}
TCHAR* PluginList::getPluginsUrl() {
if (g_options.useDevPluginList) {
return DEV_PLUGINS_URL;
}
if (g_options.forceHttp || g_winVer < WV_VISTA) {
return PLUGINS_HTTP_URL;
}
return PLUGINS_URL;
}
TCHAR* PluginList::getValidateUrl() {
if (g_options.useDevPluginList) {
return DEV_VALIDATE_BASE_URL;
}
if (g_options.forceHttp || g_winVer < WV_VISTA) {
Morty Proxy This is a proxified and sanitized view of the page, visit original site.