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.
21 #include "TortoiseUDiff.h"
22 #include "MainWindow.h"
23 #include "CmdLineParser.h"
24 #include "TaskbarUUID.h"
27 #include "../version.h"
28 #include "../Utils/CrashReport.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*/,
44 CRegStdDWORD loc
= CRegStdDWORD(L
"Software\\TortoiseGit\\LanguageID", 1033);
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());
54 CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED
);
57 hResource
= langDLL
.Init(L
"TortoiseGitUDiff", langId
);
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
);
70 INITCOMMONCONTROLSEX used
= {
71 sizeof(INITCOMMONCONTROLSEX
),
72 ICC_STANDARD_CLASSES
| ICC_BAR_CLASSES
74 InitCommonControlsEx(&used
);
77 HMODULE hSciLexerDll
= ::LoadLibrary(L
"SciLexer_tgit.dll");
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());
96 ResString
rPipeTitle(hResource
, IDS_PIPETITLE
);
97 mainWindow
.SetTitle(rPipeTitle
);
100 if (!mainWindow
.RegisterAndCreateWindow())
102 FreeLibrary(hSciLexerDll
);
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
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
);
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
;