Replace var++ by ++var and use size_t where necessary
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob41f476fe48e9e11c0cb8d7d342e697a9a474daae
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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 "TortoiseProc.h"
22 #include "SysImageList.h"
23 #include "..\Utils\CrashReport.h"
24 #include "CmdLineParser.h"
25 #include "Hooks.h"
26 #include "AppUtils.h"
27 #include "PathUtils.h"
28 #include "UnicodeUtils.h"
29 #include "MessageBox.h"
30 //#include "libintl.h"
31 #include "DirFileEnum.h"
32 //#include "SoundUtils.h"
33 #include "GitAdminDir.h"
34 #include "Git.h"
35 #include "SmartHandle.h"
36 #include "Commands\Command.h"
37 #include "..\version.h"
38 #include "JumpListHelpers.h"
39 #include "SinglePropSheetDlg.h"
40 #include "Settings\setmainpage.h"
41 #include "..\Settings\Settings.h"
42 #include "gitindex.h"
43 #include "Libraries.h"
45 #define STRUCT_IOVEC_DEFINED
47 #ifdef _DEBUG
48 #define new DEBUG_NEW
49 #endif
51 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
53 #define APPID (_T("TGIT.TGIT.1") _T(TGIT_PLATFORM))
55 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
56 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
57 END_MESSAGE_MAP()
59 //CString g_version;
60 //CString CGit::m_MsysGitPath;
61 //////////////////////////////////////////////////////////////////////////
63 CTortoiseProcApp::CTortoiseProcApp()
65 SetDllDirectory(L"");
66 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
67 EnableHtmlHelp();
68 // int argc = 0;
69 // const char* const * argv = NULL;
70 SYS_IMAGE_LIST();
71 CHooks::Create();
72 m_bLoadUserToolbars = FALSE;
73 m_bSaveState = FALSE;
74 retSuccess = false;
75 m_gdiplusToken = NULL;
79 CTortoiseProcApp::~CTortoiseProcApp()
81 CHooks::Destroy();
82 SYS_IMAGE_LIST().Cleanup();
85 // The one and only CTortoiseProcApp object
86 CTortoiseProcApp theApp;
87 CString sOrigCWD;
88 HWND hWndExplorer;
90 BOOL CTortoiseProcApp::CheckMsysGitDir()
92 //CGitIndexFileMap map;
93 //int status;
94 //CTGitPath path;
95 //path.SetFromGit(_T("src/gpl.txt"));
96 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
97 return g_Git.CheckMsysGitDir();
99 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
101 // CTortoiseProcApp initialization
103 BOOL CTortoiseProcApp::InitInstance()
105 CheckUpgrade();
106 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
107 CMFCButton::EnableWindowsTheming();
109 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
110 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
112 //set the resource dll for the required language
113 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
114 long langId = loc;
115 CString langDll;
116 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
117 langpath += "Languages";
118 // bindtextdomain("subversion", (LPCSTR)langpath);
119 // bind_textdomain_codeset("subversion", "UTF-8");
120 HINSTANCE hInst = NULL;
123 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
125 hInst = LoadLibrary(langDll);
127 CString sVer = _T(STRPRODUCTVER);
128 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
129 if (sFileVer.Compare(sVer)!=0)
131 FreeLibrary(hInst);
132 hInst = NULL;
134 if (hInst != NULL)
136 AfxSetResourceHandle(hInst);
138 else
140 DWORD lid = SUBLANGID(langId);
141 lid--;
142 if (lid > 0)
144 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
146 else
147 langId = 0;
149 } while ((hInst == NULL) && (langId != 0));
150 TCHAR buf[6];
151 _tcscpy_s(buf, _T("en"));
152 langId = loc;
153 // MFC uses a help file with the same name as the application by default,
154 // which means we have to change that default to our language specific help files
155 CString sHelppath = CPathUtils::GetAppDirectory() + _T("TortoiseGit_en.chm");
156 free((void*)m_pszHelpFilePath);
157 m_pszHelpFilePath=_tcsdup(sHelppath);
158 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
161 CString sLang = _T("_");
162 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
164 sLang += buf;
165 sHelppath.Replace(_T("_en"), sLang);
166 if (PathFileExists(sHelppath))
168 free((void*)m_pszHelpFilePath);
169 m_pszHelpFilePath=_tcsdup(sHelppath);
170 break;
173 sHelppath.Replace(sLang, _T("_en"));
174 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
176 sLang += _T("_");
177 sLang += buf;
178 sHelppath.Replace(_T("_en"), sLang);
179 if (PathFileExists(sHelppath))
181 free((void*)m_pszHelpFilePath);
182 m_pszHelpFilePath=_tcsdup(sHelppath);
183 break;
186 sHelppath.Replace(sLang, _T("_en"));
188 DWORD lid = SUBLANGID(langId);
189 lid--;
190 if (lid > 0)
192 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
194 else
195 langId = 0;
196 } while (langId);
197 setlocale(LC_ALL, "");
199 if(!CheckMsysGitDir())
201 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
202 if(ret == 2)
204 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
206 else if(ret == 1)
208 // open settings dialog
209 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
211 return FALSE;
213 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
215 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);
216 if (ret == 1)
218 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
219 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
220 return FALSE;
222 else if (ret == 2)
224 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
225 return FALSE;
229 // InitCommonControls() is required on Windows XP if an application
230 // manifest specifies use of ComCtl32.dll version 6 or later to enable
231 // visual styles. Otherwise, any window creation will fail.
233 INITCOMMONCONTROLSEX used = {
234 sizeof(INITCOMMONCONTROLSEX),
235 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
236 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
237 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
238 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
239 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
241 InitCommonControlsEx(&used);
242 AfxOleInit();
243 AfxEnableControlContainer();
244 AfxInitRichEdit2();
245 CWinAppEx::InitInstance();
246 SetRegistryKey(_T("TortoiseGit"));
247 AfxGetApp()->m_pszProfileName = _tcsdup(_T("TortoiseProc")); // w/o this ResizableLib will store data under TortoiseGitProc which is not compatible with older versions
249 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
251 hWndExplorer = NULL;
252 CString sVal = parser.GetVal(_T("hwnd"));
253 if (!sVal.IsEmpty())
254 hWndExplorer = (HWND)_ttoi64(sVal);
256 while (GetParent(hWndExplorer)!=NULL)
257 hWndExplorer = GetParent(hWndExplorer);
258 if (!IsWindow(hWndExplorer))
260 hWndExplorer = NULL;
263 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
264 // in a message box
265 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
266 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
268 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
270 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
271 return FALSE;
274 CTGitPath cmdLinePath;
275 CTGitPathList pathList;
276 if ( parser.HasKey(_T("pathfile")) )
279 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
281 cmdLinePath.SetFromUnknown(sPathfileArgument);
282 if (pathList.LoadFromFile(cmdLinePath)==false)
283 return FALSE; // no path specified!
284 if ( parser.HasKey(_T("deletepathfile")) )
286 // We can delete the temporary path file, now that we've loaded it
287 ::DeleteFile(cmdLinePath.GetWinPath());
289 // This was a path to a temporary file - it's got no meaning now, and
290 // anybody who uses it again is in for a problem...
291 cmdLinePath.Reset();
294 else
297 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
298 if (parser.HasKey(_T("expaths")))
300 // an /expaths param means we're started via the buttons in our Win7 library
301 // and that means the value of /expaths is the current directory, and
302 // the selected paths are then added as additional parameters but without a key, only a value
304 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
305 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
306 // a save bet.
307 // Without this, a command line like:
308 // /command:commit /expaths:"D:\" "D:\Utils"
309 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
310 // mark and we'd end up with:
311 // argv[1] = /command:commit
312 // argv[2] = /expaths:D:" D:\Utils
313 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
314 CString cmdLine = GetCommandLineW();
315 cmdLine.Replace(L"\\", L"\\\\");
316 int nArgs = 0;
317 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
318 if (szArglist)
320 // argument 0 is the process path, so start with 1
321 for (int i = 1; i < nArgs; ++i)
323 if (szArglist[i][0] != '/')
325 if (!sPathArgument.IsEmpty())
326 sPathArgument += '*';
327 sPathArgument += szArglist[i];
330 sPathArgument.Replace(L"\\\\", L"\\");
332 LocalFree(szArglist);
334 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
336 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
337 return FALSE;
339 int asterisk = sPathArgument.Find('*');
340 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
341 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
344 if (pathList.GetCount() == 0) {
345 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
348 InitializeJumpList();
349 EnsureGitLibrary(false);
351 // Subversion sometimes writes temp files to the current directory!
352 // Since TSVN doesn't need a specific CWD anyway, we just set it
353 // to the users temp folder: that way, Subversion is guaranteed to
354 // have write access to the CWD
356 DWORD len = GetCurrentDirectory(0, NULL);
357 if (len)
359 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
360 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
362 sOrigCWD = originalCurrentDirectory.get();
363 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
366 TCHAR pathbuf[MAX_PATH];
367 GetTortoiseGitTempPath(MAX_PATH, pathbuf);
368 SetCurrentDirectory(pathbuf);
371 CheckForNewerVersion();
373 if (parser.HasVal(_T("configdir")))
375 // the user can override the location of the Subversion config directory here
376 CString sConfigDir = parser.GetVal(_T("configdir"));
377 // g_GitGlobal.SetConfigDir(sConfigDir);
380 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
381 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
383 for (int i = 0; i < pathList.GetCount(); ++i)
384 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
385 break;
388 if(!g_Git.m_CurrentDir.IsEmpty())
390 sOrigCWD = g_Git.m_CurrentDir;
391 SetCurrentDirectory(g_Git.m_CurrentDir);
395 CString err;
398 // requires CWD to be set
399 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
401 // make sure all config files are read in order to check that none contains an error
402 g_Git.GetConfigValue(_T("doesnot.exist"));
404 catch (char* msg)
406 err = CString(msg);
409 if (!err.IsEmpty())
411 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)));
412 if (choice == 1)
414 // open the config file with alternative editor
415 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
417 else if (choice == 2)
419 // open the global config file with alternative editor
420 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
422 return FALSE;
426 // execute the requested command
427 CommandServer server;
428 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
429 if (cmd)
431 cmd->SetExplorerHwnd(hWndExplorer);
433 cmd->SetParser(parser);
434 cmd->SetPaths(pathList, cmdLinePath);
436 retSuccess = cmd->Execute();
437 delete cmd;
440 // Look for temporary files left around by TortoiseSVN and
441 // remove them. But only delete 'old' files because some
442 // apps might still be needing the recent ones.
444 DWORD len = GetTortoiseGitTempPath(0, NULL);
445 std::unique_ptr<TCHAR[]> path(new TCHAR[len + 100]);
446 len = GetTortoiseGitTempPath (len + 100, path.get());
447 if (len != 0)
449 CDirFileEnum finder(path.get());
450 FILETIME systime_;
451 ::GetSystemTimeAsFileTime(&systime_);
452 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
453 bool isDir;
454 CString filepath;
455 while (finder.NextFile(filepath, &isDir))
457 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, isDir ? FILE_FLAG_BACKUP_SEMANTICS : NULL, NULL);
458 if (hFile != INVALID_HANDLE_VALUE)
460 FILETIME createtime_;
461 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
463 ::CloseHandle(hFile);
464 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
465 if ((createtime + 864000000000) < systime) //only delete files older than a day
467 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
468 if (isDir)
469 ::RemoveDirectory(filepath);
470 else
471 ::DeleteFile(filepath);
474 else
475 ::CloseHandle(hFile);
481 // Since the dialog has been closed, return FALSE so that we exit the
482 // application, rather than start the application's message pump.
483 return FALSE;
486 void CTortoiseProcApp::CheckUpgrade()
488 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
489 CString sVersion = regVersion;
490 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
491 return;
492 // we're starting the first time with a new version!
494 LONG lVersion = 0;
495 int pos = sVersion.Find('.');
496 if (pos > 0)
498 lVersion = (_ttol(sVersion.Left(pos))<<24);
499 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
500 pos = sVersion.Find('.', pos+1);
501 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
503 else
505 pos = sVersion.Find(',');
506 if (pos > 0)
508 lVersion = (_ttol(sVersion.Left(pos))<<24);
509 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
510 pos = sVersion.Find(',', pos+1);
511 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
515 #if 0
516 if (lVersion <= 0x01010300)
518 CSoundUtils::RegisterTSVNSounds();
520 #endif
522 if (lVersion <= 0x01040000)
524 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
527 if (lVersion <= 0x01070600)
529 CoInitialize(NULL);
530 EnsureGitLibrary();
531 CoUninitialize();
532 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
533 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
534 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
535 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
538 if (lVersion <= 0x01070E00)
540 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
541 // upgrade to 1.7.15: force recreation of all diff scripts.
542 CAppUtils::SetupDiffScripts(true, CString());
544 CAppUtils::SetupDiffScripts(false, CString());
546 // set the current version so we don't come here again until the next update!
547 regVersion = _T(STRPRODUCTVER);
550 void CTortoiseProcApp::InitializeJumpList()
552 // for Win7 : use a custom jump list
553 CoInitialize(NULL);
554 SetAppID(APPID);
555 DeleteJumpList(APPID);
556 DoInitializeJumpList();
557 CoUninitialize();
560 void CTortoiseProcApp::DoInitializeJumpList()
562 ATL::CComPtr<ICustomDestinationList> pcdl;
563 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
564 if (FAILED(hr))
565 return;
567 hr = pcdl->SetAppID(APPID);
568 if (FAILED(hr))
569 return;
571 UINT uMaxSlots;
572 ATL::CComPtr<IObjectArray> poaRemoved;
573 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
574 if (FAILED(hr))
575 return;
577 ATL::CComPtr<IObjectCollection> poc;
578 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
579 if (FAILED(hr))
580 return;
582 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
583 sTemp.Remove('&');
585 ATL::CComPtr<IShellLink> psl;
586 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
587 if (SUCCEEDED(hr)) {
588 poc->AddObject(psl);
590 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
591 sTemp.Remove('&');
592 psl.Release(); // Need to release the object before calling operator&()
593 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
594 if (SUCCEEDED(hr)) {
595 poc->AddObject(psl);
598 ATL::CComPtr<IObjectArray> poa;
599 hr = poc.QueryInterface(&poa);
600 if (SUCCEEDED(hr)) {
601 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
602 pcdl->CommitList();
606 int CTortoiseProcApp::ExitInstance()
608 Gdiplus::GdiplusShutdown(m_gdiplusToken);
610 CWinAppEx::ExitInstance();
611 if (retSuccess)
612 return 0;
613 return -1;
616 void CTortoiseProcApp::CheckForNewerVersion()
618 // check for newer versions
619 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
621 time_t now;
622 struct tm ptm;
624 time(&now);
625 if ((now != 0) && (localtime_s(&ptm, &now)==0))
627 #if PREVIEW
628 // Check daily for new preview releases
629 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
630 if (((DWORD)oldday) == -1)
631 oldday = ptm.tm_yday;
632 else
634 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
636 oldday = ptm.tm_yday;
637 #else
638 int week = 0;
639 // we don't calculate the real 'week of the year' here
640 // because just to decide if we should check for an update
641 // that's not needed.
642 week = ptm.tm_yday / 7;
644 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
645 if (((DWORD)oldweek) == -1)
646 oldweek = week; // first start of TortoiseProc, no update check needed
647 else
649 if ((DWORD)week != oldweek)
651 oldweek = week;
652 #endif
653 TCHAR com[MAX_PATH+100];
654 GetModuleFileName(NULL, com, MAX_PATH);
655 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
657 CAppUtils::LaunchApplication(com, 0, false);