Moved last remaining strings to resources
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob57409d7219fc8ed65a141208b24f84e169dd54c2
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 "..\Settings\Settings.h"
47 #include "gitindex.h"
48 #include "Libraries.h"
50 #define STRUCT_IOVEC_DEFINED
51 //#include "sasl.h"
53 #ifdef _DEBUG
54 #define new DEBUG_NEW
55 #endif
57 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
59 #define APPID (_T("TGIT.TGIT.1") _T(TGIT_PLATFORM))
61 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
62 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
63 END_MESSAGE_MAP()
65 //CString g_version;
66 //CString CGit::m_MsysGitPath;
67 //////////////////////////////////////////////////////////////////////////
69 CTortoiseProcApp::CTortoiseProcApp()
71 SetDllDirectory(L"");
72 EnableHtmlHelp();
73 // int argc = 0;
74 // const char* const * argv = NULL;
75 // apr_app_initialize(&argc, &argv, NULL);
76 // svn_dso_initialize2();
77 SYS_IMAGE_LIST();
78 CHooks::Create();
79 g_GitAdminDir.Init();
80 m_bLoadUserToolbars = FALSE;
81 m_bSaveState = FALSE;
82 retSuccess = false;
86 CTortoiseProcApp::~CTortoiseProcApp()
88 // global application exit cleanup (after all SSL activity is shutdown)
89 // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)
90 // because those cleanup functions work globally per process.
91 //ERR_free_strings();
92 //EVP_cleanup();
93 //CRYPTO_cleanup_all_ex_data();
95 // since it is undefined *when* the global object SVNAdminDir is
96 // destroyed, we tell it to destroy the memory pools and terminate apr
97 // *now* instead of later when the object itself is destroyed.
98 g_GitAdminDir.Close();
99 CHooks::Destroy();
100 SYS_IMAGE_LIST().Cleanup();
101 //apr_terminate();
104 // The one and only CTortoiseProcApp object
105 CTortoiseProcApp theApp;
106 CString sOrigCWD;
107 HWND hWndExplorer;
109 BOOL CTortoiseProcApp::CheckMsysGitDir()
111 //CGitIndexFileMap map;
112 //int status;
113 //CTGitPath path;
114 //path.SetFromGit(_T("src/gpl.txt"));
115 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
116 return g_Git.CheckMsysGitDir();
118 CCrashReport crasher("tortoisegit-bug@googlegroups.com", "Crash Report for TortoiseGit " APP_X64_STRING " : " STRPRODUCTVER, TRUE);// crash
120 // CTortoiseProcApp initialization
122 BOOL CTortoiseProcApp::InitInstance()
124 EnableCrashHandler();
125 CheckUpgrade();
126 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
127 CMFCButton::EnableWindowsTheming();
129 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
130 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
132 //set the resource dll for the required language
133 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
134 long langId = loc;
135 CString langDll;
136 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
137 langpath += "Languages";
138 // bindtextdomain("subversion", (LPCSTR)langpath);
139 // bind_textdomain_codeset("subversion", "UTF-8");
140 HINSTANCE hInst = NULL;
143 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
145 hInst = LoadLibrary(langDll);
147 CString sVer = _T(STRPRODUCTVER);
148 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
149 if (sFileVer.Compare(sVer)!=0)
151 FreeLibrary(hInst);
152 hInst = NULL;
154 if (hInst != NULL)
156 AfxSetResourceHandle(hInst);
158 else
160 DWORD lid = SUBLANGID(langId);
161 lid--;
162 if (lid > 0)
164 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
166 else
167 langId = 0;
169 } while ((hInst == NULL) && (langId != 0));
170 TCHAR buf[6];
171 _tcscpy_s(buf, _T("en"));
172 langId = loc;
173 CString sHelppath;
174 sHelppath = this->m_pszHelpFilePath;
175 sHelppath = sHelppath.MakeLower();
176 // MFC uses a help file with the same name as the application by default,
177 // which means we have to change that default to our language specific help files
178 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
179 free((void*)m_pszHelpFilePath);
180 m_pszHelpFilePath=_tcsdup(sHelppath);
181 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
184 CString sLang = _T("_");
185 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
187 sLang += buf;
188 sHelppath.Replace(_T("_en"), sLang);
189 if (PathFileExists(sHelppath))
191 free((void*)m_pszHelpFilePath);
192 m_pszHelpFilePath=_tcsdup(sHelppath);
193 break;
196 sHelppath.Replace(sLang, _T("_en"));
197 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
199 sLang += _T("_");
200 sLang += buf;
201 sHelppath.Replace(_T("_en"), sLang);
202 if (PathFileExists(sHelppath))
204 free((void*)m_pszHelpFilePath);
205 m_pszHelpFilePath=_tcsdup(sHelppath);
206 break;
209 sHelppath.Replace(sLang, _T("_en"));
211 DWORD lid = SUBLANGID(langId);
212 lid--;
213 if (lid > 0)
215 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
217 else
218 langId = 0;
219 } while (langId);
220 setlocale(LC_ALL, "");
222 if(!CheckMsysGitDir())
224 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
225 if(ret == 2)
227 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
229 else if(ret == 1)
231 // open settings dialog
232 CSettings dlg(IDS_PROC_SETTINGS_TITLE);
233 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
234 dlg.SetTreeWidth(220);
236 dlg.DoModal();
237 dlg.HandleRestart();
239 return FALSE;
241 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
243 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);
244 if (ret == 1)
246 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
247 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
248 return FALSE;
250 else if (ret == 2)
252 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
253 return FALSE;
257 // InitCommonControls() is required on Windows XP if an application
258 // manifest specifies use of ComCtl32.dll version 6 or later to enable
259 // visual styles. Otherwise, any window creation will fail.
261 INITCOMMONCONTROLSEX used = {
262 sizeof(INITCOMMONCONTROLSEX),
263 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
264 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
265 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
266 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
267 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
269 InitCommonControlsEx(&used);
270 AfxOleInit();
271 AfxEnableControlContainer();
272 AfxInitRichEdit2();
273 CWinAppEx::InitInstance();
274 SetRegistryKey(_T("TortoiseGit"));
276 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
278 hWndExplorer = NULL;
279 CString sVal = parser.GetVal(_T("hwnd"));
280 if (!sVal.IsEmpty())
281 hWndExplorer = (HWND)_ttoi64(sVal);
283 while (GetParent(hWndExplorer)!=NULL)
284 hWndExplorer = GetParent(hWndExplorer);
285 if (!IsWindow(hWndExplorer))
287 hWndExplorer = NULL;
290 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
291 // in a message box
292 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
293 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
295 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
297 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
298 return FALSE;
301 CTGitPath cmdLinePath;
302 CTGitPathList pathList;
303 if ( parser.HasKey(_T("pathfile")) )
306 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
308 cmdLinePath.SetFromUnknown(sPathfileArgument);
309 if (pathList.LoadFromFile(cmdLinePath)==false)
310 return FALSE; // no path specified!
311 if ( parser.HasKey(_T("deletepathfile")) )
313 // We can delete the temporary path file, now that we've loaded it
314 ::DeleteFile(cmdLinePath.GetWinPath());
316 // This was a path to a temporary file - it's got no meaning now, and
317 // anybody who uses it again is in for a problem...
318 cmdLinePath.Reset();
321 else
324 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
325 if (parser.HasKey(_T("expaths")))
327 // an /expaths param means we're started via the buttons in our Win7 library
328 // and that means the value of /expaths is the current directory, and
329 // the selected paths are then added as additional parameters but without a key, only a value
331 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
332 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
333 // a save bet.
334 // Without this, a command line like:
335 // /command:commit /expaths:"D:\" "D:\Utils"
336 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
337 // mark and we'd end up with:
338 // argv[1] = /command:commit
339 // argv[2] = /expaths:D:" D:\Utils
340 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
341 CString cmdLine = GetCommandLineW();
342 cmdLine.Replace(L"\\", L"\\\\");
343 int nArgs = 0;
344 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
345 if (szArglist)
347 // argument 0 is the process path, so start with 1
348 for (int i=1; i<nArgs; i++)
350 if (szArglist[i][0] != '/')
352 if (!sPathArgument.IsEmpty())
353 sPathArgument += '*';
354 sPathArgument += szArglist[i];
357 sPathArgument.Replace(L"\\\\", L"\\");
359 LocalFree(szArglist);
361 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
363 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
364 return FALSE;
366 int asterisk = sPathArgument.Find('*');
367 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
368 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
371 if (pathList.GetCount() == 0) {
372 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
375 InitializeJumpList();
376 EnsureGitLibrary(false);
378 // Subversion sometimes writes temp files to the current directory!
379 // Since TSVN doesn't need a specific CWD anyway, we just set it
380 // to the users temp folder: that way, Subversion is guaranteed to
381 // have write access to the CWD
383 DWORD len = GetCurrentDirectory(0, NULL);
384 if (len)
386 auto_buffer<TCHAR> originalCurrentDirectory(len);
387 if (GetCurrentDirectory(len, originalCurrentDirectory))
389 sOrigCWD = originalCurrentDirectory;
390 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
393 TCHAR pathbuf[MAX_PATH];
394 GetTempPath(MAX_PATH, pathbuf);
395 SetCurrentDirectory(pathbuf);
398 CheckForNewerVersion();
400 if (parser.HasVal(_T("configdir")))
402 // the user can override the location of the Subversion config directory here
403 CString sConfigDir = parser.GetVal(_T("configdir"));
404 // g_GitGlobal.SetConfigDir(sConfigDir);
406 // to avoid that SASL will look for and load its plugin dlls all around the
407 // system, we set the path here.
408 // Note that SASL doesn't have to be initialized yet for this to work
409 // sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));
411 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
412 if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))
414 int i=0;
415 for(i=0;i<pathList.GetCount();i++)
416 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
417 break;
420 if(!g_Git.m_CurrentDir.IsEmpty())
422 sOrigCWD = g_Git.m_CurrentDir;
423 SetCurrentDirectory(g_Git.m_CurrentDir);
427 CString err;
430 // requires CWD to be set
431 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
433 catch (char* msg)
435 err = CString(msg);
438 if (!err.IsEmpty())
440 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)));
441 if (choice == 1)
443 // open the config file with alternative editor
444 CString path;
445 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, path);
446 path += _T("config");
447 CAppUtils::LaunchAlternativeEditor(path);
449 else if (choice == 2)
451 // open the global config file with alternative editor
452 char charBuf[MAX_PATH];
453 TCHAR buf[MAX_PATH];
454 strcpy_s(charBuf, MAX_PATH, get_windows_home_directory());
455 _tcscpy_s(buf, MAX_PATH, CA2CT(charBuf));
456 _tcscat_s(buf, MAX_PATH, _T("\\.gitconfig"));
457 CAppUtils::LaunchAlternativeEditor(buf);
459 return FALSE;
463 // execute the requested command
464 CommandServer server;
465 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
466 if (cmd)
468 cmd->SetExplorerHwnd(hWndExplorer);
470 cmd->SetParser(parser);
471 cmd->SetPaths(pathList, cmdLinePath);
473 retSuccess = cmd->Execute();
474 delete cmd;
477 // Look for temporary files left around by TortoiseSVN and
478 // remove them. But only delete 'old' files because some
479 // apps might still be needing the recent ones.
481 DWORD len = ::GetTempPath(0, NULL);
482 TCHAR * path = new TCHAR[len + 100];
483 len = ::GetTempPath (len+100, path);
484 if (len != 0)
486 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
487 FILETIME systime_;
488 ::GetSystemTimeAsFileTime(&systime_);
489 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
490 while (finder.FindNextFileNoDirectories())
492 CString filepath = finder.GetFilePath();
493 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
494 if (hFile != INVALID_HANDLE_VALUE)
496 FILETIME createtime_;
497 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
499 ::CloseHandle(hFile);
500 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
501 if ((createtime + 864000000000) < systime) //only delete files older than a day
503 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
504 ::DeleteFile(filepath);
507 else
508 ::CloseHandle(hFile);
512 delete[] path;
515 // Since the dialog has been closed, return FALSE so that we exit the
516 // application, rather than start the application's message pump.
517 return FALSE;
520 void CTortoiseProcApp::CheckUpgrade()
522 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
523 CString sVersion = regVersion;
524 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
525 return;
526 // we're starting the first time with a new version!
528 LONG lVersion = 0;
529 int pos = sVersion.Find(',');
530 if (pos > 0)
532 lVersion = (_ttol(sVersion.Left(pos))<<24);
533 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
534 pos = sVersion.Find(',', pos+1);
535 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
538 if (lVersion <= 0x01070600)
540 CoInitialize(NULL);
541 EnsureGitLibrary();
542 CoUninitialize();
543 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
544 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
545 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
546 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
547 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
549 #if 0
550 if (lVersion <= 0x01010300)
552 CSoundUtils::RegisterTSVNSounds();
554 #endif
555 if (lVersion <= 0x01020200)
557 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
558 // so remove the diff/merge scripts if they're the defaults
559 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
560 CString sDiff = diffreg;
561 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
562 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
563 diffreg = _T("");
564 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
565 sDiff = mergereg;
566 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
567 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
568 mergereg = _T("");
570 if (lVersion <= 0x01040000)
572 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
575 // set the custom diff scripts for every user
576 CString scriptsdir = CPathUtils::GetAppParentDirectory();
577 scriptsdir += _T("Diff-Scripts");
578 CSimpleFileFind files(scriptsdir);
579 while (files.FindNextFileNoDirectories())
581 CString file = files.GetFilePath();
582 CString filename = files.GetFileName();
583 CString ext = file.Mid(file.ReverseFind('-')+1);
584 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
585 CString kind;
586 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
588 kind = _T(" //E:vbscript");
590 if (file.Right(2).CompareNoCase(_T("js"))==0)
592 kind = _T(" //E:javascript");
595 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
597 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
598 CString diffregstring = diffreg;
599 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
600 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
602 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
604 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
605 CString diffregstring = diffreg;
606 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
607 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
611 // set the current version so we don't come here again until the next update!
612 regVersion = _T(STRPRODUCTVER);
615 void CTortoiseProcApp::EnableCrashHandler()
617 // the crash handler is enabled by default, but we disable it
618 // after 3 months after a release
620 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
621 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
623 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
624 : __DATE__ [2] == 'b' ? 2 \
625 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
626 : __DATE__ [2] == 'y' ? 5 \
627 : __DATE__ [2] == 'l' ? 7 \
628 : __DATE__ [2] == 'g' ? 8 \
629 : __DATE__ [2] == 'p' ? 9 \
630 : __DATE__ [2] == 't' ? 10 \
631 : __DATE__ [2] == 'v' ? 11 : 12)
633 #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
634 + (__DATE__ [5] - '0'))
636 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
638 CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);
639 CTime now = CTime::GetCurrentTime();
641 CTimeSpan timediff = now-compiletime;
642 if (timediff.GetDays() > 3*31)
644 // crasher.Enable(FALSE);
648 void CTortoiseProcApp::InitializeJumpList()
650 // for Win7 : use a custom jump list
651 CoInitialize(NULL);
652 SetAppID(APPID);
653 DeleteJumpList(APPID);
654 DoInitializeJumpList();
655 CoUninitialize();
658 void CTortoiseProcApp::DoInitializeJumpList()
660 ATL::CComPtr<ICustomDestinationList> pcdl;
661 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
662 if (FAILED(hr))
663 return;
665 hr = pcdl->SetAppID(APPID);
666 if (FAILED(hr))
667 return;
669 UINT uMaxSlots;
670 ATL::CComPtr<IObjectArray> poaRemoved;
671 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
672 if (FAILED(hr))
673 return;
675 ATL::CComPtr<IObjectCollection> poc;
676 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
677 if (FAILED(hr))
678 return;
680 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
681 sTemp.Remove('&');
683 ATL::CComPtr<IShellLink> psl;
684 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
685 if (SUCCEEDED(hr)) {
686 poc->AddObject(psl);
688 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
689 sTemp.Remove('&');
690 psl.Release(); // Need to release the object before calling operator&()
691 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
692 if (SUCCEEDED(hr)) {
693 poc->AddObject(psl);
696 ATL::CComPtr<IObjectArray> poa;
697 hr = poc.QueryInterface(&poa);
698 if (SUCCEEDED(hr)) {
699 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
700 pcdl->CommitList();
704 int CTortoiseProcApp::ExitInstance()
706 Gdiplus::GdiplusShutdown(m_gdiplusToken);
708 CWinAppEx::ExitInstance();
709 if (retSuccess)
710 return 0;
711 return -1;
714 void CTortoiseProcApp::CheckForNewerVersion()
716 // check for newer versions
717 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
719 time_t now;
720 struct tm ptm;
722 time(&now);
723 if ((now != 0) && (localtime_s(&ptm, &now)==0))
725 int week = 0;
726 // we don't calculate the real 'week of the year' here
727 // because just to decide if we should check for an update
728 // that's not needed.
729 week = ptm.tm_yday / 7;
731 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
732 if (((DWORD)oldweek) == -1)
733 oldweek = week; // first start of TortoiseProc, no update check needed
734 else
736 if ((DWORD)week != oldweek)
738 oldweek = week;
740 TCHAR com[MAX_PATH+100];
741 GetModuleFileName(NULL, com, MAX_PATH);
742 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
744 CAppUtils::LaunchApplication(com, 0, false);