1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2016, 2018-2019 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "DaemonCommand.h"
21 #include "ProgressDlg.h"
22 #include "UnicodeUtils.h"
23 #include "MessageBox.h"
26 bool DaemonCommand::Execute()
28 if (!GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
30 CMessageBox::Show(GetExplorerHWND(), IDS_NOGITREPO
, IDS_APPNAME
, MB_ICONERROR
);
33 if (CMessageBox::ShowCheck(GetExplorerHWND(), IDS_DAEMON_SECURITY_WARN
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_PROCEEDBUTTON
, IDS_ABORTBUTTON
, NULL
, L
"DaemonNoSecurityWarning", IDS_MSGBOX_DONOTSHOWAGAIN
) == 2)
35 CMessageBox::RemoveRegistryKey(L
"DaemonNoSecurityWarning"); // only store answer if it is "Proceed"
40 if (WSAStartup(MAKEWORD(2, 2), &wsaData
) != NO_ERROR
)
42 MessageBox(GetExplorerHWND(), L
"WSAStartup failed!", L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
45 SCOPE_EXIT
{ WSACleanup(); };
47 char hostName
[128] = { 0 };
48 if (gethostname(hostName
, sizeof(hostName
)) == SOCKET_ERROR
)
50 MessageBox(GetExplorerHWND(), L
"gethostname failed!", L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
55 ADDRINFOA addrinfo
= { 0 };
56 addrinfo
.ai_family
= AF_UNSPEC
;
57 PADDRINFOA result
= nullptr;
58 GetAddrInfoA(hostName
, nullptr, &addrinfo
, &result
);
59 for (auto ptr
= result
; ptr
!= nullptr; ptr
= ptr
->ai_next
)
61 if (ptr
->ai_family
!= AF_INET
&& ptr
->ai_family
!= AF_INET6
)
64 DWORD ipbufferlength
= 46;
66 if (WSAAddressToString(ptr
->ai_addr
, static_cast<DWORD
>(ptr
->ai_addrlen
), nullptr, CStrBuf(ip
, ipbufferlength
), &ipbufferlength
))
69 if (ptr
->ai_family
== AF_INET6
)
71 if (CStringUtils::StartsWith(ip
, L
"fe80:")) // strip % interface number at the end
72 ip
= ip
.Left(ip
.Find(L
'%'));
73 ip
= L
'[' + ip
; // IPv6 addresses needs to be enclosed within braces
79 FreeAddrInfoA(result
);
81 CString
basePath(g_Git
.m_CurrentDir
);
82 basePath
.TrimRight(L
'\\');
83 if (basePath
.GetLength() == 2)
87 cmd
.Format(L
"git.exe daemon --verbose --export-all --base-path=\"%s\"", static_cast<LPCWSTR
>(basePath
));
89 theApp
.m_pMainWnd
= &progDlg
;
90 progDlg
.m_GitCmd
= cmd
;
92 progDlg
.m_PreText
= L
"git://localhost/";
95 for (const auto& ip
: ips
)
97 progDlg
.m_PreText
+= L
"git://";
98 progDlg
.m_PreText
+= ip
;
99 progDlg
.m_PreText
+= L
"/\n";