Add try-catch blocks and critical sections to wrap libgit functions in CLogDataVector...
[TortoiseGit.git] / src / TortoiseUDiff / TortoiseUDiff.cpp
blob243ddcca26fe63881b01243ff8d529b6eeae9b95
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008, 2010-2012 - TortoiseSVN
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.
19 #include "stdafx.h"
20 #include "TortoiseUDiff.h"
21 #include "MainWindow.h"
22 #include "CmdLineParser.h"
23 #include "TaskbarUUID.h"
25 #include <commctrl.h>
26 #pragma comment(lib, "comctl32.lib")
29 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
32 int APIENTRY _tWinMain(HINSTANCE hInstance,
33 HINSTANCE /*hPrevInstance*/,
34 LPTSTR lpCmdLine,
35 int /*nCmdShow*/)
37 SetDllDirectory(L"");
38 SetTaskIDPerUUID();
39 MSG msg;
40 HACCEL hAccelTable;
42 CCmdLineParser parser(lpCmdLine);
44 if (parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
46 TCHAR buf[1024];
47 LoadString(hInstance, IDS_COMMANDLINEHELP, buf, sizeof(buf)/sizeof(TCHAR));
48 MessageBox(NULL, buf, _T("TortoiseGitUDiff"), MB_ICONINFORMATION);
49 return 0;
52 INITCOMMONCONTROLSEX used = {
53 sizeof(INITCOMMONCONTROLSEX),
54 ICC_STANDARD_CLASSES | ICC_BAR_CLASSES
56 InitCommonControlsEx(&used);
59 HMODULE hSciLexerDll = ::LoadLibrary(_T("SciLexer.DLL"));
60 if (hSciLexerDll == NULL)
61 return FALSE;
63 CMainWindow mainWindow(hInstance);
64 mainWindow.SetRegistryPath(_T("Software\\TortoiseGit\\UDiffViewerWindowPos"));
65 if (parser.HasVal(_T("title")))
66 mainWindow.SetTitle(parser.GetVal(_T("title")));
67 else if (parser.HasVal(_T("patchfile")))
68 mainWindow.SetTitle(parser.GetVal(_T("patchfile")));
69 else
70 mainWindow.SetTitle(_T("diff from pipe"));
72 if (!mainWindow.RegisterAndCreateWindow())
74 FreeLibrary(hSciLexerDll);
75 return 0;
78 bool bLoadedSuccessfully = false;
79 if ( (lpCmdLine[0] == 0) ||
80 (parser.HasKey(_T("p"))) )
82 // input from console pipe
83 // set console to raw mode
84 DWORD oldMode;
85 GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldMode);
86 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
88 bLoadedSuccessfully = mainWindow.LoadFile(GetStdHandle(STD_INPUT_HANDLE));
90 else if (parser.HasVal(_T("patchfile")))
91 bLoadedSuccessfully = mainWindow.LoadFile(parser.GetVal(_T("patchfile")));
92 else if (lpCmdLine[0] != 0)
93 bLoadedSuccessfully = mainWindow.LoadFile(lpCmdLine);
96 if (!bLoadedSuccessfully)
98 FreeLibrary(hSciLexerDll);
99 return 0;
102 ::ShowWindow(mainWindow.GetHWNDEdit(), SW_SHOW);
103 ::SetFocus(mainWindow.GetHWNDEdit());
105 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TORTOISEUDIFF));
107 // Main message loop:
108 while (GetMessage(&msg, NULL, 0, 0))
110 if (!TranslateAccelerator(mainWindow, hAccelTable, &msg))
112 TranslateMessage(&msg);
113 DispatchMessage(&msg);
117 FreeLibrary(hSciLexerDll);
118 return (int) msg.wParam;