OSDN Git Service

Fix Amend Last Commit CheckBox wrong Position
[tortoisegit/TortoiseGitJp.git] / src / TortoiseShell / TortoiseSVN.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "ShellExt.h"\r
21 #include "Guids.h"\r
22 #include "ShellExtClassFactory.h"\r
23 //#include "git_dso.h"\r
24 \r
25 UINT                            g_cRefThisDll = 0;                              ///< reference count of this DLL.\r
26 HINSTANCE                       g_hmodThisDll = NULL;                   ///< handle to this DLL itself.\r
27 int                                     g_cAprInit = 0;\r
28 ShellCache                      g_ShellCache;                                   ///< caching of registry entries, ...\r
29 DWORD                           g_langid;\r
30 DWORD                           g_langTimeout = 0;\r
31 HINSTANCE                       g_hResInst = NULL;\r
32 stdstring                       g_filepath;\r
33 git_wc_status_kind      g_filestatus = git_wc_status_none;      ///< holds the corresponding status to the file/dir above\r
34 bool                            g_readonlyoverlay = false;\r
35 bool                            g_lockedoverlay = false;\r
36 \r
37 bool                            g_normalovlloaded = false;\r
38 bool                            g_modifiedovlloaded = false;\r
39 bool                            g_conflictedovlloaded = false;\r
40 bool                            g_readonlyovlloaded = false;\r
41 bool                            g_deletedovlloaded = false;\r
42 bool                            g_lockedovlloaded = false;\r
43 bool                            g_addedovlloaded = false;\r
44 bool                            g_ignoredovlloaded = false;\r
45 bool                            g_unversionedovlloaded = false;\r
46 CComCriticalSection     g_csGlobalCOMGuard;\r
47 \r
48 LPCTSTR                         g_MenuIDString = _T("TortoiseSVN");\r
49 extern std::set<CShellExt *> g_exts;\r
50 \r
51 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")\r
52 \r
53 extern "C" int APIENTRY\r
54 DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)\r
55 {\r
56 #ifdef _DEBUG\r
57         // if no debugger is present, then don't load the dll.\r
58         // this prevents other apps from loading the dll and locking\r
59         // it.\r
60 \r
61         bool bInShellTest = false;\r
62         TCHAR buf[_MAX_PATH + 1];               // MAX_PATH ok, the test really is for debugging anyway.\r
63         DWORD pathLength = GetModuleFileName(NULL, buf, _MAX_PATH);\r
64         if(pathLength >= 14)\r
65         {\r
66                 if ((_tcsicmp(&buf[pathLength-14], _T("\\ShellTest.exe"))) == 0)\r
67                 {\r
68                         bInShellTest = true;\r
69                 }\r
70                 if ((_tcsicmp(&buf[pathLength-13], _T("\\verclsid.exe"))) == 0)\r
71                 {\r
72                         bInShellTest = true;\r
73                 }\r
74         }\r
75 \r
76         if (!::IsDebuggerPresent() && !bInShellTest)\r
77         {\r
78                 ATLTRACE("In debug load preventer\n");\r
79                 return FALSE;\r
80         }\r
81 #endif\r
82 \r
83         // NOTE: Do *NOT* call apr_initialize() or apr_terminate() here in DllMain(),\r
84         // because those functions call LoadLibrary() indirectly through malloc().\r
85         // And LoadLibrary() inside DllMain() is not allowed and can lead to unexpected\r
86         // behavior and even may create dependency loops in the dll load order.\r
87     if (dwReason == DLL_PROCESS_ATTACH)\r
88     {\r
89                 if (g_hmodThisDll == NULL)\r
90                 {\r
91                         g_csGlobalCOMGuard.Init();\r
92                 }\r
93 \r
94         // Extension DLL one-time initialization\r
95         g_hmodThisDll = hInstance;\r
96     }\r
97     else if (dwReason == DLL_PROCESS_DETACH)\r
98     {\r
99                 // sometimes an application doesn't release all COM objects\r
100                 // but still unloads the dll.\r
101                 // in that case, we do it ourselves\r
102                 if (g_cRefThisDll > 0)\r
103                 {\r
104                         std::set<CShellExt *>::iterator it = g_exts.begin();\r
105                         while (it != g_exts.end())\r
106                         {\r
107                                 delete *it;\r
108                                 it = g_exts.begin();\r
109                         }\r
110                         while (g_cAprInit--)\r
111                         {\r
112                                 g_GitAdminDir.Close();\r
113 //                              apr_terminate();\r
114                         }\r
115                 }\r
116                 g_csGlobalCOMGuard.Term();\r
117     }\r
118     return 1;   // ok\r
119 }\r
120 \r
121 STDAPI DllCanUnloadNow(void)\r
122 {\r
123         return (g_cRefThisDll == 0 ? S_OK : S_FALSE);\r
124 }\r
125 \r
126 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)\r
127 {\r
128     *ppvOut = NULL;\r
129         \r
130     FileState state = FileStateInvalid;\r
131     if (IsEqualIID(rclsid, CLSID_Tortoisegit_UPTODATE))\r
132         state = FileStateVersioned;\r
133     else if (IsEqualIID(rclsid, CLSID_Tortoisegit_MODIFIED))\r
134         state = FileStateModified;\r
135     else if (IsEqualIID(rclsid, CLSID_Tortoisegit_CONFLICTING))\r
136         state = FileStateConflict;\r
137     else if (IsEqualIID(rclsid, CLSID_Tortoisegit_UNCONTROLLED))\r
138         state = FileStateUncontrolled;\r
139         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_DROPHANDLER))\r
140                 state = FileStateDropHandler;\r
141         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_DELETED))\r
142                 state = FileStateDeleted;\r
143         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_READONLY))\r
144                 state = FileStateReadOnly;\r
145         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_LOCKED))\r
146                 state = FileStateLockedOverlay;\r
147         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_ADDED))\r
148                 state = FileStateAddedOverlay;\r
149         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_IGNORED))\r
150                 state = FileStateIgnoredOverlay;\r
151         else if (IsEqualIID(rclsid, CLSID_Tortoisegit_UNVERSIONED))\r
152                 state = FileStateUnversionedOverlay;\r
153         \r
154     if (state != FileStateInvalid)\r
155     {\r
156 //              apr_initialize();\r
157 //              git_dso_initialize2();\r
158                 g_GitAdminDir.Init();\r
159                 g_cAprInit++;\r
160                 \r
161                 CShellExtClassFactory *pcf = new CShellExtClassFactory(state);\r
162                 return pcf->QueryInterface(riid, ppvOut);\r
163     }\r
164         \r
165     return CLASS_E_CLASSNOTAVAILABLE;\r
166 \r
167 }\r
168 \r
169 \r