-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionkey.cpp
More file actions
executable file
·98 lines (83 loc) · 2.65 KB
/
functionkey.cpp
File metadata and controls
executable file
·98 lines (83 loc) · 2.65 KB
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
#include "functionkey.h"
#include "ini.h"
#include "utility.h"
#include "configmanager.h"
FunctionKey* FunctionKey::instance = NULL;
FunctionKey::FunctionKey()
{
}
FunctionKey::~FunctionKey()
{
}
void FunctionKey::ChangeFunction(int key, String name, String exec, String param)
{
String funkey = unicode::format(L"functionkey_f%d", key+1);
ConfigManager::GetInstance()->SetFuntionKey(funkey, L"name", name);
ConfigManager::GetInstance()->SetFuntionKey(funkey, L"exec", exec);
ConfigManager::GetInstance()->SetFuntionKey(funkey, L"param", param);
}
void FunctionKey::ExecFunction(int key, FILEINFO &info)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
String funkey = unicode::format(L"functionkey_f%d", key+1);
String funcexec = ConfigManager::GetInstance()->GetFuntionKey(funkey, L"exec");
String funcparam = ConfigManager::GetInstance()->GetFuntionKey(funkey, L"param");
if( funcexec.size() > 0 )
{
String path = info.m_type == TYPE_DIRECTORY ? info.m_fullpath : info.m_excutepath;
String param = ParseParameter(funcparam, path);
String exe = funcexec + L" " + L"\"" + param + L"\"";
utility::CreateProcess(exe);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
}
String FunctionKey::ParseParameter(String param, String path)
{
#if 1
String resultparam;
resultparam = unicode::replaceAll(param, functioncommand[0], utility::GetDrive(path.c_str()));
resultparam = unicode::replaceAll(resultparam, functioncommand[1], utility::GetDrive(path.c_str()) + utility::GetPath(path.c_str()));
resultparam = unicode::replaceAll(resultparam, functioncommand[2], path);
resultparam = unicode::replaceAll(resultparam, functioncommand[3], utility::GetFileName(path.c_str()));
return resultparam;
#else
String resultparam;
std::vector<String> tokens;
Tokenize(param, tokens, String(L"%"));
for (size_t i=0; i<tokens.size(); i++)
{
//resultparam += i > 0 ? L" " : L"";
if( functioncommand[0] == tokens[i] )
{
// drive
resultparam = resultparam + utility::GetDrive(path.c_str());
}
else if( functioncommand[1] == tokens[i] )
{
// dir
resultparam = resultparam + utility::GetDrive(path.c_str()) + utility::GetPath(path.c_str());
}
else if( functioncommand[2] == tokens[i] )
{
// fullpath
resultparam = resultparam + path;
}
else if( functioncommand[3] == tokens[i] )
{
// filename
resultparam = resultparam + utility::GetFileName(path.c_str());
}
else
{
resultparam = resultparam + tokens[i];
}
}
return resultparam;
#endif
}