Windows下最轻量级Git克隆工具源码分享

介绍了一款基于Windows系统的Git项目自动克隆工具,通过简单的界面输入Git地址和分支名,即可快速克隆项目到指定文件夹,简化了操作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 简单的来说:
    原理就是只要用户知道git地址和分支名,即可克隆项目到指定文件夹,省去了输命令行的时间,方便用户去操作

  • 系统要求:
    Windows系统,然后本身环境要装有git
    git安装地址:https://git-scm.com/

  • 部分源码分享:

#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;
}
  • 运行截图如下:
    在这里插入图片描述

  • 工具完整源码:
    https://github.com/huifeng-kooboo/WinGitAuto

  • 版本说明
    当前为1.0版本,还存在一些bug:
    尚未实现一键下载全部分支功能。

  • Remark:
    大家觉得好用的话可以分享给其他人一起用,毕竟开发不易。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AIGC布道师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值