Update OGDF to the latest stable release (v. 2015.05, Baobab)
[TortoiseGit.git] / src / TortoiseUDiff / TortoiseUDiff.cpp
blobb2ed732e212030592b9920cd870ac7b112c3c4de
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2017 - TortoiseGit
4 // Copyright (C) 2003-2008, 2010-2012, 2014-2015 - 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 "TortoiseUDiff.h"
22 #include "MainWindow.h"
23 #include "CmdLineParser.h"
24 #include "TaskbarUUID.h"
25 #include "registry.h"
26 #include "LangDll.h"
27 #include "../version.h"
28 #include "../Utils/CrashReport.h"
29 #include <algorithm>
30 #include <commctrl.h>
31 #pragma comment(lib, "comctl32.lib")
33 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
35 HINSTANCE hResource; // the resource dll
37 int APIENTRY _tWinMain(HINSTANCE hInstance,
38 HINSTANCE /*hPrevInstance*/,
39 LPTSTR lpCmdLine,
40 int /*nCmdShow*/)
42 SetDllDirectory(L"");
43 SetTaskIDPerUUID();
44 CRegStdDWORD loc = CRegStdDWORD(L"Software\\TortoiseGit\\LanguageID", 1033);
45 long langId = loc;
46 MSG msg;
47 HACCEL hAccelTable;
49 #if ENABLE_CRASHHANLDER
50 CCrashReportTGit crasher(L"TortoiseGitUDiff " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
51 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
52 #endif
54 CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
56 CLangDll langDLL;
57 hResource = langDLL.Init(L"TortoiseGitUDiff", langId);
58 if (!hResource)
59 hResource = hInstance;
61 CCmdLineParser parser(lpCmdLine);
63 if (parser.HasKey(L"?") || parser.HasKey(L"help"))
65 ResString rHelp(hResource, IDS_COMMANDLINEHELP);
66 MessageBox(nullptr, rHelp, L"TortoiseGitUDiff", MB_ICONINFORMATION);
67 return 0;
70 INITCOMMONCONTROLSEX used = {
71 sizeof(INITCOMMONCONTROLSEX),
72 ICC_STANDARD_CLASSES | ICC_BAR_CLASSES
74 InitCommonControlsEx(&used);
77 HMODULE hSciLexerDll = ::LoadLibrary(L"SciLexer_tgit.dll");
78 if (!hSciLexerDll)
79 return FALSE;
81 CMainWindow mainWindow(hResource);
82 mainWindow.SetRegistryPath(L"Software\\TortoiseGit\\UDiffViewerWindowPos");
83 if (parser.HasVal(L"title"))
84 mainWindow.SetTitle(parser.GetVal(L"title"));
85 else if (parser.HasVal(L"patchfile"))
86 mainWindow.SetTitle(parser.GetVal(L"patchfile"));
87 else if (lpCmdLine[0])
89 // remove double quotes
90 std::wstring path = lpCmdLine;
91 path.erase(std::remove(path.begin(), path.end(), L'"'), path.end());
92 mainWindow.SetTitle(path.c_str());
94 else
96 ResString rPipeTitle(hResource, IDS_PIPETITLE);
97 mainWindow.SetTitle(rPipeTitle);
100 if (!mainWindow.RegisterAndCreateWindow())
102 FreeLibrary(hSciLexerDll);
103 return 0;
106 bool bLoadedSuccessfully = false;
107 if ((lpCmdLine[0] == L'\0') || (parser.HasKey(L"p")))
109 // input from console pipe
110 // set console to raw mode
111 DWORD oldMode;
112 GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldMode);
113 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
115 bLoadedSuccessfully = mainWindow.LoadFile(GetStdHandle(STD_INPUT_HANDLE));
117 else if (parser.HasVal(L"patchfile"))
118 bLoadedSuccessfully = mainWindow.LoadFile(parser.GetVal(L"patchfile"));
119 else if (lpCmdLine[0] != L'\0')
121 // remove double quotes
122 std::wstring path = lpCmdLine;
123 path.erase(std::remove(path.begin(), path.end(), '"'), path.end());
124 bLoadedSuccessfully = mainWindow.LoadFile(path.c_str());
127 if (!bLoadedSuccessfully)
129 FreeLibrary(hSciLexerDll);
130 return 0;
133 ::ShowWindow(mainWindow.GetHWNDEdit(), SW_SHOW);
134 ::SetFocus(mainWindow.GetHWNDEdit());
136 hAccelTable = LoadAccelerators(hResource, MAKEINTRESOURCE(IDC_TORTOISEUDIFF));
138 // Main message loop:
139 while (GetMessage(&msg, nullptr, 0, 0))
141 if (!TranslateAccelerator(mainWindow, hAccelTable, &msg))
143 TranslateMessage(&msg);
144 DispatchMessage(&msg);
148 FreeLibrary(hSciLexerDll);
149 return (int) msg.wParam;