-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtproc.c
124 lines (110 loc) · 3.84 KB
/
tproc.c
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
/*
** svn_wfx - Subversion File System Plugin for Total Commander
** Copyright (C) 2010 Matthias von Faber
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "tproc.h"
#include "strbuf.h"
#include <string.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/*
** Prototypes
*/
static void tproc_unary_cmd(const char *command, const char *paramName, const char *path, WORD showCmd);
/*
** Globals
*/
static struct
{
STARTUPINFO startupInfo;
error_handler_t errorHandler;
size_t tprocPathLen;
char tprocPath[MAX_PATH];
} Global = { 0 };
/*--------------------------------------------------------------------------*/
void tproc_init(error_handler_t errorHandler)
{
HKEY key;
GetStartupInfo(&Global.startupInfo);
Global.errorHandler = errorHandler;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", 0, KEY_READ, &key) == ERROR_SUCCESS)
{
DWORD size = sizeof(Global.tprocPath);
if (RegQueryValueEx(key, "ProcPath", NULL, NULL, Global.tprocPath, &size) == ERROR_SUCCESS)
{
Global.tprocPathLen = strlen(Global.tprocPath);
Global.tprocPath[Global.tprocPathLen++] = ' ';
Global.tprocPath[Global.tprocPathLen] = '\0';
}
RegCloseKey(key);
}
}
/*--------------------------------------------------------------------------*/
void tproc_checkout(const char *url)
{
tproc_unary_cmd("checkout", "url", url, SW_RESTORE);
}
/*--------------------------------------------------------------------------*/
void tproc_blame(const char *url)
{
tproc_unary_cmd("blame", "path", url, SW_RESTORE);
}
/*--------------------------------------------------------------------------*/
void tproc_log(const char *url)
{
tproc_unary_cmd("log", "path", url, SW_MAXIMIZE);
}
/*--------------------------------------------------------------------------*/
void tproc_props(const char *url)
{
tproc_unary_cmd("properties", "path", url, SW_RESTORE);
}
/*--------------------------------------------------------------------------*/
void tproc_repobrowser(const char *url)
{
tproc_unary_cmd("repobrowser", "path", url, SW_MAXIMIZE);
}
/*--------------------------------------------------------------------------*/
void tproc_revgraph(const char *url)
{
tproc_unary_cmd("revisiongraph", "path", url, SW_MAXIMIZE);
}
/*--------------------------------------------------------------------------*/
static void tproc_unary_cmd(const char *command, const char *paramName, const char *path, WORD showCmd)
{
if (*Global.tprocPath)
{
PROCESS_INFORMATION pi;
char buf[1024];
strbuf_t s = { buf, sizeof(buf) };
strbuf_cat(&s, Global.tprocPath, Global.tprocPathLen);
Global.startupInfo.wShowWindow = showCmd;
strbuf_cat(&s, "/command:", 9);
strbuf_cat(&s, command, strlen(command));
strbuf_cat(&s, " /", 2);
strbuf_cat(&s, paramName, strlen(paramName));
strbuf_cat(&s, ":\"", 2);
strbuf_cat(&s, path, strlen(path));
strbuf_cat(&s, "\"", 1);
CreateProcess(NULL, buf, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &Global.startupInfo, &pi);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
else
{
Global.errorHandler("TortoiseSVN was not found.");
}
}