-
Notifications
You must be signed in to change notification settings - Fork 15
/
utility.cpp
67 lines (54 loc) · 1.64 KB
/
utility.cpp
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
#include <Windows.h>
#include <tchar.h>
#include <Shlwapi.h>
#include "PluginInterface.h"
#include "IniFileProcessor.h"
#include "utility.h"
wstring StringToWString(const string& s)
{
wstring temp(s.length(),L' ');
copy(s.begin(), s.end(), temp.begin());
return temp;
}
wstring GetConfigFilePath(HWND nppHandle)
{
wstring strConfigFilePath;
TCHAR szConfigDir[MAX_PATH];
TCHAR szBuffer[MAX_PATH];
szConfigDir[0] = 0;
::SendMessage(nppHandle, NPPM_GETPLUGINSCONFIGDIR,
MAX_PATH, (LPARAM)szConfigDir);
::PathCombine(szBuffer, szConfigDir, TEXT("PyNPP.ini"));
strConfigFilePath = szBuffer;
return strConfigFilePath;
}
void loadOption(HWND nppHandle, StruOptions& struOptions)
{
loadDefaultOption(struOptions);
wstring tsConfigFilePath = GetConfigFilePath(nppHandle);
IniFileProcessor processor(tsConfigFilePath);
IniFileProcessor::IniMap map;
map = processor.GetInfo(true);
IniFileProcessor::IniMap::iterator itrEnd = map.end();
if(map.find(keyPythonPath) != itrEnd)
{
struOptions.pythonPath = StringToWString(map[keyPythonPath].GetStrValue());
pythonPath = struOptions.pythonPath;
}
}
void loadDefaultOption(StruOptions& struOptions)
{
struOptions.pythonPath = GetPythonPath();
pythonPath = struOptions.pythonPath;
}
void saveOption(HWND nppHandle, StruOptions struOptions)
{
wstring tsConfigFilePath = GetConfigFilePath(nppHandle);
IniFileProcessor processor(tsConfigFilePath);
IniFileProcessor::IniMap map;
string value(struOptions.pythonPath.begin(), struOptions.pythonPath.end());
value.assign(struOptions.pythonPath.begin(), struOptions.pythonPath.end());
map[keyPythonPath] = value;
processor.SetMap(map);
processor.Save();
}