TortoiseGitBlame: Drop application styling code
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blob3e0931a03a05f5c3cb21a484740f4cd33d821c70
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 CWinAppEx::InitInstance();
193 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
194 Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, nullptr);
196 // Initialize OLE libraries
197 if (!AfxOleInit())
199 AfxMessageBox(IDP_OLE_INIT_FAILED);
200 return FALSE;
202 AfxEnableControlContainer();
203 // Standard initialization
204 // If you are not using these features and wish to reduce the size
205 // of your final executable, you should remove from the following
206 // the specific initialization routines you do not need
207 // Change the registry key under which our settings are stored
209 SetRegistryKey(L"TortoiseGit");
210 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
212 InitContextMenuManager();
214 InitKeyboardManager();
216 InitTooltipManager();
217 CMFCToolTipInfo ttParams;
218 ttParams.m_bVislManagerTheme = TRUE;
219 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
220 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
222 // Register the application's document templates. Document templates
223 // serve as the connection between documents, frame windows and views
224 CSingleDocTemplate* pDocTemplate;
225 pDocTemplate = new CSingleDocTemplate(
226 IDR_TORTOISE_GIT_BLAME_MAINFRAME,
227 RUNTIME_CLASS(CTortoiseGitBlameDoc),
228 RUNTIME_CLASS(CMainFrame), // main SDI frame window
229 RUNTIME_CLASS(CTortoiseGitBlameView));
230 if (!pDocTemplate)
231 return FALSE;
232 AddDocTemplate(pDocTemplate);
234 CCmdLineParser parser(m_lpCmdLine);
235 g_sGroupingUUID = parser.GetVal(L"groupuuid");
237 // Parse command line for standard shell commands, DDE, file open
238 CCommandLineInfo cmdInfo;
239 ParseCommandLine(cmdInfo);
241 // Dispatch commands specified on the command line. Will return FALSE if
242 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
243 if (!ProcessShellCommand(cmdInfo))
244 return FALSE;
246 // The one and only window has been initialized, so show and update it
247 m_pMainWnd->ShowWindow(SW_SHOW);
248 m_pMainWnd->UpdateWindow();
249 // call DragAcceptFiles only if there's a suffix
250 // In an SDI app, this should occur after ProcessShellCommand
251 return TRUE;
254 // CAboutDlg dialog used for App About
256 class CAboutDlg : public CDialog
258 public:
259 CAboutDlg();
261 // Dialog Data
262 enum { IDD = IDD_ABOUTBOX };
264 protected:
265 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
266 BOOL OnInitDialog();
268 // Implementation
269 DECLARE_MESSAGE_MAP()
272 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
276 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
278 CDialog::DoDataExchange(pDX);
281 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
282 END_MESSAGE_MAP()
284 BOOL CAboutDlg::OnInitDialog()
286 CDialog::OnInitDialog();
288 TCHAR verbuf[1024] = {0};
289 TCHAR maskbuf[1024] = {0};
290 ::LoadString(GetModuleHandle(nullptr), IDS_VERSION, maskbuf, _countof(maskbuf));
291 swprintf_s(verbuf, maskbuf, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD);
292 SetDlgItemText(IDC_VERSION, verbuf);
294 SetDlgItemText(IDC_COPYRIGHT, CPathUtils::GetCopyrightForSelf());
295 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>");
297 return FALSE;
300 // App command to run the dialog
301 void CTortoiseGitBlameApp::OnAppAbout()
303 CAboutDlg aboutDlg;
304 aboutDlg.DoModal();
307 void CTortoiseGitBlameApp::OnFileSettings()
309 CCommonAppUtils::RunTortoiseGitProc(L" /command:settings /page:blame");
312 // CTortoiseGitBlameApp customization load/save methods
314 void CTortoiseGitBlameApp::PreLoadState()
318 void CTortoiseGitBlameApp::LoadCustomState()
322 void CTortoiseGitBlameApp::SaveCustomState()
326 // CTortoiseGitBlameApp message handlers
328 int CTortoiseGitBlameApp::ExitInstance()
330 Gdiplus::GdiplusShutdown(m_gdiplusToken);
331 return CWinAppEx::ExitInstance();