1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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.
24 #include "SshAskPass.h"
29 #define MAX_LOADSTRING 100
32 HINSTANCE hInst
; // current instance
33 TCHAR szTitle
[MAX_LOADSTRING
]; // The title bar text
34 TCHAR szWindowClass
[MAX_LOADSTRING
]; // the main window class name
36 // Forward declarations of functions included in this code module:
37 INT_PTR CALLBACK
About(HWND
, UINT
, WPARAM
, LPARAM
);
39 TCHAR g_Promptphrase
[] = _T("Enter your OpenSSH passphrase:");
40 TCHAR
*g_Prompt
= NULL
;
42 TCHAR g_PassWord
[MAX_LOADSTRING
];
44 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
45 HINSTANCE hPrevInstance
,
49 UNREFERENCED_PARAMETER(hPrevInstance
);
53 if( _tcslen(lpCmdLine
) == 0 )
55 g_Prompt
= g_Promptphrase
;
62 TCHAR
*yesno
=_T("(yes/no)");
63 size_t lens
= _tcslen(yesno
);
69 if (_tcsncicmp(p
, yesno
, lens
) == 0)
79 if (::MessageBox(NULL
, lpCmdLine
, _T("TortoiseGit - git CLI stdin wrapper"), MB_YESNO
|MB_ICONQUESTION
) == IDYES
)
91 if(DialogBox(hInst
, MAKEINTRESOURCE(IDD_ASK_PASSWORD
), NULL
, About
) == IDOK
)
93 _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
= LoadLibrary(_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 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
125 // Message handler for password box.
126 INT_PTR CALLBACK
About(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
128 UNREFERENCED_PARAMETER(lParam
);
133 MarkWindowAsUnpinnable(hDlg
);
135 ::GetWindowRect(hDlg
,&rect
);
136 DWORD dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
137 DWORD dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
140 x
=(dwWidth
- (rect
.right
-rect
.left
))/2;
141 y
=(dwHeight
- (rect
.bottom
-rect
.top
))/2;
143 ::MoveWindow(hDlg
,x
,y
,rect
.right
-rect
.left
,rect
.bottom
-rect
.top
,TRUE
);
144 HWND title
=::GetDlgItem(hDlg
,IDC_STATIC_TITLE
);
145 ::SetWindowText(title
,g_Prompt
);
147 TCHAR
*pass
=_T("pass");
148 size_t passlens
= _tcslen(pass
);
150 bool password
= false;
153 if (_tcsncicmp(p
, pass
, passlens
) == 0)
161 SendMessage(::GetDlgItem(hDlg
, IDC_PASSWORD
), EM_SETPASSWORDCHAR
, 0, 0);
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
;