CrashServer: integrate crash handler into TortoiseGitBlame
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blobc0a158b73e790385793e11e1da38300dc55c4afd
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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 CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING));
59 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
60 EnableHtmlHelp();
62 m_bHiColorIcons = TRUE;
65 // The one and only CTortoiseGitBlameApp object
66 CTortoiseGitBlameApp theApp;
67 CString sOrigCWD;
69 // CTortoiseGitBlameApp initialization
71 BOOL CTortoiseGitBlameApp::InitInstance()
74 DWORD len = GetCurrentDirectory(0, NULL);
75 if (len)
77 auto_buffer<TCHAR> originalCurrentDirectory(len);
78 if (GetCurrentDirectory(len, originalCurrentDirectory))
80 sOrigCWD = originalCurrentDirectory;
81 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
86 //set the resource dll for the required language
87 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
88 long langId = loc;
89 CString langDll;
90 HINSTANCE hInst = NULL;
93 langDll.Format(_T("%sLanguages\\TortoiseGitBlame%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
95 hInst = LoadLibrary(langDll);
96 CString sVer = _T(STRPRODUCTVER);
97 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
98 if (sFileVer.Compare(sVer)!=0)
100 FreeLibrary(hInst);
101 hInst = NULL;
103 if (hInst != NULL)
104 AfxSetResourceHandle(hInst);
105 else
107 DWORD lid = SUBLANGID(langId);
108 lid--;
109 if (lid > 0)
111 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
113 else
114 langId = 0;
116 } while ((hInst == NULL) && (langId != 0));
117 TCHAR buf[6];
118 _tcscpy_s(buf, _T("en"));
119 langId = loc;
120 CString sHelppath;
121 sHelppath = this->m_pszHelpFilePath;
122 sHelppath = sHelppath.MakeLower();
123 sHelppath.Replace(_T(".chm"), _T("_en.chm"));
124 free((void*)m_pszHelpFilePath);
125 m_pszHelpFilePath=_tcsdup(sHelppath);
126 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
129 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf));
130 CString sLang = _T("_");
131 sLang += buf;
132 sHelppath.Replace(_T("_en"), sLang);
133 if (PathFileExists(sHelppath))
135 free((void*)m_pszHelpFilePath);
136 m_pszHelpFilePath=_tcsdup(sHelppath);
137 break;
139 sHelppath.Replace(sLang, _T("_en"));
140 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf));
141 sLang += _T("_");
142 sLang += buf;
143 sHelppath.Replace(_T("_en"), sLang);
144 if (PathFileExists(sHelppath))
146 free((void*)m_pszHelpFilePath);
147 m_pszHelpFilePath=_tcsdup(sHelppath);
148 break;
150 sHelppath.Replace(sLang, _T("_en"));
152 DWORD lid = SUBLANGID(langId);
153 lid--;
154 if (lid > 0)
156 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
158 else
159 langId = 0;
160 } while (langId);
161 setlocale(LC_ALL, "");
162 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
163 // The problems occures when the language of OS differs from the regional settings
164 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
165 SetThreadLocale(LOCALE_SYSTEM_DEFAULT);
167 // InitCommonControlsEx() is required on Windows XP if an application
168 // manifest specifies use of ComCtl32.dll version 6 or later to enable
169 // visual styles. Otherwise, any window creation will fail.
170 INITCOMMONCONTROLSEX InitCtrls;
171 InitCtrls.dwSize = sizeof(InitCtrls);
172 // Set this to include all the common control classes you want to use
173 // in your application.
174 InitCtrls.dwICC = ICC_WIN95_CLASSES;
175 InitCommonControlsEx(&InitCtrls);
177 CWinAppEx::InitInstance();
179 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
180 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
182 // Initialize OLE libraries
183 if (!AfxOleInit())
185 AfxMessageBox(IDP_OLE_INIT_FAILED);
186 return FALSE;
188 AfxEnableControlContainer();
189 // Standard initialization
190 // If you are not using these features and wish to reduce the size
191 // of your final executable, you should remove from the following
192 // the specific initialization routines you do not need
193 // Change the registry key under which our settings are stored
195 SetRegistryKey(_T("TortoiseGit"));
196 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
198 InitContextMenuManager();
200 InitKeyboardManager();
202 InitTooltipManager();
203 CMFCToolTipInfo ttParams;
204 ttParams.m_bVislManagerTheme = TRUE;
205 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
206 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
208 // Register the application's document templates. Document templates
209 // serve as the connection between documents, frame windows and views
210 CSingleDocTemplate* pDocTemplate;
211 pDocTemplate = new CSingleDocTemplate(
212 IDR_TORTOISE_GIT_BLAME_MAINFRAME,
213 RUNTIME_CLASS(CTortoiseGitBlameDoc),
214 RUNTIME_CLASS(CMainFrame), // main SDI frame window
215 RUNTIME_CLASS(CTortoiseGitBlameView));
216 if (!pDocTemplate)
217 return FALSE;
218 AddDocTemplate(pDocTemplate);
222 // Parse command line for standard shell commands, DDE, file open
223 CCommandLineInfo cmdInfo;
224 ParseCommandLine(cmdInfo);
226 // Dispatch commands specified on the command line. Will return FALSE if
227 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
228 if (!ProcessShellCommand(cmdInfo))
229 return FALSE;
231 // The one and only window has been initialized, so show and update it
232 m_pMainWnd->ShowWindow(SW_SHOW);
233 m_pMainWnd->UpdateWindow();
234 // call DragAcceptFiles only if there's a suffix
235 // In an SDI app, this should occur after ProcessShellCommand
236 return TRUE;
239 // CAboutDlg dialog used for App About
241 class CAboutDlg : public CDialog
243 public:
244 CAboutDlg();
246 // Dialog Data
247 enum { IDD = IDD_ABOUTBOX };
249 protected:
250 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
251 BOOL OnInitDialog();
253 // Implementation
254 DECLARE_MESSAGE_MAP()
257 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
261 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
263 CDialog::DoDataExchange(pDX);
266 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
267 END_MESSAGE_MAP()
269 BOOL CAboutDlg::OnInitDialog()
271 CDialog::OnInitDialog();
273 TCHAR verbuf[1024] = {0};
274 TCHAR maskbuf[1024] = {0};
275 if (!::LoadString(GetModuleHandle(NULL), IDS_VERSION, maskbuf, _countof(maskbuf)))
277 SecureZeroMemory(maskbuf, sizeof(maskbuf));
279 _stprintf_s(verbuf, maskbuf, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD);
280 SetDlgItemText(IDC_VERSION, verbuf);
282 return FALSE;
285 // App command to run the dialog
286 void CTortoiseGitBlameApp::OnAppAbout()
288 CAboutDlg aboutDlg;
289 aboutDlg.DoModal();
292 void CTortoiseGitBlameApp::OnFileSettings()
294 CCommonAppUtils::RunTortoiseProc(_T(" /command:settings /page:blame"));
297 // CTortoiseGitBlameApp customization load/save methods
299 void CTortoiseGitBlameApp::PreLoadState()
301 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP, IDR_BLAME_POPUP);
304 void CTortoiseGitBlameApp::LoadCustomState()
308 void CTortoiseGitBlameApp::SaveCustomState()
312 // CTortoiseGitBlameApp message handlers
314 int CTortoiseGitBlameApp::ExitInstance()
316 Gdiplus::GdiplusShutdown(m_gdiplusToken);
317 return CWinAppEx::ExitInstance();