1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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 // SshAskPass.cpp : Defines the entry point for the application.
29 #pragma comment(lib, "comctl32.lib")
30 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
32 #define MAX_LOADSTRING 100
35 HINSTANCE hInst
; // current instance
37 const TCHAR g_Promptphrase
[] = _T("Enter your OpenSSH passphrase:");
38 const TCHAR
*g_Prompt
= g_Promptphrase
;
40 TCHAR g_PassWord
[MAX_LOADSTRING
];
42 // Forward declarations of functions included in this code module:
43 INT_PTR CALLBACK
PasswdDlg(HWND
, UINT
, WPARAM
, LPARAM
);
45 int APIENTRY
_tWinMain(HINSTANCE
/*hInstance*/,
46 HINSTANCE
/*hPrevInstance*/,
54 size_t cmdlineLen
=_tcslen(lpCmdLine
);
55 if (lpCmdLine
[0] == '"' && cmdlineLen
> 1 && lpCmdLine
[cmdlineLen
- 1] == '"')
57 lpCmdLine
[cmdlineLen
- 1] = 0;
60 if (lpCmdLine
[0] != 0)
63 const TCHAR
*yesno
=_T("(yes/no)");
64 const size_t lens
= _tcslen(yesno
);
65 const TCHAR
*p
= lpCmdLine
;
70 if (_tcsncicmp(p
, yesno
, lens
) == 0)
80 if (::MessageBox(NULL
, g_Prompt
, _T("TortoiseGit - git CLI stdin wrapper"), MB_YESNO
|MB_ICONQUESTION
) == IDYES
)
92 if (DialogBox(hInst
, MAKEINTRESOURCE(IDD_ASK_PASSWORD
), nullptr, PasswdDlg
) == IDOK
)
94 _tprintf(_T("%s\n"), g_PassWord
);
102 void MarkWindowAsUnpinnable(HWND hWnd
)
104 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
106 HMODULE hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
109 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
112 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
116 var
.boolVal
= VARIANT_TRUE
;
117 pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
125 // Message handler for password box.
126 INT_PTR CALLBACK
PasswdDlg(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM
/*lParam*/)
132 MarkWindowAsUnpinnable(hDlg
);
134 ::GetWindowRect(hDlg
,&rect
);
135 DWORD dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
136 DWORD dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
139 x
=(dwWidth
- (rect
.right
-rect
.left
))/2;
140 y
=(dwHeight
- (rect
.bottom
-rect
.top
))/2;
142 ::MoveWindow(hDlg
,x
,y
,rect
.right
-rect
.left
,rect
.bottom
-rect
.top
,TRUE
);
143 HWND title
=::GetDlgItem(hDlg
,IDC_STATIC_TITLE
);
144 ::SetWindowText(title
,g_Prompt
);
146 const TCHAR
*pass
=_T("pass");
147 const size_t passlens
= _tcslen(pass
);
148 const TCHAR
*p
= g_Prompt
;
149 bool password
= false;
152 if (_tcsncicmp(p
, pass
, passlens
) == 0)
160 SendMessage(::GetDlgItem(hDlg
, IDC_PASSWORD
), EM_SETPASSWORDCHAR
, 0, 0);
161 ::FlashWindow(hDlg
, TRUE
);
163 return (INT_PTR
)TRUE
;
167 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
169 if( LOWORD(wParam
) == IDOK
)
171 HWND password
= ::GetDlgItem(hDlg
,IDC_PASSWORD
);
172 ::GetWindowText(password
,g_PassWord
,MAX_LOADSTRING
);
174 EndDialog(hDlg
, LOWORD(wParam
));
175 return (INT_PTR
)TRUE
;
179 return (INT_PTR
)FALSE
;