1 // TortoiseIDiff - an image diff viewer in TortoiseSVN and TortoiseGit
3 // Copyright (C) 2006-2007, 2010-2013 - 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.
20 #include "MainWindow.h"
21 #include "CmdLineParser.h"
24 #include "TortoiseIDiff.h"
25 #include "TaskbarUUID.h"
28 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
31 HINSTANCE hInst
; // current instance
32 HINSTANCE hResource
; // the resource dll
36 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
37 HINSTANCE
/*hPrevInstance*/,
43 CRegStdDWORD loc
= CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
45 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
48 hResource
= langDLL
.Init(_T("TortoiseIDiff"), langId
);
49 if (hResource
== NULL
)
50 hResource
= hInstance
;
52 CCmdLineParser
parser(lpCmdLine
);
54 if (parser
.HasKey(_T("?")) || parser
.HasKey(_T("help")))
57 LoadString(hResource
, IDS_COMMANDLINEHELP
, buf
, _countof(buf
));
58 MessageBox(NULL
, buf
, _T("TortoiseIDiff"), MB_ICONINFORMATION
);
67 INITCOMMONCONTROLSEX used
= {
68 sizeof(INITCOMMONCONTROLSEX
),
69 ICC_STANDARD_CLASSES
| ICC_BAR_CLASSES
| ICC_WIN95_CLASSES
71 InitCommonControlsEx(&used
);
73 // load the cursors we need
74 curHand
= (HCURSOR
)LoadImage(hInst
, MAKEINTRESOURCE(IDC_PANCUR
), IMAGE_CURSOR
, 0, 0, LR_DEFAULTSIZE
);
75 curHandDown
= (HCURSOR
)LoadImage(hInst
, MAKEINTRESOURCE(IDC_PANDOWNCUR
), IMAGE_CURSOR
, 0, 0, LR_DEFAULTSIZE
);
77 std::unique_ptr
<CMainWindow
> mainWindow(new CMainWindow(hResource
));
78 mainWindow
->SetRegistryPath(_T("Software\\TortoiseGit\\TortoiseIDiffWindowPos"));
79 std::wstring leftfile
= parser
.HasVal(_T("left")) ? parser
.GetVal(_T("left")) : _T("");
80 std::wstring rightfile
= parser
.HasVal(_T("right")) ? parser
.GetVal(_T("right")) : _T("");
81 if ((leftfile
.empty()) && (lpCmdLine
[0] != 0))
84 LPWSTR
* szArglist
= CommandLineToArgvW(GetCommandLineW(), &nArgs
);
93 if (PathFileExists(szArglist
[1]) && PathFileExists(szArglist
[2]))
95 leftfile
= szArglist
[1];
96 rightfile
= szArglist
[2];
101 // Free memory allocated for CommandLineToArgvW arguments.
102 LocalFree(szArglist
);
104 mainWindow
->SetLeft(leftfile
.c_str(), parser
.HasVal(_T("lefttitle")) ? parser
.GetVal(_T("lefttitle")) : _T(""));
105 mainWindow
->SetRight(rightfile
.c_str(), parser
.HasVal(_T("righttitle")) ? parser
.GetVal(_T("righttitle")) : _T(""));
106 if (parser
.HasVal(L
"base"))
107 mainWindow
->SetSelectionImage(FileTypeBase
, parser
.GetVal(L
"base"), parser
.HasVal(L
"basetitle") ? parser
.GetVal(L
"basetitle") : L
"");
108 if (parser
.HasVal(L
"mine"))
109 mainWindow
->SetSelectionImage(FileTypeMine
, parser
.GetVal(L
"mine"), parser
.HasVal(L
"minetitle") ? parser
.GetVal(L
"minetitle") : L
"");
110 if (parser
.HasVal(L
"theirs"))
111 mainWindow
->SetSelectionImage(FileTypeTheirs
, parser
.GetVal(L
"theirs"), parser
.HasVal(L
"theirstitle") ? parser
.GetVal(L
"theirstitle") : L
"");
112 if (parser
.HasVal(L
"result"))
113 mainWindow
->SetSelectionResult(parser
.GetVal(L
"result"));
114 if (mainWindow
->RegisterAndCreateWindow())
116 HACCEL hAccelTable
= LoadAccelerators(hResource
, MAKEINTRESOURCE(IDR_TORTOISEIDIFF
));
117 if (!parser
.HasVal(L
"left") && parser
.HasVal(L
"base") && !parser
.HasVal(L
"mine") && !parser
.HasVal(L
"theirs"))
119 PostMessage(*mainWindow
, WM_COMMAND
, ID_FILE_OPEN
, 0);
121 if (parser
.HasKey(_T("overlay")))
123 PostMessage(*mainWindow
, WM_COMMAND
, ID_VIEW_OVERLAPIMAGES
, 0);
125 if (parser
.HasKey(_T("fit")))
127 PostMessage(*mainWindow
, WM_COMMAND
, ID_VIEW_FITIMAGEHEIGHTS
, 0);
128 PostMessage(*mainWindow
, WM_COMMAND
, ID_VIEW_FITIMAGEWIDTHS
, 0);
130 if (parser
.HasKey(_T("fitwidth")))
132 PostMessage(*mainWindow
, WM_COMMAND
, ID_VIEW_FITIMAGEWIDTHS
, 0);
134 if (parser
.HasKey(_T("fitheight")))
136 PostMessage(*mainWindow
, WM_COMMAND
, ID_VIEW_FITIMAGEHEIGHTS
, 0);
138 if (parser
.HasKey(_T("showinfo")))
140 PostMessage(*mainWindow
, WM_COMMAND
, ID_VIEW_IMAGEINFO
, 0);
142 // Main message loop:
143 while (GetMessage(&msg
, NULL
, 0, 0))
145 if (!TranslateAccelerator(*mainWindow
, hAccelTable
, &msg
))
147 TranslateMessage(&msg
);
148 DispatchMessage(&msg
);
151 return (int) msg
.wParam
;
154 DestroyCursor(curHand
);
155 DestroyCursor(curHandDown
);