1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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 // 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 CCrashReportTGit
crasher(L
"TortoiseGitBlame " _T(APP_X64_STRING
), TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
, TGIT_VERDATE
);
62 CCrashReport::Instance().AddUserInfoToReport(L
"CommandLine", GetCommandLine());
65 m_gdiplusToken
= NULL
;
66 m_bHiColorIcons
= TRUE
;
69 // The one and only CTortoiseGitBlameApp object
70 CTortoiseGitBlameApp theApp
;
73 // CTortoiseGitBlameApp initialization
75 BOOL
CTortoiseGitBlameApp::InitInstance()
78 DWORD len
= GetCurrentDirectory(0, NULL
);
81 std::unique_ptr
<TCHAR
[]> originalCurrentDirectory(new TCHAR
[len
]);
82 if (GetCurrentDirectory(len
, originalCurrentDirectory
.get()))
84 sOrigCWD
= originalCurrentDirectory
.get();
85 sOrigCWD
= CPathUtils::GetLongPathname(sOrigCWD
);
90 //set the resource dll for the required language
91 CRegDWORD loc
= CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
94 HINSTANCE hInst
= NULL
;
97 langDll
.Format(_T("%sLanguages\\TortoiseGitBlame%d.dll"), (LPCTSTR
)CPathUtils::GetAppParentDirectory(), langId
);
99 hInst
= LoadLibrary(langDll
);
100 CString sVer
= _T(STRPRODUCTVER
);
101 CString sFileVer
= CPathUtils::GetVersionFromFile(langDll
);
102 if (sFileVer
.Compare(sVer
)!=0)
108 AfxSetResourceHandle(hInst
);
111 DWORD lid
= SUBLANGID(langId
);
115 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
120 } while ((hInst
== NULL
) && (langId
!= 0));
122 _tcscpy_s(buf
, _T("en"));
125 sHelppath
= this->m_pszHelpFilePath
;
126 sHelppath
= sHelppath
.MakeLower();
127 sHelppath
.Replace(_T(".chm"), _T("_en.chm"));
128 free((void*)m_pszHelpFilePath
);
129 m_pszHelpFilePath
=_tcsdup(sHelppath
);
130 sHelppath
= CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
133 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO639LANGNAME
, buf
, _countof(buf
));
134 CString sLang
= _T("_");
136 sHelppath
.Replace(_T("_en"), sLang
);
137 if (PathFileExists(sHelppath
))
139 free((void*)m_pszHelpFilePath
);
140 m_pszHelpFilePath
=_tcsdup(sHelppath
);
143 sHelppath
.Replace(sLang
, _T("_en"));
144 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO3166CTRYNAME
, buf
, _countof(buf
));
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"));
156 DWORD lid
= SUBLANGID(langId
);
160 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
165 setlocale(LC_ALL
, "");
166 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
167 // The problems occures when the language of OS differs from the regional settings
168 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
169 SetThreadLocale(LOCALE_SYSTEM_DEFAULT
);
171 // InitCommonControlsEx() is required on Windows XP if an application
172 // manifest specifies use of ComCtl32.dll version 6 or later to enable
173 // visual styles. Otherwise, any window creation will fail.
174 INITCOMMONCONTROLSEX InitCtrls
;
175 InitCtrls
.dwSize
= sizeof(InitCtrls
);
176 // Set this to include all the common control classes you want to use
177 // in your application.
178 InitCtrls
.dwICC
= ICC_WIN95_CLASSES
;
179 InitCommonControlsEx(&InitCtrls
);
181 CWinAppEx::InitInstance();
183 Gdiplus::GdiplusStartupInput gdiplusStartupInput
;
184 Gdiplus::GdiplusStartup(&m_gdiplusToken
,&gdiplusStartupInput
,NULL
);
186 // Initialize OLE libraries
189 AfxMessageBox(IDP_OLE_INIT_FAILED
);
192 AfxEnableControlContainer();
193 // Standard initialization
194 // If you are not using these features and wish to reduce the size
195 // of your final executable, you should remove from the following
196 // the specific initialization routines you do not need
197 // Change the registry key under which our settings are stored
199 SetRegistryKey(_T("TortoiseGit"));
200 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
202 InitContextMenuManager();
204 InitKeyboardManager();
206 InitTooltipManager();
207 CMFCToolTipInfo ttParams
;
208 ttParams
.m_bVislManagerTheme
= TRUE
;
209 theApp
.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL
,
210 RUNTIME_CLASS(CMFCToolTipCtrl
), &ttParams
);
212 // Register the application's document templates. Document templates
213 // serve as the connection between documents, frame windows and views
214 CSingleDocTemplate
* pDocTemplate
;
215 pDocTemplate
= new CSingleDocTemplate(
216 IDR_TORTOISE_GIT_BLAME_MAINFRAME
,
217 RUNTIME_CLASS(CTortoiseGitBlameDoc
),
218 RUNTIME_CLASS(CMainFrame
), // main SDI frame window
219 RUNTIME_CLASS(CTortoiseGitBlameView
));
222 AddDocTemplate(pDocTemplate
);
226 // Parse command line for standard shell commands, DDE, file open
227 CCommandLineInfo cmdInfo
;
228 ParseCommandLine(cmdInfo
);
230 // Dispatch commands specified on the command line. Will return FALSE if
231 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
232 if (!ProcessShellCommand(cmdInfo
))
235 // The one and only window has been initialized, so show and update it
236 m_pMainWnd
->ShowWindow(SW_SHOW
);
237 m_pMainWnd
->UpdateWindow();
238 // call DragAcceptFiles only if there's a suffix
239 // In an SDI app, this should occur after ProcessShellCommand
243 // CAboutDlg dialog used for App About
245 class CAboutDlg
: public CDialog
251 enum { IDD
= IDD_ABOUTBOX
};
254 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
258 DECLARE_MESSAGE_MAP()
261 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
265 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
267 CDialog::DoDataExchange(pDX
);
270 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
273 BOOL
CAboutDlg::OnInitDialog()
275 CDialog::OnInitDialog();
277 TCHAR verbuf
[1024] = {0};
278 TCHAR maskbuf
[1024] = {0};
279 if (!::LoadString(GetModuleHandle(NULL
), IDS_VERSION
, maskbuf
, _countof(maskbuf
)))
281 SecureZeroMemory(maskbuf
, sizeof(maskbuf
));
283 _stprintf_s(verbuf
, maskbuf
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
284 SetDlgItemText(IDC_VERSION
, verbuf
);
289 // App command to run the dialog
290 void CTortoiseGitBlameApp::OnAppAbout()
296 void CTortoiseGitBlameApp::OnFileSettings()
298 CCommonAppUtils::RunTortoiseGitProc(_T(" /command:settings /page:blame"));
301 // CTortoiseGitBlameApp customization load/save methods
303 void CTortoiseGitBlameApp::PreLoadState()
305 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP
, IDR_BLAME_POPUP
);
308 void CTortoiseGitBlameApp::LoadCustomState()
312 void CTortoiseGitBlameApp::SaveCustomState()
316 // CTortoiseGitBlameApp message handlers
318 int CTortoiseGitBlameApp::ExitInstance()
320 Gdiplus::GdiplusShutdown(m_gdiplusToken
);
321 return CWinAppEx::ExitInstance();