1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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"
31 #pragma comment(lib, "comctl32.lib")
32 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
34 #define MAX_LOADSTRING 100
37 HINSTANCE hInst
; // current instance
38 TCHAR szTitle
[MAX_LOADSTRING
]; // The title bar text
39 TCHAR szWindowClass
[MAX_LOADSTRING
]; // the main window class name
41 // Forward declarations of functions included in this code module:
42 INT_PTR CALLBACK
About(HWND
, UINT
, WPARAM
, LPARAM
);
44 TCHAR g_Promptphrase
[] = _T("Enter your OpenSSH passphrase:");
45 TCHAR
*g_Prompt
= NULL
;
47 TCHAR g_PassWord
[MAX_LOADSTRING
];
49 int APIENTRY
_tWinMain(HINSTANCE
/*hInstance*/,
50 HINSTANCE
/*hPrevInstance*/,
58 if( _tcslen(lpCmdLine
) == 0 )
60 g_Prompt
= g_Promptphrase
;
67 TCHAR
*yesno
=_T("(yes/no)");
68 size_t lens
= _tcslen(yesno
);
74 if (_tcsncicmp(p
, yesno
, lens
) == 0)
84 if (::MessageBox(NULL
, lpCmdLine
, _T("TortoiseGit - git CLI stdin wrapper"), MB_YESNO
|MB_ICONQUESTION
) == IDYES
)
96 if(DialogBox(hInst
, MAKEINTRESOURCE(IDD_ASK_PASSWORD
), NULL
, About
) == IDOK
)
98 _tprintf(_T("%s\n"), g_PassWord
);
106 void MarkWindowAsUnpinnable(HWND hWnd
)
108 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
110 HMODULE hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
113 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
116 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
120 var
.boolVal
= VARIANT_TRUE
;
121 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
129 // Message handler for password box.
130 INT_PTR CALLBACK
About(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM
/*lParam*/)
136 MarkWindowAsUnpinnable(hDlg
);
138 ::GetWindowRect(hDlg
,&rect
);
139 DWORD dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
140 DWORD dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
143 x
=(dwWidth
- (rect
.right
-rect
.left
))/2;
144 y
=(dwHeight
- (rect
.bottom
-rect
.top
))/2;
146 ::MoveWindow(hDlg
,x
,y
,rect
.right
-rect
.left
,rect
.bottom
-rect
.top
,TRUE
);
147 HWND title
=::GetDlgItem(hDlg
,IDC_STATIC_TITLE
);
148 ::SetWindowText(title
,g_Prompt
);
150 TCHAR
*pass
=_T("pass");
151 size_t passlens
= _tcslen(pass
);
153 bool password
= false;
156 if (_tcsncicmp(p
, pass
, passlens
) == 0)
164 SendMessage(::GetDlgItem(hDlg
, IDC_PASSWORD
), EM_SETPASSWORDCHAR
, 0, 0);
166 return (INT_PTR
)TRUE
;
170 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
172 if( LOWORD(wParam
) == IDOK
)
174 HWND password
= ::GetDlgItem(hDlg
,IDC_PASSWORD
);
175 ::GetWindowText(password
,g_PassWord
,MAX_LOADSTRING
);
177 EndDialog(hDlg
, LOWORD(wParam
));
178 return (INT_PTR
)TRUE
;
182 return (INT_PTR
)FALSE
;