1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2016, 2018 - 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 (CMessageBox::ShowCheck(GetExplorerHWND(), IDS_DAEMON_SECURITY_WARN
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_PROCEEDBUTTON
, IDS_ABORTBUTTON
, NULL
, L
"DaemonNoSecurityWarning", IDS_MSGBOX_DONOTSHOWAGAIN
) == 2)
30 CMessageBox::RemoveRegistryKey(L
"DaemonNoSecurityWarning"); // only store answer if it is "Proceed"
35 if (WSAStartup(MAKEWORD(2, 2), &wsaData
) != NO_ERROR
)
37 MessageBox(GetExplorerHWND(), L
"WSAStartup failed!", L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
40 SCOPE_EXIT
{ WSACleanup(); };
42 char hostName
[128] = { 0 };
43 if (gethostname(hostName
, sizeof(hostName
)) == SOCKET_ERROR
)
45 MessageBox(GetExplorerHWND(), L
"gethostname failed!", L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
50 ADDRINFOA addrinfo
= { 0 };
51 addrinfo
.ai_family
= AF_UNSPEC
;
52 PADDRINFOA result
= nullptr;
53 GetAddrInfoA(hostName
, nullptr, &addrinfo
, &result
);
54 for (auto ptr
= result
; ptr
!= nullptr; ptr
= ptr
->ai_next
)
56 if (ptr
->ai_family
!= AF_INET
&& ptr
->ai_family
!= AF_INET6
)
59 DWORD ipbufferlength
= 46;
61 if (WSAAddressToString(ptr
->ai_addr
, (DWORD
)ptr
->ai_addrlen
, nullptr, CStrBuf(ip
, ipbufferlength
), &ipbufferlength
))
64 if (ptr
->ai_family
== AF_INET6
)
66 if (CStringUtils::StartsWith(ip
, L
"fe80:")) // strip % interface number at the end
67 ip
= ip
.Left(ip
.Find(L
'%'));
68 ip
= L
'[' + ip
; // IPv6 addresses needs to be enclosed within braces
74 FreeAddrInfoA(result
);
76 CString
basePath(g_Git
.m_CurrentDir
);
77 basePath
.TrimRight(L
'\\');
78 if (basePath
.GetLength() == 2)
82 cmd
.Format(L
"git.exe daemon --verbose --export-all --base-path=\"%s\"", (LPCTSTR
)basePath
);
84 theApp
.m_pMainWnd
= &progDlg
;
85 progDlg
.m_GitCmd
= cmd
;
87 progDlg
.m_PreText
= L
"git://localhost/";
90 for (const auto& ip
: ips
)
92 progDlg
.m_PreText
+= L
"git://";
93 progDlg
.m_PreText
+= ip
;
94 progDlg
.m_PreText
+= L
"/\n";