correctly initialize sOrigCWD before using it
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlame.cpp
blob1b2ef40555da81cda15b2363b19f3baac6555f49
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.
23 #include "stdafx.h"
24 #include "afxwinappex.h"
25 #include "TortoiseGitBlame.h"
26 #include "MainFrm.h"
27 #include "../version.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
31 #include "CmdLineParser.h"
32 #include "PathUtils.h"
34 #ifdef _DEBUG
35 #define new DEBUG_NEW
36 #endif
39 // CTortoiseGitBlameApp
41 BEGIN_MESSAGE_MAP(CTortoiseGitBlameApp, CWinAppEx)
42 ON_COMMAND(ID_APP_ABOUT, &CTortoiseGitBlameApp::OnAppAbout)
43 // Standard file based document commands
44 ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
45 ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
46 // Standard print setup command
47 ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
48 END_MESSAGE_MAP()
51 // CTortoiseGitBlameApp construction
53 CTortoiseGitBlameApp::CTortoiseGitBlameApp()
55 SetDllDirectory(L"");
56 EnableHtmlHelp();
59 DWORD len = GetCurrentDirectory(0, NULL);
60 if (len)
62 auto_buffer<TCHAR> originalCurrentDirectory(len);
63 if (GetCurrentDirectory(len, originalCurrentDirectory))
65 sOrigCWD = originalCurrentDirectory;
66 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
71 m_bHiColorIcons = TRUE;
74 // The one and only CTortoiseGitBlameApp object
76 CString sOrigCWD;
77 CTortoiseGitBlameApp theApp;
79 // CTortoiseGitBlameApp initialization
81 BOOL CTortoiseGitBlameApp::InitInstance()
83 // InitCommonControlsEx() is required on Windows XP if an application
84 // manifest specifies use of ComCtl32.dll version 6 or later to enable
85 // visual styles. Otherwise, any window creation will fail.
86 INITCOMMONCONTROLSEX InitCtrls;
87 InitCtrls.dwSize = sizeof(InitCtrls);
88 // Set this to include all the common control classes you want to use
89 // in your application.
90 InitCtrls.dwICC = ICC_WIN95_CLASSES;
91 InitCommonControlsEx(&InitCtrls);
93 CWinAppEx::InitInstance();
95 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
96 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
98 // Initialize OLE libraries
99 if (!AfxOleInit())
101 AfxMessageBox(IDP_OLE_INIT_FAILED);
102 return FALSE;
104 AfxEnableControlContainer();
105 // Standard initialization
106 // If you are not using these features and wish to reduce the size
107 // of your final executable, you should remove from the following
108 // the specific initialization routines you do not need
109 // Change the registry key under which our settings are stored
111 SetRegistryKey(_T("TortoiseGit"));
112 LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
114 InitContextMenuManager();
116 InitKeyboardManager();
118 InitTooltipManager();
119 CMFCToolTipInfo ttParams;
120 ttParams.m_bVislManagerTheme = TRUE;
121 theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
122 RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
124 // Register the application's document templates. Document templates
125 // serve as the connection between documents, frame windows and views
126 CSingleDocTemplate* pDocTemplate;
127 pDocTemplate = new CSingleDocTemplate(
128 IDR_TORTOISE_GIT_BLAME_MAINFRAME,
129 RUNTIME_CLASS(CTortoiseGitBlameDoc),
130 RUNTIME_CLASS(CMainFrame), // main SDI frame window
131 RUNTIME_CLASS(CTortoiseGitBlameView));
132 if (!pDocTemplate)
133 return FALSE;
134 AddDocTemplate(pDocTemplate);
138 // Parse command line for standard shell commands, DDE, file open
139 CCommandLineInfo cmdInfo;
140 ParseCommandLine(cmdInfo);
142 // Dispatch commands specified on the command line. Will return FALSE if
143 // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
144 if (!ProcessShellCommand(cmdInfo))
145 return FALSE;
147 // The one and only window has been initialized, so show and update it
148 m_pMainWnd->ShowWindow(SW_SHOW);
149 m_pMainWnd->UpdateWindow();
150 // call DragAcceptFiles only if there's a suffix
151 // In an SDI app, this should occur after ProcessShellCommand
152 return TRUE;
155 // CAboutDlg dialog used for App About
157 class CAboutDlg : public CDialog
159 public:
160 CAboutDlg();
162 // Dialog Data
163 enum { IDD = IDD_ABOUTBOX };
165 protected:
166 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
167 BOOL OnInitDialog();
169 // Implementation
170 DECLARE_MESSAGE_MAP()
173 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
177 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
179 CDialog::DoDataExchange(pDX);
182 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
183 END_MESSAGE_MAP()
185 BOOL CAboutDlg::OnInitDialog()
187 CDialog::OnInitDialog();
189 TCHAR verbuf[1024] = {0};
190 TCHAR maskbuf[1024] = {0};
191 if (!::LoadString(GetModuleHandle(NULL), IDS_VERSION, maskbuf, _countof(maskbuf)))
193 SecureZeroMemory(maskbuf, sizeof(maskbuf));
195 _stprintf_s(verbuf, maskbuf, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD);
196 SetDlgItemText(IDC_VERSION, verbuf);
198 return FALSE;
201 // App command to run the dialog
202 void CTortoiseGitBlameApp::OnAppAbout()
204 CAboutDlg aboutDlg;
205 aboutDlg.DoModal();
208 // CTortoiseGitBlameApp customization load/save methods
210 void CTortoiseGitBlameApp::PreLoadState()
212 GetContextMenuManager()->AddMenu(IDR_BLAME_POPUP, IDR_BLAME_POPUP);
215 void CTortoiseGitBlameApp::LoadCustomState()
219 void CTortoiseGitBlameApp::SaveCustomState()
223 // CTortoiseGitBlameApp message handlers
225 int CTortoiseGitBlameApp::ExitInstance()
227 Gdiplus::GdiplusShutdown(m_gdiplusToken);
228 return CWinAppEx::ExitInstance();