Fix diff-xls.js error reported from http://tortoisesvn.tigris.org/ds/viewMessage...
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blob48ff57e1c048d2ba5823b4375fcd18bce4db8ce1
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.
23 #include "stdafx.h"
24 #include "afxwinappex.h"
25 #include "TortoiseGitBlame.h"
26 #include "MainFrm.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"
37 #ifdef _DEBUG
38 #define new DEBUG_NEW
39 #endif
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)
51 END_MESSAGE_MAP()
54 // CTortoiseGitBlameApp construction
56 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
58 SetDllDirectory(L"");
59 SetTaskIDPerUUID();
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());
65 EnableHtmlHelp();
67 m_gdiplusToken = NULL;
68 m_bHiColorIcons = TRUE;
71 // The one and only CTortoiseGitBlameApp object
72 CTortoiseGitBlameApp theApp;
73 CString sOrigCWD;
74 CString g_sGroupingUUID;
76 // CTortoiseGitBlameApp initialization
78 BOOL CTortoiseGitBlameApp::InitInstance()
81 DWORD len = GetCurrentDirectory(0, NULL);
82 if (len)
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);
95 long langId = loc;
96 CString langDll;
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)
107 FreeLibrary(hInst);
108 hInst = NULL;
110 if (hInst != NULL)
111 AfxSetResourceHandle(hInst);
112 else
114 DWORD lid = SUBLANGID(langId);
115 lid--;
116 if (lid > 0)
118 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
120 else
121 langId = 0;
123 } while ((hInst == NULL) && (langId != 0));
124 TCHAR buf[6];
125 _tcscpy_s(buf, _T("en"));
126 langId = loc;
127 CString sHelppath;
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("_");
138 sLang += buf;
139 sHelppath.Replace(_T("_en"), sLang);
140 if (PathFileExists(sHelppath))
142 free((void*)m_pszHelpFilePath);
143 m_pszHelpFilePath=_tcsdup(sHelppath);
144 break;
146 sHelppath.Replace(sLang, _T("_en"));
147 GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf));
148 sLang += _T("_");
149 sLang += buf;
150 sHelppath.Replace(_T("_en"), sLang);
151 if (PathFileExists(sHelppath))
153 free((void*)m_pszHelpFilePath);
154 m_pszHelpFilePath=_tcsdup(sHelppath);
155 break;
157 sHelppath.Replace(sLang, _T("_en"));
159 DWORD lid = SUBLANGID(langId);
160 lid--;
161 if (lid > 0)
163 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
165 else
166 langId = 0;
167 } while (langId);
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
190 if (!AfxOleInit())
192 AfxMessageBox(IDP_OLE_INIT_FAILED);
193 return FALSE;
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));
223 if (!pDocTemplate)
224 return FALSE;
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))
237 return FALSE;
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
244 return TRUE;
247 // CAboutDlg dialog used for App About
249 class CAboutDlg : public CDialog
251 public:
252 CAboutDlg();
254 // Dialog Data
255 enum { IDD = IDD_ABOUTBOX };
257 protected:
258 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
259 BOOL OnInitDialog();
261 // Implementation
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)
275 END_MESSAGE_MAP()
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);
290 return FALSE;
293 // App command to run the dialog
294 void CTortoiseGitBlameApp::OnAppAbout()
296 CAboutDlg aboutDlg;
297 aboutDlg.DoModal();
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();