cleanup .gitignore
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blobbe7eb957e317e9937ecc4bc8a2310342f32bf759
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 //#include "vld.h"
22 #include "TortoiseProc.h"
23 #include "SysImageList.h"
24 #include "CrashReport.h"
25 #include "CmdLineParser.h"
26 #include "Hooks.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "UnicodeUtils.h"
30 #include "MessageBox.h"
31 //#include "libintl.h"
32 #include "DirFileEnum.h"
33 //#include "SoundUtils.h"
34 //#include "SVN.h"
35 #include "GitAdminDir.h"
36 #include "Git.h"
37 //#include "SVNGlobal.h"
38 //#include "svn_types.h"
39 //#include "svn_dso.h"
40 //#include <openssl/ssl.h>
41 //#include <openssl/err.h>
42 #include "SmartHandle.h"
43 #include "Commands\Command.h"
44 #include "..\version.h"
45 #include "JumpListHelpers.h"
46 #include "SinglePropSheetDlg.h"
47 #include "Settings\setmainpage.h"
48 #include "..\Settings\Settings.h"
49 #include "gitindex.h"
50 #include "Libraries.h"
52 #define STRUCT_IOVEC_DEFINED
53 //#include "sasl.h"
55 #ifdef _DEBUG
56 #define new DEBUG_NEW
57 #endif
59 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
61 #define APPID (_T("TGIT.TGIT.1") _T(TGIT_PLATFORM))
63 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
64 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
65 END_MESSAGE_MAP()
67 //CString g_version;
68 //CString CGit::m_MsysGitPath;
69 //////////////////////////////////////////////////////////////////////////
71 CTortoiseProcApp::CTortoiseProcApp()
73 SetDllDirectory(L"");
74 EnableHtmlHelp();
75 // int argc = 0;
76 // const char* const * argv = NULL;
77 // apr_app_initialize(&argc, &argv, NULL);
78 // svn_dso_initialize2();
79 SYS_IMAGE_LIST();
80 CHooks::Create();
81 g_GitAdminDir.Init();
82 m_bLoadUserToolbars = FALSE;
83 m_bSaveState = FALSE;
84 retSuccess = false;
88 CTortoiseProcApp::~CTortoiseProcApp()
90 // global application exit cleanup (after all SSL activity is shutdown)
91 // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)
92 // because those cleanup functions work globally per process.
93 //ERR_free_strings();
94 //EVP_cleanup();
95 //CRYPTO_cleanup_all_ex_data();
97 // since it is undefined *when* the global object SVNAdminDir is
98 // destroyed, we tell it to destroy the memory pools and terminate apr
99 // *now* instead of later when the object itself is destroyed.
100 g_GitAdminDir.Close();
101 CHooks::Destroy();
102 SYS_IMAGE_LIST().Cleanup();
103 //apr_terminate();
106 // The one and only CTortoiseProcApp object
107 CTortoiseProcApp theApp;
108 CString sOrigCWD;
109 HWND hWndExplorer;
111 BOOL CTortoiseProcApp::CheckMsysGitDir()
113 //CGitIndexFileMap map;
114 //int status;
115 //CTGitPath path;
116 //path.SetFromGit(_T("src/gpl.txt"));
117 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
118 return g_Git.CheckMsysGitDir();
120 CCrashReport crasher("tortoisegit-bug@googlegroups.com", "Crash Report for TortoiseGit " APP_X64_STRING " : " STRPRODUCTVER, TRUE);// crash
122 // CTortoiseProcApp initialization
124 BOOL CTortoiseProcApp::InitInstance()
126 EnableCrashHandler();
127 CheckUpgrade();
128 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
129 CMFCButton::EnableWindowsTheming();
131 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
132 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
134 //set the resource dll for the required language
135 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
136 long langId = loc;
137 CString langDll;
138 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
139 langpath += "Languages";
140 // bindtextdomain("subversion", (LPCSTR)langpath);
141 // bind_textdomain_codeset("subversion", "UTF-8");
142 HINSTANCE hInst = NULL;
145 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
147 hInst = LoadLibrary(langDll);
149 CString sVer = _T(STRPRODUCTVER);
150 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
151 if (sFileVer.Compare(sVer)!=0)
153 FreeLibrary(hInst);
154 hInst = NULL;
156 if (hInst != NULL)
158 AfxSetResourceHandle(hInst);
160 else
162 DWORD lid = SUBLANGID(langId);
163 lid--;
164 if (lid > 0)
166 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
168 else
169 langId = 0;
171 } while ((hInst == NULL) && (langId != 0));
172 TCHAR buf[6];
173 _tcscpy_s(buf, _T("en"));
174 langId = loc;
175 CString sHelppath;
176 sHelppath = this->m_pszHelpFilePath;
177 sHelppath = sHelppath.MakeLower();
178 // MFC uses a help file with the same name as the application by default,
179 // which means we have to change that default to our language specific help files
180 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
181 free((void*)m_pszHelpFilePath);
182 m_pszHelpFilePath=_tcsdup(sHelppath);
183 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
186 CString sLang = _T("_");
187 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
189 sLang += buf;
190 sHelppath.Replace(_T("_en"), sLang);
191 if (PathFileExists(sHelppath))
193 free((void*)m_pszHelpFilePath);
194 m_pszHelpFilePath=_tcsdup(sHelppath);
195 break;
198 sHelppath.Replace(sLang, _T("_en"));
199 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
201 sLang += _T("_");
202 sLang += buf;
203 sHelppath.Replace(_T("_en"), sLang);
204 if (PathFileExists(sHelppath))
206 free((void*)m_pszHelpFilePath);
207 m_pszHelpFilePath=_tcsdup(sHelppath);
208 break;
211 sHelppath.Replace(sLang, _T("_en"));
213 DWORD lid = SUBLANGID(langId);
214 lid--;
215 if (lid > 0)
217 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
219 else
220 langId = 0;
221 } while (langId);
222 setlocale(LC_ALL, "");
224 if(!CheckMsysGitDir())
226 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
227 if(ret == 2)
229 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
231 else if(ret == 1)
233 // open settings dialog
234 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
236 return FALSE;
238 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
240 int ret = CMessageBox::ShowCheck(NULL, IDS_PROC_OLDMSYSGIT, IDS_APPNAME, 1, IDI_EXCLAMATION, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON, IDS_IGNOREBUTTON, _T("OldMsysgitVersionWarning"), IDS_PROC_NOTSHOWAGAINIGNORE);
241 if (ret == 1)
243 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
244 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
245 return FALSE;
247 else if (ret == 2)
249 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
250 return FALSE;
254 // InitCommonControls() is required on Windows XP if an application
255 // manifest specifies use of ComCtl32.dll version 6 or later to enable
256 // visual styles. Otherwise, any window creation will fail.
258 INITCOMMONCONTROLSEX used = {
259 sizeof(INITCOMMONCONTROLSEX),
260 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
261 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
262 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
263 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
264 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
266 InitCommonControlsEx(&used);
267 AfxOleInit();
268 AfxEnableControlContainer();
269 AfxInitRichEdit2();
270 CWinAppEx::InitInstance();
271 SetRegistryKey(_T("TortoiseGit"));
273 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
275 hWndExplorer = NULL;
276 CString sVal = parser.GetVal(_T("hwnd"));
277 if (!sVal.IsEmpty())
278 hWndExplorer = (HWND)_ttoi64(sVal);
280 while (GetParent(hWndExplorer)!=NULL)
281 hWndExplorer = GetParent(hWndExplorer);
282 if (!IsWindow(hWndExplorer))
284 hWndExplorer = NULL;
287 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
288 // in a message box
289 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
290 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
292 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
294 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
295 return FALSE;
298 CTGitPath cmdLinePath;
299 CTGitPathList pathList;
300 if ( parser.HasKey(_T("pathfile")) )
303 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
305 cmdLinePath.SetFromUnknown(sPathfileArgument);
306 if (pathList.LoadFromFile(cmdLinePath)==false)
307 return FALSE; // no path specified!
308 if ( parser.HasKey(_T("deletepathfile")) )
310 // We can delete the temporary path file, now that we've loaded it
311 ::DeleteFile(cmdLinePath.GetWinPath());
313 // This was a path to a temporary file - it's got no meaning now, and
314 // anybody who uses it again is in for a problem...
315 cmdLinePath.Reset();
318 else
321 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
322 if (parser.HasKey(_T("expaths")))
324 // an /expaths param means we're started via the buttons in our Win7 library
325 // and that means the value of /expaths is the current directory, and
326 // the selected paths are then added as additional parameters but without a key, only a value
328 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
329 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
330 // a save bet.
331 // Without this, a command line like:
332 // /command:commit /expaths:"D:\" "D:\Utils"
333 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
334 // mark and we'd end up with:
335 // argv[1] = /command:commit
336 // argv[2] = /expaths:D:" D:\Utils
337 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
338 CString cmdLine = GetCommandLineW();
339 cmdLine.Replace(L"\\", L"\\\\");
340 int nArgs = 0;
341 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
342 if (szArglist)
344 // argument 0 is the process path, so start with 1
345 for (int i=1; i<nArgs; i++)
347 if (szArglist[i][0] != '/')
349 if (!sPathArgument.IsEmpty())
350 sPathArgument += '*';
351 sPathArgument += szArglist[i];
354 sPathArgument.Replace(L"\\\\", L"\\");
356 LocalFree(szArglist);
358 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
360 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
361 return FALSE;
363 int asterisk = sPathArgument.Find('*');
364 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
365 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
368 if (pathList.GetCount() == 0) {
369 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
372 InitializeJumpList();
373 EnsureGitLibrary(false);
375 // Subversion sometimes writes temp files to the current directory!
376 // Since TSVN doesn't need a specific CWD anyway, we just set it
377 // to the users temp folder: that way, Subversion is guaranteed to
378 // have write access to the CWD
380 DWORD len = GetCurrentDirectory(0, NULL);
381 if (len)
383 auto_buffer<TCHAR> originalCurrentDirectory(len);
384 if (GetCurrentDirectory(len, originalCurrentDirectory))
386 sOrigCWD = originalCurrentDirectory;
387 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
390 TCHAR pathbuf[MAX_PATH];
391 GetTempPath(MAX_PATH, pathbuf);
392 SetCurrentDirectory(pathbuf);
395 CheckForNewerVersion();
397 if (parser.HasVal(_T("configdir")))
399 // the user can override the location of the Subversion config directory here
400 CString sConfigDir = parser.GetVal(_T("configdir"));
401 // g_GitGlobal.SetConfigDir(sConfigDir);
403 // to avoid that SASL will look for and load its plugin dlls all around the
404 // system, we set the path here.
405 // Note that SASL doesn't have to be initialized yet for this to work
406 // sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));
408 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
409 if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))
411 int i=0;
412 for(i=0;i<pathList.GetCount();i++)
413 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
414 break;
417 if(!g_Git.m_CurrentDir.IsEmpty())
419 sOrigCWD = g_Git.m_CurrentDir;
420 SetCurrentDirectory(g_Git.m_CurrentDir);
424 CString err;
427 // requires CWD to be set
428 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
430 catch (char* msg)
432 err = CString(msg);
435 if (!err.IsEmpty())
437 UINT choice = CMessageBox::Show(hWndExplorer, err, _T("TortoiseGit"), 1, IDI_ERROR, CString(MAKEINTRESOURCE(IDS_PROC_EDITLOCALGITCONFIG)), CString(MAKEINTRESOURCE(IDS_PROC_EDITGLOBALGITCONFIG)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
438 if (choice == 1)
440 // open the config file with alternative editor
441 CString path;
442 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, path);
443 path += _T("config");
444 CAppUtils::LaunchAlternativeEditor(path);
446 else if (choice == 2)
448 // open the global config file with alternative editor
449 char charBuf[MAX_PATH];
450 TCHAR buf[MAX_PATH];
451 strcpy_s(charBuf, MAX_PATH, get_windows_home_directory());
452 _tcscpy_s(buf, MAX_PATH, CA2CT(charBuf));
453 _tcscat_s(buf, MAX_PATH, _T("\\.gitconfig"));
454 CAppUtils::LaunchAlternativeEditor(buf);
456 return FALSE;
460 // execute the requested command
461 CommandServer server;
462 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
463 if (cmd)
465 cmd->SetExplorerHwnd(hWndExplorer);
467 cmd->SetParser(parser);
468 cmd->SetPaths(pathList, cmdLinePath);
470 retSuccess = cmd->Execute();
471 delete cmd;
474 // Look for temporary files left around by TortoiseSVN and
475 // remove them. But only delete 'old' files because some
476 // apps might still be needing the recent ones.
478 DWORD len = ::GetTempPath(0, NULL);
479 TCHAR * path = new TCHAR[len + 100];
480 len = ::GetTempPath (len+100, path);
481 if (len != 0)
483 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
484 FILETIME systime_;
485 ::GetSystemTimeAsFileTime(&systime_);
486 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
487 while (finder.FindNextFileNoDirectories())
489 CString filepath = finder.GetFilePath();
490 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
491 if (hFile != INVALID_HANDLE_VALUE)
493 FILETIME createtime_;
494 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
496 ::CloseHandle(hFile);
497 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
498 if ((createtime + 864000000000) < systime) //only delete files older than a day
500 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
501 ::DeleteFile(filepath);
504 else
505 ::CloseHandle(hFile);
509 delete[] path;
512 // Since the dialog has been closed, return FALSE so that we exit the
513 // application, rather than start the application's message pump.
514 return FALSE;
517 void CTortoiseProcApp::CheckUpgrade()
519 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
520 CString sVersion = regVersion;
521 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
522 return;
523 // we're starting the first time with a new version!
525 LONG lVersion = 0;
526 int pos = sVersion.Find(',');
527 if (pos > 0)
529 lVersion = (_ttol(sVersion.Left(pos))<<24);
530 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
531 pos = sVersion.Find(',', pos+1);
532 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
535 if (lVersion <= 0x01070600)
537 CoInitialize(NULL);
538 EnsureGitLibrary();
539 CoUninitialize();
540 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
541 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
542 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
543 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
544 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
546 #if 0
547 if (lVersion <= 0x01010300)
549 CSoundUtils::RegisterTSVNSounds();
551 #endif
552 if (lVersion <= 0x01020200)
554 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
555 // so remove the diff/merge scripts if they're the defaults
556 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
557 CString sDiff = diffreg;
558 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
559 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
560 diffreg = _T("");
561 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
562 sDiff = mergereg;
563 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
564 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
565 mergereg = _T("");
567 if (lVersion <= 0x01040000)
569 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
572 // set the custom diff scripts for every user
573 CString scriptsdir = CPathUtils::GetAppParentDirectory();
574 scriptsdir += _T("Diff-Scripts");
575 CSimpleFileFind files(scriptsdir);
576 while (files.FindNextFileNoDirectories())
578 CString file = files.GetFilePath();
579 CString filename = files.GetFileName();
580 CString ext = file.Mid(file.ReverseFind('-')+1);
581 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
582 CString kind;
583 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
585 kind = _T(" //E:vbscript");
587 if (file.Right(2).CompareNoCase(_T("js"))==0)
589 kind = _T(" //E:javascript");
592 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
594 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
595 CString diffregstring = diffreg;
596 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
597 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
599 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
601 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
602 CString diffregstring = diffreg;
603 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
604 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
608 // set the current version so we don't come here again until the next update!
609 regVersion = _T(STRPRODUCTVER);
612 void CTortoiseProcApp::EnableCrashHandler()
614 // the crash handler is enabled by default, but we disable it
615 // after 3 months after a release
617 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
618 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
620 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
621 : __DATE__ [2] == 'b' ? 2 \
622 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
623 : __DATE__ [2] == 'y' ? 5 \
624 : __DATE__ [2] == 'l' ? 7 \
625 : __DATE__ [2] == 'g' ? 8 \
626 : __DATE__ [2] == 'p' ? 9 \
627 : __DATE__ [2] == 't' ? 10 \
628 : __DATE__ [2] == 'v' ? 11 : 12)
630 #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
631 + (__DATE__ [5] - '0'))
633 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
635 CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);
636 CTime now = CTime::GetCurrentTime();
638 CTimeSpan timediff = now-compiletime;
639 if (timediff.GetDays() > 3*31)
641 // crasher.Enable(FALSE);
645 void CTortoiseProcApp::InitializeJumpList()
647 // for Win7 : use a custom jump list
648 CoInitialize(NULL);
649 SetAppID(APPID);
650 DeleteJumpList(APPID);
651 DoInitializeJumpList();
652 CoUninitialize();
655 void CTortoiseProcApp::DoInitializeJumpList()
657 ATL::CComPtr<ICustomDestinationList> pcdl;
658 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
659 if (FAILED(hr))
660 return;
662 hr = pcdl->SetAppID(APPID);
663 if (FAILED(hr))
664 return;
666 UINT uMaxSlots;
667 ATL::CComPtr<IObjectArray> poaRemoved;
668 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
669 if (FAILED(hr))
670 return;
672 ATL::CComPtr<IObjectCollection> poc;
673 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
674 if (FAILED(hr))
675 return;
677 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
678 sTemp.Remove('&');
680 ATL::CComPtr<IShellLink> psl;
681 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
682 if (SUCCEEDED(hr)) {
683 poc->AddObject(psl);
685 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
686 sTemp.Remove('&');
687 psl.Release(); // Need to release the object before calling operator&()
688 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
689 if (SUCCEEDED(hr)) {
690 poc->AddObject(psl);
693 ATL::CComPtr<IObjectArray> poa;
694 hr = poc.QueryInterface(&poa);
695 if (SUCCEEDED(hr)) {
696 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
697 pcdl->CommitList();
701 int CTortoiseProcApp::ExitInstance()
703 Gdiplus::GdiplusShutdown(m_gdiplusToken);
705 CWinAppEx::ExitInstance();
706 if (retSuccess)
707 return 0;
708 return -1;
711 void CTortoiseProcApp::CheckForNewerVersion()
713 // check for newer versions
714 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
716 time_t now;
717 struct tm ptm;
719 time(&now);
720 if ((now != 0) && (localtime_s(&ptm, &now)==0))
722 int week = 0;
723 // we don't calculate the real 'week of the year' here
724 // because just to decide if we should check for an update
725 // that's not needed.
726 week = ptm.tm_yday / 7;
728 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
729 if (((DWORD)oldweek) == -1)
730 oldweek = week; // first start of TortoiseProc, no update check needed
731 else
733 if ((DWORD)week != oldweek)
735 oldweek = week;
737 TCHAR com[MAX_PATH+100];
738 GetModuleFileName(NULL, com, MAX_PATH);
739 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
741 CAppUtils::LaunchApplication(com, 0, false);