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"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
31 #include "CmdLineParser.h"
32 #include "PathUtils.h"
33 #include "CommonAppUtils.h"
40 // CTortoiseGitBlameApp
42 BEGIN_MESSAGE_MAP(CTortoiseGitBlameApp
, CWinAppEx
)
43 ON_COMMAND(ID_APP_ABOUT
, &CTortoiseGitBlameApp::OnAppAbout
)
44 // Standard file based document commands
45 ON_COMMAND(ID_FILE_NEW
, &CWinAppEx::OnFileNew
)
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()
60 m_bHiColorIcons
= TRUE
;
63 // The one and only CTortoiseGitBlameApp object
64 CTortoiseGitBlameApp theApp
;
67 // CTortoiseGitBlameApp initialization
69 BOOL
CTortoiseGitBlameApp::InitInstance()
72 DWORD len
= GetCurrentDirectory(0, NULL
);
75 auto_buffer
<TCHAR
> originalCurrentDirectory(len
);
76 if (GetCurrentDirectory(len
, originalCurrentDirectory
))
78 sOrigCWD
= originalCurrentDirectory
;
79 sOrigCWD
= CPathUtils::GetLongPathname(sOrigCWD
);
84 //set the resource dll for the required language
85 CRegDWORD loc
= CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
88 HINSTANCE hInst
= NULL
;
91 langDll
.Format(_T("%sLanguages\\TortoiseGitBlame%d.dll"), (LPCTSTR
)CPathUtils::GetAppParentDirectory(), langId
);
93 hInst
= LoadLibrary(langDll
);
94 CString sVer
= _T(STRPRODUCTVER
);
95 CString sFileVer
= CPathUtils::GetVersionFromFile(langDll
);
96 if (sFileVer
.Compare(sVer
)!=0)
102 AfxSetResourceHandle(hInst
);
105 DWORD lid
= SUBLANGID(langId
);
109 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
114 } while ((hInst
== NULL
) && (langId
!= 0));
116 _tcscpy_s(buf
, _T("en"));
119 sHelppath
= this->m_pszHelpFilePath
;
120 sHelppath
= sHelppath
.MakeLower();
121 sHelppath
.Replace(_T(".chm"), _T("_en.chm"));
122 free((void*)m_pszHelpFilePath
);
123 m_pszHelpFilePath
=_tcsdup(sHelppath
);
124 sHelppath
= CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGitBlame_en.chm");
127 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO639LANGNAME
, buf
, _countof(buf
));
128 CString sLang
= _T("_");
130 sHelppath
.Replace(_T("_en"), sLang
);
131 if (PathFileExists(sHelppath
))
133 free((void*)m_pszHelpFilePath
);
134 m_pszHelpFilePath
=_tcsdup(sHelppath
);
137 sHelppath
.Replace(sLang
, _T("_en"));
138 GetLocaleInfo(MAKELCID(langId
, SORT_DEFAULT
), LOCALE_SISO3166CTRYNAME
, buf
, _countof(buf
));
141 sHelppath
.Replace(_T("_en"), sLang
);
142 if (PathFileExists(sHelppath
))
144 free((void*)m_pszHelpFilePath
);
145 m_pszHelpFilePath
=_tcsdup(sHelppath
);
148 sHelppath
.Replace(sLang
, _T("_en"));
150 DWORD lid
= SUBLANGID(langId
);
154 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
159 setlocale(LC_ALL
, "");
160 // We need to explicitly set the thread locale to the system default one to avoid possible problems with saving files in its original codepage
161 // The problems occures when the language of OS differs from the regional settings
162 // See the details here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100887
163 SetThreadLocale(LOCALE_SYSTEM_DEFAULT
);
165 // InitCommonControlsEx() is required on Windows XP if an application
166 // manifest specifies use of ComCtl32.dll version 6 or later to enable
167 // visual styles. Otherwise, any window creation will fail.
168 INITCOMMONCONTROLSEX InitCtrls
;
169 InitCtrls
.dwSize
= sizeof(InitCtrls
);
170 // Set this to include all the common control classes you want to use
171 // in your application.
172 InitCtrls
.dwICC
= ICC_WIN95_CLASSES
;
173 InitCommonControlsEx(&InitCtrls
);
175 CWinAppEx::InitInstance();
177 Gdiplus::GdiplusStartupInput gdiplusStartupInput
;
178 Gdiplus::GdiplusStartup(&m_gdiplusToken
,&gdiplusStartupInput
,NULL
);
180 // Initialize OLE libraries
183 AfxMessageBox(IDP_OLE_INIT_FAILED
);
186 AfxEnableControlContainer();
187 // Standard initialization
188 // If you are not using these features and wish to reduce the size
189 // of your final executable, you should remove from the following
190 // the specific initialization routines you do not need
191 // Change the registry key under which our settings are stored
193 SetRegistryKey(_T("TortoiseGit"));
194 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
196 InitContextMenuManager();
198 InitKeyboardManager();
200 InitTooltipManager();
201 CMFCToolTipInfo ttParams
;
202 ttParams
.m_bVislManagerTheme
= TRUE
;
203 theApp
.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL
,
204 RUNTIME_CLASS(CMFCToolTipCtrl
), &ttParams
);
206 // Register the application's document templates. Document templates
207 // serve as the connection between documents, frame windows and views
208 CSingleDocTemplate
* pDocTemplate
;
209 pDocTemplate
= new CSingleDocTemplate(
210 IDR_TORTOISE_GIT_BLAME_MAINFRAME
,
211 RUNTIME_CLASS(CTortoiseGitBlameDoc
),
212 RUNTIME_CLASS(CMainFrame
), // main SDI frame window
213 RUNTIME_CLASS(CTortoiseGitBlameView
));
216 AddDocTemplate(pDocTemplate
);
220 // Parse command line for standard shell commands, DDE, file open
221 CCommandLineInfo cmdInfo
;
222 ParseCommandLine(cmdInfo
);
224 // Dispatch commands specified on the command line. Will return FALSE if
225 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
226 if (!ProcessShellCommand(cmdInfo
))
229 // The one and only window has been initialized, so show and update it
230 m_pMainWnd
->ShowWindow(SW_SHOW
);
231 m_pMainWnd
->UpdateWindow();
232 // call DragAcceptFiles only if there's a suffix
233 // In an SDI app, this should occur after ProcessShellCommand
237 // CAboutDlg dialog used for App About
239 class CAboutDlg
: public CDialog
245 enum { IDD
= IDD_ABOUTBOX
};
248 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
252 DECLARE_MESSAGE_MAP()
255 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
259 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
261 CDialog::DoDataExchange(pDX
);
264 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
267 BOOL
CAboutDlg::OnInitDialog()
269 CDialog::OnInitDialog();
271 TCHAR verbuf
[1024] = {0};
272 TCHAR maskbuf
[1024] = {0};
273 if (!::LoadString(GetModuleHandle(NULL
), IDS_VERSION
, maskbuf
, _countof(maskbuf
)))
275 SecureZeroMemory(maskbuf
, sizeof(maskbuf
));
277 _stprintf_s(verbuf
, maskbuf
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
278 SetDlgItemText(IDC_VERSION
, verbuf
);
283 // App command to run the dialog
284 void CTortoiseGitBlameApp::OnAppAbout()
290 void CTortoiseGitBlameApp::OnFileSettings()
292 CCommonAppUtils::RunTortoiseProc(_T(" /command:settings /page:blame"));
295 // CTortoiseGitBlameApp customization load/save methods
297 void CTortoiseGitBlameApp::PreLoadState()
299 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP
, IDR_BLAME_POPUP
);
302 void CTortoiseGitBlameApp::LoadCustomState()
306 void CTortoiseGitBlameApp::SaveCustomState()
310 // CTortoiseGitBlameApp message handlers
312 int CTortoiseGitBlameApp::ExitInstance()
314 Gdiplus::GdiplusShutdown(m_gdiplusToken
);
315 return CWinAppEx::ExitInstance();