-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.c
More file actions
68 lines (63 loc) · 2.15 KB
/
client.c
File metadata and controls
68 lines (63 loc) · 2.15 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
#include <windows.h>
#include <Shlwapi.h>
#include "../plugin/globals.h"
BYTE ParseArgument(WCHAR* cmd) {
if (!StrCmpIW(cmd, L"goto")) return FRC_GOTO;
if (!StrCmpIW(cmd, L"copy")) return FRC_COPY;
if (!StrCmpIW(cmd, L"qcpy")) return FRC_QCPY;
if (!StrCmpIW(cmd, L"quit")) return FRC_QUIT;
if (!StrCmpIW(cmd, L"into")) return FRC_INTO;
return FRC_NONE;
}
__declspec(noreturn) void ExitNoSlot() {
MessageBoxA(NULL,
"Unable to open Mailslot handle.",
"FRC Client Error", MB_OK | MB_ICONERROR);
ExitProcess(1);
}
__declspec(noreturn) void ExitUsage() {
MessageBoxA(NULL,
"The FRC client executable supports the following commands as its first parameter, "
"followed by an optional argument in some cases. All commands are case-insensitive.\n\n"
"GOTO\nNavigate to the file or folder given as the second argument.\n\n"
"INTO\nLike GOTO, but if the given argument is a folder, navigate into it.\n\n"
"COPY\nInsert the second argument as a string into the FAR command line\n\n"
"QCPY\nInsert the second argument into the FAR command line, but wrap it in double "
"quotes if it contains a space character (used to insert path names)\n\n"
"QUIT\nIssue a request for FRC server termination. The second argument is ignored.",
"FRC Client Usage", MB_OK | MB_ICONWARNING);
ExitProcess(1);
}
__declspec(noreturn) void main() {
int argc;
WCHAR **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argc >= 2) {
BYTE type = ParseArgument(argv[1]);
if (type != FRC_NONE) {
HANDLE slot = CreateFileW(
FRC_MSLOT,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (slot && slot != INVALID_HANDLE_VALUE) {
WCHAR cmdMask = ((WCHAR)type) << 8;
WCHAR *cmd = &cmdMask;
DWORD size = 2;
if (argc >= 3) {
cmd = argv[2];
size = (lstrlenW(cmd)+1) * sizeof(WCHAR);
cmd[0] = cmdMask | LOBYTE(cmd[0]);
}
WriteFile(slot, cmd, size, &size, NULL);
CloseHandle(slot);
ExitProcess(0);
} else {
ExitNoSlot();
}
}
}
ExitUsage();
}