1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Diagnostics;
7
using System.Windows.Forms;
8
using ICSharpCode.Core;
9
using ICSharpCode.SharpDevelop.Gui;
10
using Microsoft.Win32;
12
namespace ICSharpCode.Svn
15
/// Wraps commands opening a dialog window.
16
/// The current implementation launches TortoiseSVN.
18
public static class SvnGuiWrapper
20
static string GetPathFromRegistry(RegistryHive hive, string valueName)
22
RegistryView view = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Default;
23
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(hive, view)) {
24
using (RegistryKey key = baseKey.OpenSubKey("SOFTWARE\\TortoiseSVN")) {
26
return key.GetValue(valueName) as string;
33
static string GetPathFromRegistry(string valueName)
35
return GetPathFromRegistry(RegistryHive.CurrentUser, valueName)
36
?? GetPathFromRegistry(RegistryHive.LocalMachine, valueName);
39
static void Proc(string command, string fileName, MethodInvoker callback)
41
Proc(command, fileName, callback, null);
44
static void Proc(string command, string fileName, MethodInvoker callback, string argument)
46
string path = GetPathFromRegistry("ProcPath");
48
using (TortoiseSvnNotFoundForm form = new TortoiseSvnNotFoundForm()) {
49
form.ShowDialog(WorkbenchSingleton.MainWin32Window);
53
StringBuilder arguments = new StringBuilder();
54
arguments.Append("/command:");
55
arguments.Append(command);
56
if (fileName != null) {
57
arguments.Append(" /notempfile ");
58
arguments.Append(" /path:\"");
59
arguments.Append(fileName);
60
arguments.Append('"');
62
if (argument != null) {
63
arguments.Append(' ');
64
arguments.Append(argument);
66
Process p = new Process();
67
p.StartInfo.FileName = path;
68
p.StartInfo.Arguments = arguments.ToString();
69
//p.StartInfo.RedirectStandardError = true;
70
//p.StartInfo.RedirectStandardOutput = true;
71
p.StartInfo.UseShellExecute = false;
72
p.EnableRaisingEvents = true;
73
p.Exited += delegate {
75
if (callback != null) { callback(); }
77
// p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
78
// SvnClient.Instance.SvnCategory.AppendText(e.Data);
80
// p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
81
// SvnClient.Instance.SvnCategory.AppendText(e.Data);
84
} catch (Exception ex) {
85
MessageService.ShowError(ex.Message);
90
public static void ShowCheckoutDialog(MethodInvoker callback)
92
Proc("checkout", null, callback);
95
public static void ShowExportDialog(MethodInvoker callback)
97
Proc("export", null, callback);
100
public static void Update(string fileName, MethodInvoker callback)
102
Proc("update", fileName, callback);
105
public static void ApplyPatch(string fileName, MethodInvoker callback)
107
//Proc("applypatch", fileName, callback);
108
// TODO: Applying patches is not implemented.
109
MessageService.ShowMessage("Applying patches is not implemented.");
112
public static void CreatePatch(string fileName, MethodInvoker callback)
114
Proc("createpatch", fileName, callback);
117
public static void Revert(string fileName, MethodInvoker callback)
119
Proc("revert", fileName, callback);
122
public static void Commit(string fileName, MethodInvoker callback)
124
Proc("commit", fileName, callback);
127
public static void Add(string fileName, MethodInvoker callback)
129
Proc("add", fileName, callback);
132
public static void Ignore(string fileName, MethodInvoker callback)
134
Proc("ignore", fileName, callback);
137
public static void ShowSvnHelp()
139
Proc("help", null, null);
142
public static void ShowSvnSettings()
144
Proc("settings", null, null);
147
public static void ShowSvnAbout()
149
Proc("about", null, null);
152
public static void Diff(string fileName, MethodInvoker callback)
154
Proc("diff", fileName, callback);
157
public static void ConflictEditor(string fileName, MethodInvoker callback)
159
Proc("conflicteditor", fileName, callback);
162
public static void ResolveConflict(string fileName, MethodInvoker callback)
164
Proc("resolve", fileName, callback);
167
public static void ShowLog(string fileName, MethodInvoker callback)
169
Proc("log", fileName, callback);
172
public static void Cleanup(string fileName, MethodInvoker callback)
174
Proc("cleanup", fileName, callback);
177
public static void RevisionGraph(string fileName, MethodInvoker callback)
179
Proc("revisiongraph", fileName, callback);
182
public static void RepoStatus(string fileName, MethodInvoker callback)
184
Proc("repostatus", fileName, callback);
187
public static void RepoBrowser(string fileName, MethodInvoker callback)
189
Proc("repobrowser", fileName, callback);
192
public static void UpdateToRevision(string fileName, MethodInvoker callback)
194
Proc("update", fileName, callback, "/rev");
197
public static void Export(string fileName, MethodInvoker callback)
199
Proc("export", fileName, callback);
202
public static void Branch(string fileName, MethodInvoker callback)
204
Proc("copy", fileName, callback);
207
public static void Lock(string fileName, MethodInvoker callback)
209
Proc("lock", fileName, callback);
212
public static void Blame(string fileName, MethodInvoker callback)
214
Proc("blame", fileName, callback);
217
public static void Switch(string fileName, MethodInvoker callback)
219
Proc("switch", fileName, callback);
222
public static void Merge(string fileName, MethodInvoker callback)
224
Proc("merge", fileName, callback);
227
public static void Relocate(string fileName, MethodInvoker callback)
229
Proc("relocate", fileName, callback);