Kiln » TortoiseHg » TortoiseHg
Clone URL:  
RunDialog.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
// Copyright (C) 2011 Fog Creek Software // // 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 2 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 "stdafx.h" #include "RunDialog.h" #include "TortoiseUtils.h" #include "StringUtils.h" #include "THgStatus.h" #include "Kiln.h" #include "KeyboardHelpDialog.h" void RunDialog(HWND hWnd, const CString& strCmd, const CAtlList<CString>& listFiles, const CString& strFolder) { CString strDir = GetTHgProgRoot(); if (strDir.IsEmpty()) { ATLTRACE("RunDialog: THG root is empty\n"); return; } CString strHgCmd = strDir + "\\thgw.exe"; WIN32_FIND_DATA data; HANDLE hFind = ::FindFirstFile(strHgCmd, &data); if (hFind == INVALID_HANDLE_VALUE) { strHgCmd = strDir + "\\hgtk.exe"; hFind = ::FindFirstFile(strHgCmd, &data); if (hFind == INVALID_HANDLE_VALUE) { strHgCmd = strDir + "\\thg.cmd"; } else { ::FindClose(hFind); } } else { ::FindClose(hFind); } strHgCmd = Quote(strHgCmd) + " --nofork " + strCmd; CString strCwd; if (!strFolder.IsEmpty()) { strCwd = strFolder; } else if (!listFiles.IsEmpty()) { strCwd = listFiles.GetHead(); if (!::PathIsDirectory(strCwd)) strCwd = DirName(strCwd); } else { ATLTRACE("***** RunDialog: can't get cwd\n"); return; } if (strCmd == "thgstatus") { if (CTHgStatus::Remove(strCwd) != 0) { CString strPath = strDir + "\\TortoiseHgOverlayServer.exe"; LaunchCommand(Quote(strPath), strDir); } return; } else if (strCmd == "keyboard") { CKeyboardHelpDialog dlg; dlg.DoModal(hWnd); } else if (strCmd == "kiln") { KilnOpenRepo(hWnd, strCwd); return; } else if (strCmd == "kilnfiles") { KilnOpenFiles(hWnd, strCwd, listFiles); return; } if (!listFiles.IsEmpty()) { CAtlTemporaryFile file; if (FAILED(file.Create())) { ATLTRACE("***** RunDialog: error: failed to create temporary file\n"); return; } ATLTRACE("RunDialog: temp file = '%s'\n", file.TempFileName()); POSITION position = listFiles.GetHeadPosition(); while (position != NULL) { CString strFile = listFiles.GetNext(position); ATLTRACE("RunDialog: temp file adding '%s'\n", (LPCTSTR)strFile); file.Write((LPCTSTR)strFile, strFile.GetLength()); file.Write("\n", 1); } if (strCmd == "drag_move" || strCmd == "drag_copy") { // Append the current directory as the dest. file.Write((LPCTSTR)strCwd, strCwd.GetLength()); file.Write("\n", 1); } strHgCmd += " --listfile "; strHgCmd += file.TempFileName(); file.Close(); } LaunchCommand(strHgCmd, strCwd); }