-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeConsoleLink.cpp
211 lines (196 loc) · 6.96 KB
/
MakeConsoleLink.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
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
/*
MakeConsoleLink
A small program to help creating a shortcut (*.lnk) file
including console properties
*/
#include "stdafx.h"
#include "MakeConsoleLink.h"
int __cdecl _tmain(int argc, TCHAR **argv)
{
if (!ParseCommandLine(argc, argv))
{
_tprintf(TEXT("\nInvalid command line!\n"));
}
CCoInitialize init;
CComPtr<IShellLink> spsl;
spsl.CoCreateInstance(CLSID_ShellLink);
spsl->SetPath(commandLine);
spsl->SetArguments(szCommandArguments);
NT_CONSOLE_PROPS props;
ZeroMemory(&props, sizeof(NT_CONSOLE_PROPS));
SetConsoleProperties(&props);
CComQIPtr<IShellLinkDataList>(spsl)->AddDataBlock(&props);
CComQIPtr<IPersistFile>(spsl)->Save(szShortcutPath, TRUE);
return 0;
}
bool SetConsoleProperties(NT_CONSOLE_PROPS *props)
{
props->dbh.cbSize = sizeof(NT_CONSOLE_PROPS);
props->dbh.dwSignature = NT_CONSOLE_PROPS_SIG;
/*
The *Fill* settings below creates a bright green font on a blue background.
This is hard coded, as I don't yet have a great way to incoroporate this into
the command line parameters.
*/
props->wFillAttribute = (FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE);
props->wPopupFillAttribute = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED;
props->dwWindowSize.X = windowSizeX;
props->dwWindowSize.Y = windowSizeY;
props->dwScreenBufferSize.X = screenBufferSizeX;
props->dwScreenBufferSize.Y = screenBufferSizeY;
props->uCursorSize = cursorSize;
props->bQuickEdit = quickEdit;
props->bInsertMode = insertMode;
props->bAutoPosition = autoPosition;
props->uHistoryBufferSize = historyBufferSize;
props->uNumberOfHistoryBuffers = numberOfHistoryBuffers;
/*
Straight copy of the default colors for a console window
if we don't fill these out, black is the only color choice
if anyone wants to modify the fill colors :}
*/
props->ColorTable[0] = RGB(0x00, 0x00, 0x00);
props->ColorTable[1] = RGB(0x00, 0x00, 0x80);
props->ColorTable[2] = RGB(0x00, 0x80, 0x00);
props->ColorTable[3] = RGB(0x00, 0x80, 0x80);
props->ColorTable[4] = RGB(0x80, 0x00, 0x00);
props->ColorTable[5] = RGB(0x80, 0x00, 0x80);
props->ColorTable[6] = RGB(0x80, 0x80, 0x00);
props->ColorTable[7] = RGB(0xC0, 0xC0, 0xC0);
props->ColorTable[8] = RGB(0x80, 0x80, 0x80);
props->ColorTable[9] = RGB(0x00, 0x00, 0xFF);
props->ColorTable[10] = RGB(0x00, 0xFF, 0x00);
props->ColorTable[11] = RGB(0x00, 0xFF, 0xFF);
props->ColorTable[12] = RGB(0xFF, 0x00, 0x00);
props->ColorTable[13] = RGB(0xFF, 0x00, 0xFF);
props->ColorTable[14] = RGB(0xFF, 0xFF, 0x00);
props->ColorTable[15] = RGB(0xFF, 0xFF, 0xFF);
return true;
}
bool ParseCommandLine(int argc, TCHAR* argv[])
{
for (int i = 1; i < argc; ++i)
{
if (_wcsicmp(argv[i], L"-commandLine") == 0)
{
if (++i < argc)
{
StringCchCopy(commandLine, MAX_PATH, argv[i]);
if (commandLine[0] == 0)
{
_tprintf(TEXT("ERROR: invalid commandLine parameter: %s\n"), argv[i]);
return false;
}
}
}
else if (_wcsicmp(argv[i], L"-commandArgs") == 0)
{
if (++i < argc)
{
StringCchCopy(szCommandArguments, MAX_PATH, argv[i]);
if (commandLine[0] == 0)
{
_tprintf(TEXT("ERROR: invalid szCommandArguments parameter: %s\n"), argv[i]);
return false;
}
}
}
else if (_wcsicmp(argv[i], L"-shortcutPath") == 0)
{
if (++i < argc)
{
StringCchCopy(szShortcutPath, MAX_PATH, argv[i]);
if (commandLine[0] == 0)
{
_tprintf(TEXT("ERROR: invalid shortcutPath parameter: %s\n"), argv[i]);
return false;
}
}
}
else if (_wcsicmp(argv[i], L"-quickedit") == 0)
{
if (++i < argc)
{
quickEdit = (BOOL)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-insertMode") == 0)
{
if (++i < argc)
{
insertMode = (BOOL)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-windowSizeX") == 0)
{
if (++i < argc)
{
windowSizeX = (SHORT)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-windowSizeY") == 0)
{
if (++i < argc)
{
windowSizeY = (SHORT)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-windowBufferX") == 0)
{
if (++i < argc)
{
screenBufferSizeX = (SHORT)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-windowBufferY") == 0)
{
if (++i < argc)
{
screenBufferSizeY = (SHORT)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-bufferSize") == 0)
{
if (++i < argc)
{
historyBufferSize = (USHORT)_wtoi(argv[i]);
}
}
else if (_wcsicmp(argv[i], L"-historyBufferSize") == 0)
{
if (++i < argc)
{
numberOfHistoryBuffers = (USHORT)_wtoi(argv[i]);
}
}
else if ((_wcsicmp(argv[i], L"-help") == 0) || (_wcsicmp(argv[i], L"-?") == 0))
{
ShowHelp();
}
else
{
//show help anyway if we can't figure out the command line
ShowHelp();
//but let the caller know that we failed too
return false;
}
}
return true;
}
void ShowHelp()
{
_tprintf(TEXT("MakeConsoleLink creates a shortcut with specified console properties\n\n"));
_tprintf(TEXT("Command line options:\n"));
_tprintf(TEXT(" -commandLine\tName of shortcut executable (required)\n"));
_tprintf(TEXT(" -commandArgs\tArguments for command line (required)\n"));
_tprintf(TEXT(" -shortcutPath\tPath to shortcut to create (required)\n"));
_tprintf(TEXT(" -quickedit\t\tTurn on quickedit mode (0|1) - Default: 1 (on)\n"));
_tprintf(TEXT(" -insertMode\t\tTurn on insert mode (0|1) - Default: 1 (on)\n"));
_tprintf(TEXT(" -windowSizeX\tWindow Width - Default: 132\n"));
_tprintf(TEXT(" -windowSizeY\tWindow Height - Default:50\n"));
_tprintf(TEXT(" -windowBufferX\tSize of width buffer - Default:132\n"));
_tprintf(TEXT(" -windowBufferY\tSize of height buffer - Default: 1000\n"));
_tprintf(TEXT(" -bufferSize\t\tSize of command buffer - Default: 25\n"));
_tprintf(TEXT(" -historyBufferSize\tNumber of history buffers - Default: 4\n"));
_tprintf(TEXT("\n"));
}