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.
24 #include "afxwinappex.h"
25 #include "TortoiseGitBlame.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"
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
)
52 // CTortoiseGitBlameApp construction
54 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
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());
68 m_gdiplusToken
= NULL
;
69 m_bHiColorIcons
= TRUE
;
72 CTortoiseGitBlameApp::~CTortoiseGitBlameApp()
74 git_libgit2_shutdown();
77 // The one and only CTortoiseGitBlameApp object
78 CTortoiseGitBlameApp theApp
;
80 CString g_sGroupingUUID
;
81 CString g_sGroupingIcon
;
82 bool g_bGroupingRemoveIcon
= false;
84 // CTortoiseGitBlameApp initialization
86 BOOL
CTortoiseGitBlameApp::InitInstance()
89 DWORD len
= GetCurrentDirectory(0, NULL
);
92 std::unique_ptr
<TCHAR
[]> originalCurrentDirectory(new TCHAR
[len
]);
93 if (GetCurrentDirectory(len
, originalCurrentDirectory
.get()))
95 sOrigCWD
= originalCurrentDirectory
.get();
96 sOrigCWD
= CPathUtils::GetLongPathname(sOrigCWD
);
101 //set the resource dll for the required language
102 CRegDWORD loc
= CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
105 HINSTANCE hInst
= NULL
;
108 langDll
.Format(_T("%sLanguages\\TortoiseGitBlame%ld.dll"), (LPCTSTR
)CPathUtils::GetAppParentDirectory(), langId
);
110 hInst
= LoadLibrary(langDll
);
111 CString sVer
= _T(STRPRODUCTVER
);
112 CString sFileVer
= CPathUtils::GetVersionFromFile(langDll
);
113 if (sFileVer
.Compare(sVer
)!=0)
119 AfxSetResourceHandle(hInst
);
122 DWORD lid
= SUBLANGID(langId
);
126 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
131 } while ((hInst
== NULL
) && (langId
!= 0));
132 TCHAR buf
[6] = { 0 };
133 _tcscpy_s(buf
, _T("en"));
136 sHelppath
= this->m_pszHelpFilePath
;
137 sHelppath
= sHelppath
.MakeLower();
138 sHelppath
.Replace(_T(".chm"), _T("_en.chm"));
139 free((void*)m_pszHelpFilePath
);
140 m_pszHelpFilePath
=_tcsdup(sHelppath
);
141 sHelppath
= CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
144 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO639LANGNAME
, buf
, _countof(buf
));
145 CString sLang
= _T("_");
147 sHelppath
.Replace(_T("_en"), sLang
);
148 if (PathFileExists(sHelppath
))
150 free((void*)m_pszHelpFilePath
);
151 m_pszHelpFilePath
=_tcsdup(sHelppath
);
154 sHelppath
.Replace(sLang
, _T("_en"));
155 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO3166CTRYNAME
, buf
, _countof(buf
));
158 sHelppath
.Replace(_T("_en"), sLang
);
159 if (PathFileExists(sHelppath
))
161 free((void*)m_pszHelpFilePath
);
162 m_pszHelpFilePath
=_tcsdup(sHelppath
);
165 sHelppath
.Replace(sLang
, _T("_en"));
167 DWORD lid
= SUBLANGID(langId
);
171 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
176 setlocale(LC_ALL
, "");
177 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
178 // The problems occures when the language of OS differs from the regional settings
179 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
180 SetThreadLocale(LOCALE_SYSTEM_DEFAULT
);
182 // InitCommonControlsEx() is required on Windows XP if an application
183 // manifest specifies use of ComCtl32.dll version 6 or later to enable
184 // visual styles. Otherwise, any window creation will fail.
185 INITCOMMONCONTROLSEX InitCtrls
;
186 InitCtrls
.dwSize
= sizeof(InitCtrls
);
187 // Set this to include all the common control classes you want to use
188 // in your application.
189 InitCtrls
.dwICC
= ICC_WIN95_CLASSES
;
190 InitCommonControlsEx(&InitCtrls
);
192 CWinAppEx::InitInstance();
194 Gdiplus::GdiplusStartupInput gdiplusStartupInput
;
195 Gdiplus::GdiplusStartup(&m_gdiplusToken
,&gdiplusStartupInput
,NULL
);
197 // Initialize OLE libraries
200 AfxMessageBox(IDP_OLE_INIT_FAILED
);
203 AfxEnableControlContainer();
204 // Standard initialization
205 // If you are not using these features and wish to reduce the size
206 // of your final executable, you should remove from the following
207 // the specific initialization routines you do not need
208 // Change the registry key under which our settings are stored
210 SetRegistryKey(_T("TortoiseGit"));
211 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
213 InitContextMenuManager();
215 InitKeyboardManager();
217 InitTooltipManager();
218 CMFCToolTipInfo ttParams
;
219 ttParams
.m_bVislManagerTheme
= TRUE
;
220 theApp
.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL
,
221 RUNTIME_CLASS(CMFCToolTipCtrl
), &ttParams
);
223 // Register the application's document templates. Document templates
224 // serve as the connection between documents, frame windows and views
225 CSingleDocTemplate
* pDocTemplate
;
226 pDocTemplate
= new CSingleDocTemplate(
227 IDR_TORTOISE_GIT_BLAME_MAINFRAME
,
228 RUNTIME_CLASS(CTortoiseGitBlameDoc
),
229 RUNTIME_CLASS(CMainFrame
), // main SDI frame window
230 RUNTIME_CLASS(CTortoiseGitBlameView
));
233 AddDocTemplate(pDocTemplate
);
235 CCmdLineParser parser
= CCmdLineParser(this->m_lpCmdLine
);
236 g_sGroupingUUID
= parser
.GetVal(L
"groupuuid");
238 // Parse command line for standard shell commands, DDE, file open
239 CCommandLineInfo cmdInfo
;
240 ParseCommandLine(cmdInfo
);
242 // Dispatch commands specified on the command line. Will return FALSE if
243 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
244 if (!ProcessShellCommand(cmdInfo
))
247 // The one and only window has been initialized, so show and update it
248 m_pMainWnd
->ShowWindow(SW_SHOW
);
249 m_pMainWnd
->UpdateWindow();
250 // call DragAcceptFiles only if there's a suffix
251 // In an SDI app, this should occur after ProcessShellCommand
255 // CAboutDlg dialog used for App About
257 class CAboutDlg
: public CDialog
263 enum { IDD
= IDD_ABOUTBOX
};
266 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
270 DECLARE_MESSAGE_MAP()
273 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
277 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
279 CDialog::DoDataExchange(pDX
);
282 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
285 BOOL
CAboutDlg::OnInitDialog()
287 CDialog::OnInitDialog();
289 TCHAR verbuf
[1024] = {0};
290 TCHAR maskbuf
[1024] = {0};
291 ::LoadString(GetModuleHandle(NULL
), IDS_VERSION
, maskbuf
, _countof(maskbuf
));
292 _stprintf_s(verbuf
, maskbuf
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
293 SetDlgItemText(IDC_VERSION
, verbuf
);
298 // App command to run the dialog
299 void CTortoiseGitBlameApp::OnAppAbout()
305 void CTortoiseGitBlameApp::OnFileSettings()
307 CCommonAppUtils::RunTortoiseGitProc(_T(" /command:settings /page:blame"));
310 // CTortoiseGitBlameApp customization load/save methods
312 void CTortoiseGitBlameApp::PreLoadState()
316 void CTortoiseGitBlameApp::LoadCustomState()
320 void CTortoiseGitBlameApp::SaveCustomState()
324 // CTortoiseGitBlameApp message handlers
326 int CTortoiseGitBlameApp::ExitInstance()
328 Gdiplus::GdiplusShutdown(m_gdiplusToken
);
329 return CWinAppEx::ExitInstance();