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"
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
)
49 // Standard print setup command
50 ON_COMMAND(ID_FILE_PRINT_SETUP
, &CWinAppEx::OnFilePrintSetup
)
54 // CTortoiseGitBlameApp construction
56 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
60 // prevent from inheriting %GIT_DIR% from parent process by resetting it,
61 // use MSVC function instead of Windows API because MSVC runtime caches environment variables
62 _tputenv(_T("GIT_DIR="));
63 CCrashReportTGit
crasher(L
"TortoiseGitBlame " _T(APP_X64_STRING
), TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
, TGIT_VERDATE
);
64 CCrashReport::Instance().AddUserInfoToReport(L
"CommandLine", GetCommandLine());
67 m_gdiplusToken
= NULL
;
68 m_bHiColorIcons
= TRUE
;
71 // The one and only CTortoiseGitBlameApp object
72 CTortoiseGitBlameApp theApp
;
74 CString g_sGroupingUUID
;
76 // CTortoiseGitBlameApp initialization
78 BOOL
CTortoiseGitBlameApp::InitInstance()
81 DWORD len
= GetCurrentDirectory(0, NULL
);
84 std::unique_ptr
<TCHAR
[]> originalCurrentDirectory(new TCHAR
[len
]);
85 if (GetCurrentDirectory(len
, originalCurrentDirectory
.get()))
87 sOrigCWD
= originalCurrentDirectory
.get();
88 sOrigCWD
= CPathUtils::GetLongPathname(sOrigCWD
);
93 //set the resource dll for the required language
94 CRegDWORD loc
= CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
97 HINSTANCE hInst
= NULL
;
100 langDll
.Format(_T("%sLanguages\\TortoiseGitBlame%d.dll"), (LPCTSTR
)CPathUtils::GetAppParentDirectory(), langId
);
102 hInst
= LoadLibrary(langDll
);
103 CString sVer
= _T(STRPRODUCTVER
);
104 CString sFileVer
= CPathUtils::GetVersionFromFile(langDll
);
105 if (sFileVer
.Compare(sVer
)!=0)
111 AfxSetResourceHandle(hInst
);
114 DWORD lid
= SUBLANGID(langId
);
118 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
123 } while ((hInst
== NULL
) && (langId
!= 0));
125 _tcscpy_s(buf
, _T("en"));
128 sHelppath
= this->m_pszHelpFilePath
;
129 sHelppath
= sHelppath
.MakeLower();
130 sHelppath
.Replace(_T(".chm"), _T("_en.chm"));
131 free((void*)m_pszHelpFilePath
);
132 m_pszHelpFilePath
=_tcsdup(sHelppath
);
133 sHelppath
= CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
136 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO639LANGNAME
, buf
, _countof(buf
));
137 CString sLang
= _T("_");
139 sHelppath
.Replace(_T("_en"), sLang
);
140 if (PathFileExists(sHelppath
))
142 free((void*)m_pszHelpFilePath
);
143 m_pszHelpFilePath
=_tcsdup(sHelppath
);
146 sHelppath
.Replace(sLang
, _T("_en"));
147 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO3166CTRYNAME
, buf
, _countof(buf
));
150 sHelppath
.Replace(_T("_en"), sLang
);
151 if (PathFileExists(sHelppath
))
153 free((void*)m_pszHelpFilePath
);
154 m_pszHelpFilePath
=_tcsdup(sHelppath
);
157 sHelppath
.Replace(sLang
, _T("_en"));
159 DWORD lid
= SUBLANGID(langId
);
163 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
168 setlocale(LC_ALL
, "");
169 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
170 // The problems occures when the language of OS differs from the regional settings
171 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
172 SetThreadLocale(LOCALE_SYSTEM_DEFAULT
);
174 // InitCommonControlsEx() is required on Windows XP if an application
175 // manifest specifies use of ComCtl32.dll version 6 or later to enable
176 // visual styles. Otherwise, any window creation will fail.
177 INITCOMMONCONTROLSEX InitCtrls
;
178 InitCtrls
.dwSize
= sizeof(InitCtrls
);
179 // Set this to include all the common control classes you want to use
180 // in your application.
181 InitCtrls
.dwICC
= ICC_WIN95_CLASSES
;
182 InitCommonControlsEx(&InitCtrls
);
184 CWinAppEx::InitInstance();
186 Gdiplus::GdiplusStartupInput gdiplusStartupInput
;
187 Gdiplus::GdiplusStartup(&m_gdiplusToken
,&gdiplusStartupInput
,NULL
);
189 // Initialize OLE libraries
192 AfxMessageBox(IDP_OLE_INIT_FAILED
);
195 AfxEnableControlContainer();
196 // Standard initialization
197 // If you are not using these features and wish to reduce the size
198 // of your final executable, you should remove from the following
199 // the specific initialization routines you do not need
200 // Change the registry key under which our settings are stored
202 SetRegistryKey(_T("TortoiseGit"));
203 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
205 InitContextMenuManager();
207 InitKeyboardManager();
209 InitTooltipManager();
210 CMFCToolTipInfo ttParams
;
211 ttParams
.m_bVislManagerTheme
= TRUE
;
212 theApp
.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL
,
213 RUNTIME_CLASS(CMFCToolTipCtrl
), &ttParams
);
215 // Register the application's document templates. Document templates
216 // serve as the connection between documents, frame windows and views
217 CSingleDocTemplate
* pDocTemplate
;
218 pDocTemplate
= new CSingleDocTemplate(
219 IDR_TORTOISE_GIT_BLAME_MAINFRAME
,
220 RUNTIME_CLASS(CTortoiseGitBlameDoc
),
221 RUNTIME_CLASS(CMainFrame
), // main SDI frame window
222 RUNTIME_CLASS(CTortoiseGitBlameView
));
225 AddDocTemplate(pDocTemplate
);
227 CCmdLineParser parser
= CCmdLineParser(this->m_lpCmdLine
);
228 g_sGroupingUUID
= parser
.GetVal(L
"groupuuid");
230 // Parse command line for standard shell commands, DDE, file open
231 CCommandLineInfo cmdInfo
;
232 ParseCommandLine(cmdInfo
);
234 // Dispatch commands specified on the command line. Will return FALSE if
235 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
236 if (!ProcessShellCommand(cmdInfo
))
239 // The one and only window has been initialized, so show and update it
240 m_pMainWnd
->ShowWindow(SW_SHOW
);
241 m_pMainWnd
->UpdateWindow();
242 // call DragAcceptFiles only if there's a suffix
243 // In an SDI app, this should occur after ProcessShellCommand
247 // CAboutDlg dialog used for App About
249 class CAboutDlg
: public CDialog
255 enum { IDD
= IDD_ABOUTBOX
};
258 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
262 DECLARE_MESSAGE_MAP()
265 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
269 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
271 CDialog::DoDataExchange(pDX
);
274 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
277 BOOL
CAboutDlg::OnInitDialog()
279 CDialog::OnInitDialog();
281 TCHAR verbuf
[1024] = {0};
282 TCHAR maskbuf
[1024] = {0};
283 if (!::LoadString(GetModuleHandle(NULL
), IDS_VERSION
, maskbuf
, _countof(maskbuf
)))
285 SecureZeroMemory(maskbuf
, sizeof(maskbuf
));
287 _stprintf_s(verbuf
, maskbuf
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
288 SetDlgItemText(IDC_VERSION
, verbuf
);
293 // App command to run the dialog
294 void CTortoiseGitBlameApp::OnAppAbout()
300 void CTortoiseGitBlameApp::OnFileSettings()
302 CCommonAppUtils::RunTortoiseGitProc(_T(" /command:settings /page:blame"));
305 // CTortoiseGitBlameApp customization load/save methods
307 void CTortoiseGitBlameApp::PreLoadState()
309 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP
, IDR_BLAME_POPUP
);
312 void CTortoiseGitBlameApp::LoadCustomState()
316 void CTortoiseGitBlameApp::SaveCustomState()
320 // CTortoiseGitBlameApp message handlers
322 int CTortoiseGitBlameApp::ExitInstance()
324 Gdiplus::GdiplusShutdown(m_gdiplusToken
);
325 return CWinAppEx::ExitInstance();