1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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.
27 #include "UnicodeUtils.h"
30 #pragma comment(lib, "comctl32.lib")
31 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
33 #define MAX_LOADSTRING 100
36 HINSTANCE hInst
; // current instance
38 const TCHAR g_Promptphrase
[] = L
"Enter your OpenSSH passphrase:";
39 const TCHAR
* g_Prompt
= g_Promptphrase
;
41 TCHAR g_PassWord
[MAX_LOADSTRING
];
43 // Forward declarations of functions included in this code module:
44 INT_PTR CALLBACK
PasswdDlg(HWND
, UINT
, WPARAM
, LPARAM
);
46 int APIENTRY
_tWinMain(HINSTANCE
/*hInstance*/,
47 HINSTANCE
/*hPrevInstance*/,
55 size_t cmdlineLen
= wcslen(lpCmdLine
);
56 if (lpCmdLine
[0] == '"' && cmdlineLen
> 1 && lpCmdLine
[cmdlineLen
- 1] == '"')
58 lpCmdLine
[cmdlineLen
- 1] = L
'\0';
61 if (lpCmdLine
[0] != L
'\0')
64 if (StrStrI(lpCmdLine
, L
"(yes/no)"))
66 if (::MessageBox(nullptr, g_Prompt
, L
"TortoiseGit - git CLI stdin wrapper", MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
73 if (StrStrI(lpCmdLine
, L
"Should I try again?"))
75 if (::MessageBox(nullptr, g_Prompt
, L
"TortoiseGit - git CLI yes/no wrapper", MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
81 if (DialogBox(hInst
, MAKEINTRESOURCE(IDD_ASK_PASSWORD
), nullptr, PasswdDlg
) == IDOK
)
83 printf("%s\n", CUnicodeUtils::StdGetUTF8(g_PassWord
).c_str());
90 void MarkWindowAsUnpinnable(HWND hWnd
)
92 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
94 HMODULE hShell
= AtlLoadSystemLibraryUsingFullPath(L
"Shell32.dll");
97 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
100 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
104 var
.boolVal
= VARIANT_TRUE
;
105 pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
113 // Message handler for password box.
114 INT_PTR CALLBACK
PasswdDlg(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM
/*lParam*/)
120 MarkWindowAsUnpinnable(hDlg
);
122 ::GetWindowRect(hDlg
,&rect
);
123 DWORD dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
124 DWORD dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
127 x
=(dwWidth
- (rect
.right
-rect
.left
))/2;
128 y
=(dwHeight
- (rect
.bottom
-rect
.top
))/2;
130 ::MoveWindow(hDlg
,x
,y
,rect
.right
-rect
.left
,rect
.bottom
-rect
.top
,TRUE
);
131 HWND title
= ::GetDlgItem(hDlg
, IDC_STATIC_TITLE
);
132 ::SetWindowText(title
, g_Prompt
);
133 if (!StrStrI(g_Prompt
, L
"pass"))
134 SendMessage(::GetDlgItem(hDlg
, IDC_PASSWORD
), EM_SETPASSWORDCHAR
, 0, 0);
135 ::FlashWindow(hDlg
, TRUE
);
137 return (INT_PTR
)TRUE
;
141 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
143 if( LOWORD(wParam
) == IDOK
)
145 HWND password
= ::GetDlgItem(hDlg
,IDC_PASSWORD
);
146 ::GetWindowText(password
,g_PassWord
,MAX_LOADSTRING
);
148 EndDialog(hDlg
, LOWORD(wParam
));
149 return (INT_PTR
)TRUE
;
153 return (INT_PTR
)FALSE
;