Fixed issue #3184: Commiting asks for user data although they are set via includeif
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blob67ea9a5701d77fe3b3f21547d2c55ec082994515
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - 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 #if ENABLE_CRASHHANLDER
59 CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
60 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
61 #endif
62 EnableHtmlHelp();
63 git_libgit2_init();
64 m_gdiplusToken = NULL;
65 m_bHiColorIcons = TRUE;
68 CTortoiseGitBlameApp::~CTortoiseGitBlameApp()
70 git_libgit2_shutdown();
73 // The one and only CTortoiseGitBlameApp object
74 CTortoiseGitBlameApp theApp;
75 CString sOrigCWD;
76 CString g_sGroupingUUID;
77 CString g_sGroupingIcon;
78 bool g_bGroupingRemoveIcon = false;
80 // CTortoiseGitBlameApp initialization
82 BOOL CTortoiseGitBlameApp::InitInstance()
85 DWORD len = GetCurrentDirectory(0, nullptr);
86 if (len)
88 auto originalCurrentDirectory = std::make_unique<TCHAR[]>(len);
89 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
91 sOrigCWD = originalCurrentDirectory.get();
92 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
97 //set the resource dll for the required language
98 CRegDWORD loc = CRegDWORD(L"Software\\TortoiseGit\\LanguageID", 1033);
99 long langId = loc;
100 CString langDll;
101 HINSTANCE hInst = nullptr;
104 langDll.Format(L"%sLanguages\\TortoiseGitBlame%ld.dll", (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
106 hInst = LoadLibrary(langDll);
107 CString sVer = _T(STRPRODUCTVER);
108 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
109 if (sFileVer.Compare(sVer)!=0)
111 FreeLibrary(hInst);
112 hInst = nullptr;
114 if (hInst)
115 AfxSetResourceHandle(hInst);
116 else
118 DWORD lid = SUBLANGID(langId);
119 lid--;
120 if (lid > 0)
122 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
124 else
125 langId = 0;
127 } while (!hInst && (langId != 0));
129 CString langStr;
130 langStr.Format(L"%ld", langId);
131 CCrashReport::Instance().AddUserInfoToReport(L"LanguageID", langStr);
133 TCHAR buf[6] = { 0 };
134 wcscpy_s(buf, L"en");
135 langId = loc;
136 CString sHelppath;
137 sHelppath = this->m_pszHelpFilePath;
138 sHelppath = sHelppath.MakeLower();
139 sHelppath.Replace(L".chm", L"_en.chm");
140 free((void*)m_pszHelpFilePath);
141 m_pszHelpFilePath=_wcsdup(sHelppath);
142 sHelppath = CPathUtils::GetAppParentDirectory() + L"Languages\\TortoiseGitBlame_en.chm";
145 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf));
146 CString sLang = L"_";
147 sLang += buf;
148 sHelppath.Replace(L"_en", sLang);
149 if (PathFileExists(sHelppath))
151 free((void*)m_pszHelpFilePath);
152 m_pszHelpFilePath=_wcsdup(sHelppath);
153 break;
155 sHelppath.Replace(sLang, L"_en");
156 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf));
157 sLang += L'_';
158 sLang += buf;
159 sHelppath.Replace(L"_en", sLang);
160 if (PathFileExists(sHelppath))
162 free((void*)m_pszHelpFilePath);
163 m_pszHelpFilePath=_wcsdup(sHelppath);
164 break;
166 sHelppath.Replace(sLang, L"_en");
168 DWORD lid = SUBLANGID(langId);
169 lid--;
170 if (lid > 0)
171 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
172 else
173 langId = 0;
174 } while (langId);
175 setlocale(LC_ALL, "");
176 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
177 // The problems occures when the language of OS differs from the regional settings
178 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
179 SetThreadLocale(LOCALE_SYSTEM_DEFAULT);
181 // InitCommonControlsEx() is required on Windows XP if an application
182 // manifest specifies use of ComCtl32.dll version 6 or later to enable
183 // visual styles. Otherwise, any window creation will fail.
184 INITCOMMONCONTROLSEX InitCtrls;
185 InitCtrls.dwSize = sizeof(InitCtrls);
186 // Set this to include all the common control classes you want to use
187 // in your application.
188 InitCtrls.dwICC = ICC_WIN95_CLASSES;
189 InitCommonControlsEx(&InitCtrls);
191 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
193 CWinAppEx::InitInstance();
195 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
196 Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, nullptr);
198 // Initialize OLE libraries
199 if (!AfxOleInit())
201 AfxMessageBox(IDP_OLE_INIT_FAILED);
202 return FALSE;
204 AfxEnableControlContainer();
205 // Standard initialization
206 // If you are not using these features and wish to reduce the size
207 // of your final executable, you should remove from the following
208 // the specific initialization routines you do not need
209 // Change the registry key under which our settings are stored
211 SetRegistryKey(L"TortoiseGit");
212 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
214 InitContextMenuManager();
216 InitKeyboardManager();
218 InitTooltipManager();
219 CMFCToolTipInfo ttParams;
220 ttParams.m_bVislManagerTheme = TRUE;
221 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
222 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
224 // Register the application's document templates. Document templates
225 // serve as the connection between documents, frame windows and views
226 CSingleDocTemplate* pDocTemplate;
227 pDocTemplate = new CSingleDocTemplate(
228 IDR_TORTOISE_GIT_BLAME_MAINFRAME,
229 RUNTIME_CLASS(CTortoiseGitBlameDoc),
230 RUNTIME_CLASS(CMainFrame), // main SDI frame window
231 RUNTIME_CLASS(CTortoiseGitBlameView));
232 if (!pDocTemplate)
233 return FALSE;
234 AddDocTemplate(pDocTemplate);
236 CCmdLineParser parser(m_lpCmdLine);
237 g_sGroupingUUID = parser.GetVal(L"groupuuid");
239 // Parse command line for standard shell commands, DDE, file open
240 CCommandLineInfo cmdInfo;
241 ParseCommandLine(cmdInfo);
243 // Dispatch commands specified on the command line. Will return FALSE if
244 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
245 if (!ProcessShellCommand(cmdInfo))
246 return FALSE;
248 // The one and only window has been initialized, so show and update it
249 m_pMainWnd->ShowWindow(SW_SHOW);
250 m_pMainWnd->UpdateWindow();
251 // call DragAcceptFiles only if there's a suffix
252 // In an SDI app, this should occur after ProcessShellCommand
253 return TRUE;
256 // CAboutDlg dialog used for App About
258 class CAboutDlg : public CDialog
260 public:
261 CAboutDlg();
263 // Dialog Data
264 enum { IDD = IDD_ABOUTBOX };
266 protected:
267 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
268 BOOL OnInitDialog();
270 // Implementation
271 DECLARE_MESSAGE_MAP()
274 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
278 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
280 CDialog::DoDataExchange(pDX);
283 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
284 END_MESSAGE_MAP()
286 BOOL CAboutDlg::OnInitDialog()
288 CDialog::OnInitDialog();
290 TCHAR verbuf[1024] = {0};
291 TCHAR maskbuf[1024] = {0};
292 ::LoadString(GetModuleHandle(nullptr), IDS_VERSION, maskbuf, _countof(maskbuf));
293 swprintf_s(verbuf, maskbuf, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD);
294 SetDlgItemText(IDC_VERSION, verbuf);
296 SetDlgItemText(IDC_COPYRIGHT, CPathUtils::GetCopyrightForSelf());
297 SetDlgItemText(IDC_STATIC_AUTHORS, L"Sven Strickroth <email@cs-ware.de> (Current Maintainer), Sup Yut Sum <ch3cooli@gmail.com>, Frank Li <lznuaa@gmail.com> and Martin Strauß <MStrauss@MuellerBBM-vas.de>");
299 return FALSE;
302 // App command to run the dialog
303 void CTortoiseGitBlameApp::OnAppAbout()
305 CAboutDlg aboutDlg;
306 aboutDlg.DoModal();
309 void CTortoiseGitBlameApp::OnFileSettings()
311 CCommonAppUtils::RunTortoiseGitProc(L" /command:settings /page:blame");
314 // CTortoiseGitBlameApp customization load/save methods
316 void CTortoiseGitBlameApp::PreLoadState()
320 void CTortoiseGitBlameApp::LoadCustomState()
324 void CTortoiseGitBlameApp::SaveCustomState()
328 // CTortoiseGitBlameApp message handlers
330 int CTortoiseGitBlameApp::ExitInstance()
332 Gdiplus::GdiplusShutdown(m_gdiplusToken);
333 return CWinAppEx::ExitInstance();