Do not quit TortoiseGitProc after running Bisect Start from log list
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blob373a41aeb9faecb4be830a0fbb128dcba5dce238
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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"
35 #include "TaskbarUUID.h"
37 #ifdef _DEBUG
38 #define new DEBUG_NEW
39 #endif
42 // CTortoiseGitBlameApp
44 BEGIN_MESSAGE_MAP(CTortoiseGitBlameApp, CWinAppEx)
45 ON_COMMAND(ID_APP_ABOUT, &CTortoiseGitBlameApp::OnAppAbout)
46 // Standard file based document commands
47 ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
48 ON_COMMAND(ID_FILE_SETTINGS, &CTortoiseGitBlameApp::OnFileSettings)
49 END_MESSAGE_MAP()
52 // CTortoiseGitBlameApp construction
54 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
56 SetDllDirectory(L"");
57 SetTaskIDPerUUID();
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 #if ENABLE_CRASHHANLDER
62 CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
63 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
64 #endif
65 EnableHtmlHelp();
67 m_nAppLook = 0;
68 m_gdiplusToken = NULL;
69 m_bHiColorIcons = TRUE;
72 // The one and only CTortoiseGitBlameApp object
73 CTortoiseGitBlameApp theApp;
74 CString sOrigCWD;
75 CString g_sGroupingUUID;
76 CString g_sGroupingIcon;
77 bool g_bGroupingRemoveIcon = false;
79 // CTortoiseGitBlameApp initialization
81 BOOL CTortoiseGitBlameApp::InitInstance()
84 DWORD len = GetCurrentDirectory(0, NULL);
85 if (len)
87 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
88 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
90 sOrigCWD = originalCurrentDirectory.get();
91 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
96 //set the resource dll for the required language
97 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
98 long langId = loc;
99 CString langDll;
100 HINSTANCE hInst = NULL;
103 langDll.Format(_T("%sLanguages\\TortoiseGitBlame%ld.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
105 hInst = LoadLibrary(langDll);
106 CString sVer = _T(STRPRODUCTVER);
107 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
108 if (sFileVer.Compare(sVer)!=0)
110 FreeLibrary(hInst);
111 hInst = NULL;
113 if (hInst != NULL)
114 AfxSetResourceHandle(hInst);
115 else
117 DWORD lid = SUBLANGID(langId);
118 lid--;
119 if (lid > 0)
121 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
123 else
124 langId = 0;
126 } while ((hInst == NULL) && (langId != 0));
127 TCHAR buf[6] = { 0 };
128 _tcscpy_s(buf, _T("en"));
129 langId = loc;
130 CString sHelppath;
131 sHelppath = this->m_pszHelpFilePath;
132 sHelppath = sHelppath.MakeLower();
133 sHelppath.Replace(_T(".chm"), _T("_en.chm"));
134 free((void*)m_pszHelpFilePath);
135 m_pszHelpFilePath=_tcsdup(sHelppath);
136 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
139 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf));
140 CString sLang = _T("_");
141 sLang += buf;
142 sHelppath.Replace(_T("_en"), sLang);
143 if (PathFileExists(sHelppath))
145 free((void*)m_pszHelpFilePath);
146 m_pszHelpFilePath=_tcsdup(sHelppath);
147 break;
149 sHelppath.Replace(sLang, _T("_en"));
150 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf));
151 sLang += _T("_");
152 sLang += buf;
153 sHelppath.Replace(_T("_en"), sLang);
154 if (PathFileExists(sHelppath))
156 free((void*)m_pszHelpFilePath);
157 m_pszHelpFilePath=_tcsdup(sHelppath);
158 break;
160 sHelppath.Replace(sLang, _T("_en"));
162 DWORD lid = SUBLANGID(langId);
163 lid--;
164 if (lid > 0)
166 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
168 else
169 langId = 0;
170 } while (langId);
171 setlocale(LC_ALL, "");
172 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
173 // The problems occures when the language of OS differs from the regional settings
174 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
175 SetThreadLocale(LOCALE_SYSTEM_DEFAULT);
177 // InitCommonControlsEx() is required on Windows XP if an application
178 // manifest specifies use of ComCtl32.dll version 6 or later to enable
179 // visual styles. Otherwise, any window creation will fail.
180 INITCOMMONCONTROLSEX InitCtrls;
181 InitCtrls.dwSize = sizeof(InitCtrls);
182 // Set this to include all the common control classes you want to use
183 // in your application.
184 InitCtrls.dwICC = ICC_WIN95_CLASSES;
185 InitCommonControlsEx(&InitCtrls);
187 CWinAppEx::InitInstance();
189 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
190 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
192 // Initialize OLE libraries
193 if (!AfxOleInit())
195 AfxMessageBox(IDP_OLE_INIT_FAILED);
196 return FALSE;
198 AfxEnableControlContainer();
199 // Standard initialization
200 // If you are not using these features and wish to reduce the size
201 // of your final executable, you should remove from the following
202 // the specific initialization routines you do not need
203 // Change the registry key under which our settings are stored
205 SetRegistryKey(_T("TortoiseGit"));
206 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
208 InitContextMenuManager();
210 InitKeyboardManager();
212 InitTooltipManager();
213 CMFCToolTipInfo ttParams;
214 ttParams.m_bVislManagerTheme = TRUE;
215 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
216 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
218 // Register the application's document templates. Document templates
219 // serve as the connection between documents, frame windows and views
220 CSingleDocTemplate* pDocTemplate;
221 pDocTemplate = new CSingleDocTemplate(
222 IDR_TORTOISE_GIT_BLAME_MAINFRAME,
223 RUNTIME_CLASS(CTortoiseGitBlameDoc),
224 RUNTIME_CLASS(CMainFrame), // main SDI frame window
225 RUNTIME_CLASS(CTortoiseGitBlameView));
226 if (!pDocTemplate)
227 return FALSE;
228 AddDocTemplate(pDocTemplate);
230 CCmdLineParser parser = CCmdLineParser(this->m_lpCmdLine);
231 g_sGroupingUUID = parser.GetVal(L"groupuuid");
233 // Parse command line for standard shell commands, DDE, file open
234 CCommandLineInfo cmdInfo;
235 ParseCommandLine(cmdInfo);
237 // Dispatch commands specified on the command line. Will return FALSE if
238 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
239 if (!ProcessShellCommand(cmdInfo))
240 return FALSE;
242 // The one and only window has been initialized, so show and update it
243 m_pMainWnd->ShowWindow(SW_SHOW);
244 m_pMainWnd->UpdateWindow();
245 // call DragAcceptFiles only if there's a suffix
246 // In an SDI app, this should occur after ProcessShellCommand
247 return TRUE;
250 // CAboutDlg dialog used for App About
252 class CAboutDlg : public CDialog
254 public:
255 CAboutDlg();
257 // Dialog Data
258 enum { IDD = IDD_ABOUTBOX };
260 protected:
261 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
262 BOOL OnInitDialog();
264 // Implementation
265 DECLARE_MESSAGE_MAP()
268 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
272 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
274 CDialog::DoDataExchange(pDX);
277 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
278 END_MESSAGE_MAP()
280 BOOL CAboutDlg::OnInitDialog()
282 CDialog::OnInitDialog();
284 TCHAR verbuf[1024] = {0};
285 TCHAR maskbuf[1024] = {0};
286 ::LoadString(GetModuleHandle(NULL), IDS_VERSION, maskbuf, _countof(maskbuf));
287 _stprintf_s(verbuf, maskbuf, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD);
288 SetDlgItemText(IDC_VERSION, verbuf);
290 return FALSE;
293 // App command to run the dialog
294 void CTortoiseGitBlameApp::OnAppAbout()
296 CAboutDlg aboutDlg;
297 aboutDlg.DoModal();
300 void CTortoiseGitBlameApp::OnFileSettings()
302 CCommonAppUtils::RunTortoiseGitProc(_T(" /command:settings /page:blame"));
305 // CTortoiseGitBlameApp customization load/save methods
307 void CTortoiseGitBlameApp::PreLoadState()
311 void CTortoiseGitBlameApp::LoadCustomState()
315 void CTortoiseGitBlameApp::SaveCustomState()
319 // CTortoiseGitBlameApp message handlers
321 int CTortoiseGitBlameApp::ExitInstance()
323 Gdiplus::GdiplusShutdown(m_gdiplusToken);
324 return CWinAppEx::ExitInstance();