|
// 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);
}
|
Loading...