簡單的來講: 原理就是隻要用戶知道git地址和分支名,便可克隆項目到指定文件夾,省去了輸命令行的時間,方便用戶去操做git
系統要求: Windows系統,而後自己環境要裝有git git安裝地址:git-scm.com/github
部分源碼分享:bash
#include "StdAfx.h"
#include "MainWnd.h"
using namespace std;
BEGIN_MSG_MAP(CMainWnd)
MSG_WM_INITDIALOG(OnInitDialog)
MSG_WM_SIZE(OnSize)
CHAIN_MSG_MAP(DMHWnd)// 將未處理的消息交由DMHWnd處理
END_MSG_MAP()
BEGIN_EVENT_MAP(CMainWnd)
EVENT_NAME_COMMAND(L"closebutton",OnClose)
EVENT_NAME_COMMAND(L"maxbutton",OnMaximize)
EVENT_NAME_COMMAND(L"restorebutton",OnRestore)
EVENT_NAME_COMMAND(L"minbutton", OnMinimize)
EVENT_NAME_COMMAND(L"btn_filesave",OnSavePath) //綁定保存路徑事件
EVENT_NAME_COMMAND(L"btn_rungit",OnRunGit) //保存Rungit事件
END_EVENT_MAP()
BOOL CMainWnd::OnInitDialog(HWND wndFocus, LPARAM lInitParam)
{
//綁定相關控件
m_txt_filesave = FindChildByNameT<DUIEdit>(L"txt_savepath");
m_btn_git = FindChildByNameT<DUIButton>(L"btn_rungit");
m_btn_filesave = FindChildByNameT<DUIButton>(L"btn_filesave");
m_txt_gitpath = FindChildByNameT<DUIEdit>(L"txt_gitpath");
m_txt_branchname = FindChildByNameT<DUIEdit>(L"txt_branchname");
m_radiobtn_branches = FindChildByNameT<DUIRadioButton>(L"radiobtn_branches");
return TRUE;
}
void CMainWnd::OnSize(UINT nType, CSize size)
{
DUIWindow* pMaxBtn = FindChildByName(L"maxbutton");
DUIWindow* pRestoreBtn = FindChildByName(L"restorebutton");
if (0 != size.cx&&0 != size.cy&&pMaxBtn&&pRestoreBtn)
{
if (SIZE_MAXIMIZED == nType)
{
pMaxBtn->DM_SetVisible(false);
pRestoreBtn->DM_SetVisible(true);
}
else if (SIZE_RESTORED == nType)
{
pMaxBtn->DM_SetVisible(true);
pRestoreBtn->DM_SetVisible(false);
}
}
//生成圓形矩形框
if (!IsIconic())
{
CRect rcWnd;
::GetWindowRect(m_hWnd, &rcWnd);
::OffsetRect(&rcWnd, -rcWnd.left, -rcWnd.top);
HRGN hWndRgn = ::CreateRoundRectRgn(0, 0, rcWnd.right, rcWnd.bottom,4,4);
SetWindowRgn(hWndRgn, TRUE);
::DeleteObject(hWndRgn);
}
SetMsgHandled(FALSE); // 由DMHWnd繼續處理OnSize消息
}
DMCode CMainWnd::OnClose()
{
DestroyWindow();
return DM_ECODE_OK;
}
DMCode CMainWnd::OnMaximize()
{
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
return DM_ECODE_OK;
}
DMCode CMainWnd::OnRestore()
{
SendMessage(WM_SYSCOMMAND,SC_RESTORE);
return DM_ECODE_OK;
}
DMCode CMainWnd::OnMinimize()
{
SendMessage(WM_SYSCOMMAND,SC_MINIMIZE);
return DM_ECODE_OK;
}
DMCode CMainWnd::OnSavePath()
{
//選擇文件夾保存
BROWSEINFO bi;
bi.hwndOwner = NULL;
bi.pidlRoot = CSIDL_DESKTOP;//文件夾的根目錄,此處爲桌面
bi.pszDisplayName = NULL;
bi.lpszTitle = NULL;//顯示位於對話框左上部的提示信息
bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;//有新建文件夾按鈕
bi.lpfn = NULL;
bi.iImage = 0;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);//調用選擇對話框
if (pidl == NULL)
{
::MessageBox(0,L"選擇失敗",L"當前未選擇文件夾",0);
return DM_ECODE_OK;
}
TCHAR strFolder[MAX_PATH];
SHGetPathFromIDList(pidl, strFolder);
//填充在Edit框上
m_txt_filesave->SetWindowTextW(strFolder);//
return DM_ECODE_OK;
}
std::string WStringToString(const std::wstring &wstr)
{
std::string str;
int nLen = (int)wstr.length();
str.resize(nLen, ' ');
int nResult = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wstr.c_str(), nLen, (LPSTR)str.c_str(), nLen, NULL, NULL);
if (nResult == 0)
{
return "";
}
return str;
}
DMCode CMainWnd::OnRunGit()
{
//獲取相關字符
std::wstring str_savepath =m_txt_filesave->GetLineText(); //獲取保存路徑
std::wstring str_branch_name = m_txt_branchname->GetLineText(); //獲取分支名
std::wstring str_git_path = m_txt_gitpath->GetLineText();//獲取git路徑
bool is_full = m_radiobtn_branches->DM_IsChecked(); //判斷是否被選中
if (str_savepath.size() <=0 || str_branch_name.size() <= 0 || str_git_path.size()<= 0)
{
::MessageBox(0,L"錯誤提示",L"當前信息填寫不完善,請從新填寫",0);
}
//str_cmd格式 like this: git clone -b http://github.com c:/ss
std::wstring str_cmd = L"git clone -b ";
str_cmd.append(str_branch_name);
str_cmd.append(L" ");
str_cmd.append(str_git_path);
str_cmd.append(L" ");
str_cmd.append(str_savepath);
string str_cmd_path =WStringToString(str_cmd);
WinExec(str_cmd_path.c_str(),SW_NORMAL); //bug:只有在normal狀況下才能夠git
return DM_ECODE_OK;
}
複製代碼
運行截圖以下: app
工具完整源碼: github.com/huifeng-koo…ide
版本說明 當前爲1.0版本,還存在一些bug: 還沒有實現一鍵下載所有分支功能。工具
Remark: 你們以爲好用的話能夠分享給其餘人一塊兒用,畢竟開發不易。ui