GitProcessList: Add success/failure info when finish command
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blobf9653942b9dba90ca4332f5c37ffad725706fb6c
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 // TortoiseGitBlame.cpp : Defines the class behaviors for the application.
23 #include "stdafx.h"
24 #include "afxwinappex.h"
25 #include "TortoiseGitBlame.h"
26 #include "MainFrm.h"
27 #include "../version.h"
28 #include "../Utils/CrashReport.h"
30 #include "TortoiseGitBlameDoc.h"
31 #include "TortoiseGitBlameView.h"
32 #include "CmdLineParser.h"
33 #include "PathUtils.h"
34 #include "CommonAppUtils.h"
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #endif
41 // CTortoiseGitBlameApp
43 BEGIN_MESSAGE_MAP(CTortoiseGitBlameApp, CWinAppEx)
44 ON_COMMAND(ID_APP_ABOUT, &CTortoiseGitBlameApp::OnAppAbout)
45 // Standard file based document commands
46 ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
47 ON_COMMAND(ID_FILE_SETTINGS, &CTortoiseGitBlameApp::OnFileSettings)
48 // Standard print setup command
49 ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
50 END_MESSAGE_MAP()
53 // CTortoiseGitBlameApp construction
55 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
57 SetDllDirectory(L"");
58 // prevent from inheriting %GIT_DIR% from parent process by resetting it,
59 // use MSVC function instead of Windows API because MSVC runtime caches environment variables
60 _tputenv(_T("GIT_DIR="));
61 CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
62 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
63 EnableHtmlHelp();
65 m_gdiplusToken = NULL;
66 m_bHiColorIcons = TRUE;
69 // The one and only CTortoiseGitBlameApp object
70 CTortoiseGitBlameApp theApp;
71 CString sOrigCWD;
73 // CTortoiseGitBlameApp initialization
75 BOOL CTortoiseGitBlameApp::InitInstance()
78 DWORD len = GetCurrentDirectory(0, NULL);
79 if (len)
81 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
82 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
84 sOrigCWD = originalCurrentDirectory.get();
85 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
90 //set the resource dll for the required language
91 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
92 long langId = loc;
93 CString langDll;
94 HINSTANCE hInst = NULL;
97 langDll.Format(_T("%sLanguages\\TortoiseGitBlame%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
99 hInst = LoadLibrary(langDll);
100 CString sVer = _T(STRPRODUCTVER);
101 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
102 if (sFileVer.Compare(sVer)!=0)
104 FreeLibrary(hInst);
105 hInst = NULL;
107 if (hInst != NULL)
108 AfxSetResourceHandle(hInst);
109 else
111 DWORD lid = SUBLANGID(langId);
112 lid--;
113 if (lid > 0)
115 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
117 else
118 langId = 0;
120 } while ((hInst == NULL) && (langId != 0));
121 TCHAR buf[6];
122 _tcscpy_s(buf, _T("en"));
123 langId = loc;
124 CString sHelppath;
125 sHelppath = this->m_pszHelpFilePath;
126 sHelppath = sHelppath.MakeLower();
127 sHelppath.Replace(_T(".chm"), _T("_en.chm"));
128 free((void*)m_pszHelpFilePath);
129 m_pszHelpFilePath=_tcsdup(sHelppath);
130 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
133 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf));
134 CString sLang = _T("_");
135 sLang += buf;
136 sHelppath.Replace(_T("_en"), sLang);
137 if (PathFileExists(sHelppath))
139 free((void*)m_pszHelpFilePath);
140 m_pszHelpFilePath=_tcsdup(sHelppath);
141 break;
143 sHelppath.Replace(sLang, _T("_en"));
144 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf));
145 sLang += _T("_");
146 sLang += buf;
147 sHelppath.Replace(_T("_en"), sLang);
148 if (PathFileExists(sHelppath))
150 free((void*)m_pszHelpFilePath);
151 m_pszHelpFilePath=_tcsdup(sHelppath);
152 break;
154 sHelppath.Replace(sLang, _T("_en"));
156 DWORD lid = SUBLANGID(langId);
157 lid--;
158 if (lid > 0)
160 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
162 else
163 langId = 0;
164 } while (langId);
165 setlocale(LC_ALL, "");
166 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
167 // The problems occures when the language of OS differs from the regional settings
168 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
169 SetThreadLocale(LOCALE_SYSTEM_DEFAULT);
171 // InitCommonControlsEx() is required on Windows XP if an application
172 // manifest specifies use of ComCtl32.dll version 6 or later to enable
173 // visual styles. Otherwise, any window creation will fail.
174 INITCOMMONCONTROLSEX InitCtrls;
175 InitCtrls.dwSize = sizeof(InitCtrls);
176 // Set this to include all the common control classes you want to use
177 // in your application.
178 InitCtrls.dwICC = ICC_WIN95_CLASSES;
179 InitCommonControlsEx(&InitCtrls);
181 CWinAppEx::InitInstance();
183 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
184 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
186 // Initialize OLE libraries
187 if (!AfxOleInit())
189 AfxMessageBox(IDP_OLE_INIT_FAILED);
190 return FALSE;
192 AfxEnableControlContainer();
193 // Standard initialization
194 // If you are not using these features and wish to reduce the size
195 // of your final executable, you should remove from the following
196 // the specific initialization routines you do not need
197 // Change the registry key under which our settings are stored
199 SetRegistryKey(_T("TortoiseGit"));
200 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
202 InitContextMenuManager();
204 InitKeyboardManager();
206 InitTooltipManager();
207 CMFCToolTipInfo ttParams;
208 ttParams.m_bVislManagerTheme = TRUE;
209 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
210 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
212 // Register the application's document templates. Document templates
213 // serve as the connection between documents, frame windows and views
214 CSingleDocTemplate* pDocTemplate;
215 pDocTemplate = new CSingleDocTemplate(
216 IDR_TORTOISE_GIT_BLAME_MAINFRAME,
217 RUNTIME_CLASS(CTortoiseGitBlameDoc),
218 RUNTIME_CLASS(CMainFrame), // main SDI frame window
219 RUNTIME_CLASS(CTortoiseGitBlameView));
220 if (!pDocTemplate)
221 return FALSE;
222 AddDocTemplate(pDocTemplate);
226 // Parse command line for standard shell commands, DDE, file open
227 CCommandLineInfo cmdInfo;
228 ParseCommandLine(cmdInfo);
230 // Dispatch commands specified on the command line. Will return FALSE if
231 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
232 if (!ProcessShellCommand(cmdInfo))
233 return FALSE;
235 // The one and only window has been initialized, so show and update it
236 m_pMainWnd->ShowWindow(SW_SHOW);
237 m_pMainWnd->UpdateWindow();
238 // call DragAcceptFiles only if there's a suffix
239 // In an SDI app, this should occur after ProcessShellCommand
240 return TRUE;
243 // CAboutDlg dialog used for App About
245 class CAboutDlg : public CDialog
247 public:
248 CAboutDlg();
250 // Dialog Data
251 enum { IDD = IDD_ABOUTBOX };
253 protected:
254 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
255 BOOL OnInitDialog();
257 // Implementation
258 DECLARE_MESSAGE_MAP()
261 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
265 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
267 CDialog::DoDataExchange(pDX);
270 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
271 END_MESSAGE_MAP()
273 BOOL CAboutDlg::OnInitDialog()
275 CDialog::OnInitDialog();
277 TCHAR verbuf[1024] = {0};
278 TCHAR maskbuf[1024] = {0};
279 if (!::LoadString(GetModuleHandle(NULL), IDS_VERSION, maskbuf, _countof(maskbuf)))
281 SecureZeroMemory(maskbuf, sizeof(maskbuf));
283 _stprintf_s(verbuf, maskbuf, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD);
284 SetDlgItemText(IDC_VERSION, verbuf);
286 return FALSE;
289 // App command to run the dialog
290 void CTortoiseGitBlameApp::OnAppAbout()
292 CAboutDlg aboutDlg;
293 aboutDlg.DoModal();
296 void CTortoiseGitBlameApp::OnFileSettings()
298 CCommonAppUtils::RunTortoiseGitProc(_T(" /command:settings /page:blame"));
301 // CTortoiseGitBlameApp customization load/save methods
303 void CTortoiseGitBlameApp::PreLoadState()
305 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP, IDR_BLAME_POPUP);
308 void CTortoiseGitBlameApp::LoadCustomState()
312 void CTortoiseGitBlameApp::SaveCustomState()
316 // CTortoiseGitBlameApp message handlers
318 int CTortoiseGitBlameApp::ExitInstance()
320 Gdiplus::GdiplusShutdown(m_gdiplusToken);
321 return CWinAppEx::ExitInstance();