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.
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"
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
)
53 // CTortoiseGitBlameApp construction
55 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
58 CCrashReportTGit
crasher(L
"TortoiseGitBlame " _T(APP_X64_STRING
));
59 CCrashReport::Instance().AddUserInfoToReport(L
"CommandLine", GetCommandLine());
62 m_gdiplusToken
= NULL
;
63 m_bHiColorIcons
= TRUE
;
66 // The one and only CTortoiseGitBlameApp object
67 CTortoiseGitBlameApp theApp
;
70 // CTortoiseGitBlameApp initialization
72 BOOL
CTortoiseGitBlameApp::InitInstance()
75 DWORD len
= GetCurrentDirectory(0, NULL
);
78 auto_buffer
<TCHAR
> originalCurrentDirectory(len
);
79 if (GetCurrentDirectory(len
, originalCurrentDirectory
))
81 sOrigCWD
= originalCurrentDirectory
;
82 sOrigCWD
= CPathUtils::GetLongPathname(sOrigCWD
);
87 //set the resource dll for the required language
88 CRegDWORD loc
= CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
91 HINSTANCE hInst
= NULL
;
94 langDll
.Format(_T("%sLanguages\\TortoiseGitBlame%d.dll"), (LPCTSTR
)CPathUtils::GetAppParentDirectory(), langId
);
96 hInst
= LoadLibrary(langDll
);
97 CString sVer
= _T(STRPRODUCTVER
);
98 CString sFileVer
= CPathUtils::GetVersionFromFile(langDll
);
99 if (sFileVer
.Compare(sVer
)!=0)
105 AfxSetResourceHandle(hInst
);
108 DWORD lid
= SUBLANGID(langId
);
112 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
117 } while ((hInst
== NULL
) && (langId
!= 0));
119 _tcscpy_s(buf
, _T("en"));
122 sHelppath
= this->m_pszHelpFilePath
;
123 sHelppath
= sHelppath
.MakeLower();
124 sHelppath
.Replace(_T(".chm"), _T("_en.chm"));
125 free((void*)m_pszHelpFilePath
);
126 m_pszHelpFilePath
=_tcsdup(sHelppath
);
127 sHelppath
= CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
130 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO639LANGNAME
, buf
, _countof(buf
));
131 CString sLang
= _T("_");
133 sHelppath
.Replace(_T("_en"), sLang
);
134 if (PathFileExists(sHelppath
))
136 free((void*)m_pszHelpFilePath
);
137 m_pszHelpFilePath
=_tcsdup(sHelppath
);
140 sHelppath
.Replace(sLang
, _T("_en"));
141 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO3166CTRYNAME
, buf
, _countof(buf
));
144 sHelppath
.Replace(_T("_en"), sLang
);
145 if (PathFileExists(sHelppath
))
147 free((void*)m_pszHelpFilePath
);
148 m_pszHelpFilePath
=_tcsdup(sHelppath
);
151 sHelppath
.Replace(sLang
, _T("_en"));
153 DWORD lid
= SUBLANGID(langId
);
157 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
162 setlocale(LC_ALL
, "");
163 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
164 // The problems occures when the language of OS differs from the regional settings
165 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
166 SetThreadLocale(LOCALE_SYSTEM_DEFAULT
);
168 // InitCommonControlsEx() is required on Windows XP if an application
169 // manifest specifies use of ComCtl32.dll version 6 or later to enable
170 // visual styles. Otherwise, any window creation will fail.
171 INITCOMMONCONTROLSEX InitCtrls
;
172 InitCtrls
.dwSize
= sizeof(InitCtrls
);
173 // Set this to include all the common control classes you want to use
174 // in your application.
175 InitCtrls
.dwICC
= ICC_WIN95_CLASSES
;
176 InitCommonControlsEx(&InitCtrls
);
178 CWinAppEx::InitInstance();
180 Gdiplus::GdiplusStartupInput gdiplusStartupInput
;
181 Gdiplus::GdiplusStartup(&m_gdiplusToken
,&gdiplusStartupInput
,NULL
);
183 // Initialize OLE libraries
186 AfxMessageBox(IDP_OLE_INIT_FAILED
);
189 AfxEnableControlContainer();
190 // Standard initialization
191 // If you are not using these features and wish to reduce the size
192 // of your final executable, you should remove from the following
193 // the specific initialization routines you do not need
194 // Change the registry key under which our settings are stored
196 SetRegistryKey(_T("TortoiseGit"));
197 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
199 InitContextMenuManager();
201 InitKeyboardManager();
203 InitTooltipManager();
204 CMFCToolTipInfo ttParams
;
205 ttParams
.m_bVislManagerTheme
= TRUE
;
206 theApp
.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL
,
207 RUNTIME_CLASS(CMFCToolTipCtrl
), &ttParams
);
209 // Register the application's document templates. Document templates
210 // serve as the connection between documents, frame windows and views
211 CSingleDocTemplate
* pDocTemplate
;
212 pDocTemplate
= new CSingleDocTemplate(
213 IDR_TORTOISE_GIT_BLAME_MAINFRAME
,
214 RUNTIME_CLASS(CTortoiseGitBlameDoc
),
215 RUNTIME_CLASS(CMainFrame
), // main SDI frame window
216 RUNTIME_CLASS(CTortoiseGitBlameView
));
219 AddDocTemplate(pDocTemplate
);
223 // Parse command line for standard shell commands, DDE, file open
224 CCommandLineInfo cmdInfo
;
225 ParseCommandLine(cmdInfo
);
227 // Dispatch commands specified on the command line. Will return FALSE if
228 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
229 if (!ProcessShellCommand(cmdInfo
))
232 // The one and only window has been initialized, so show and update it
233 m_pMainWnd
->ShowWindow(SW_SHOW
);
234 m_pMainWnd
->UpdateWindow();
235 // call DragAcceptFiles only if there's a suffix
236 // In an SDI app, this should occur after ProcessShellCommand
240 // CAboutDlg dialog used for App About
242 class CAboutDlg
: public CDialog
248 enum { IDD
= IDD_ABOUTBOX
};
251 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
255 DECLARE_MESSAGE_MAP()
258 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
262 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
264 CDialog::DoDataExchange(pDX
);
267 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
270 BOOL
CAboutDlg::OnInitDialog()
272 CDialog::OnInitDialog();
274 TCHAR verbuf
[1024] = {0};
275 TCHAR maskbuf
[1024] = {0};
276 if (!::LoadString(GetModuleHandle(NULL
), IDS_VERSION
, maskbuf
, _countof(maskbuf
)))
278 SecureZeroMemory(maskbuf
, sizeof(maskbuf
));
280 _stprintf_s(verbuf
, maskbuf
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
281 SetDlgItemText(IDC_VERSION
, verbuf
);
286 // App command to run the dialog
287 void CTortoiseGitBlameApp::OnAppAbout()
293 void CTortoiseGitBlameApp::OnFileSettings()
295 CCommonAppUtils::RunTortoiseGitProc(_T(" /command:settings /page:blame"));
298 // CTortoiseGitBlameApp customization load/save methods
300 void CTortoiseGitBlameApp::PreLoadState()
302 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP
, IDR_BLAME_POPUP
);
305 void CTortoiseGitBlameApp::LoadCustomState()
309 void CTortoiseGitBlameApp::SaveCustomState()
313 // CTortoiseGitBlameApp message handlers
315 int CTortoiseGitBlameApp::ExitInstance()
317 Gdiplus::GdiplusShutdown(m_gdiplusToken
);
318 return CWinAppEx::ExitInstance();