• R/O
  • SSH
  • HTTPS

netoffice: Commit


Commit MetaInfo

Revision195 (tree)
Time2018-07-23 03:15:21
Authorsebastiandotnet

Log Message

- add com shim core logging

Change Summary

Incremental Difference

--- NetOfficeShimLoader/ShimLoader/CustomRegisterValue.cpp (revision 194)
+++ NetOfficeShimLoader/ShimLoader/CustomRegisterValue.cpp (revision 195)
@@ -63,7 +63,7 @@
6363 if (_parseValue && 0 == wcscmp(_value, L"$LocalTime"))
6464 {
6565 if(NULL == localtime_s(&buf, &t))
66- wcsftime(buffer, maxLen, L"%d-%m-%Y %I:%M:%S", &buf);
66+ wcsftime(buffer, maxLen, L"%d-%m-%Y %I:%M:%S %p", &buf);
6767 else
6868 StringCchCopy(buffer, maxLen, _value);
6969 }
@@ -77,7 +77,7 @@
7777 else if (_parseValue && 0 == wcscmp(_value, L"$LocalTimeDEFormat"))
7878 {
7979 if (NULL == localtime_s(&buf, &t))
80- wcsftime(buffer, maxLen, L"%d.%m.%Y %I:%M:%S", &buf);
80+ wcsftime(buffer, maxLen, L"%d.%m.%Y %H:%M:%S", &buf);
8181 else
8282 StringCchCopy(buffer, maxLen, _value);
8383 }
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
--- NetOfficeShimLoader/ShimLoader/DllRegister32On64.cpp (revision 194)
+++ NetOfficeShimLoader/ShimLoader/DllRegister32On64.cpp (revision 195)
@@ -24,7 +24,7 @@
2424
2525 HRESULT DllRegister(HINSTANCE module, LPCWSTR officeApplications[], DWORD addinLoadBehavior, DWORD addinCommandLineSafe, WCHAR* progId, WCHAR* classId, WCHAR* friendlyName, WCHAR* description, WCHAR* version, RegisterMode mode, BOOL addinRegistration)
2626 {
27- NetOffice_ShimLoader_Analytics::WriteLog(L"Register32On64::DllRegister::Enter");
27+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::DllRegister::Enter");
2828
2929 HRESULT hr = S_OK;
3030
@@ -34,7 +34,7 @@
3434 !version || !version[0])
3535 {
3636 hr = E_INVALIDARG;
37- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllRegister::FailExit", hr);
37+ NetOffice_ShimLoader_Analytics::WriteRegisterError(L"Register32On64::DllRegister::FailExit", hr);
3838 return hr;
3939 }
4040
@@ -47,7 +47,7 @@
4747 hr = RegisterCOMAddin(officeApplications[i], progId, friendlyName, description, addinLoadBehavior, addinCommandLineSafe, System == mode);
4848 if (!SUCCEEDED(hr))
4949 {
50- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllRegister::Error#RegisterCOMAddin");
50+ NetOffice_ShimLoader_Analytics::WriteRegisterError(L"Register32On64::DllRegister::Error#RegisterCOMAddin", hr);
5151 break;
5252 }
5353 }
@@ -54,13 +54,13 @@
5454 }
5555 else
5656 {
57- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllRegister::Error#RegisterCOMComponent");
57+ NetOffice_ShimLoader_Analytics::WriteRegisterError(L"Register32On64::DllRegister::Error#RegisterCOMComponent", hr);
5858 }
5959
6060 if (SUCCEEDED(hr))
61- NetOffice_ShimLoader_Analytics::WriteLog(L"Register32On64::DllRegister::Exit");
61+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::DllRegister::Exit");
6262 else
63- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllRegister::FailExit");
63+ NetOffice_ShimLoader_Analytics::WriteRegisterError(L"Register32On64::DllRegister::FailExit", hr);
6464
6565 return hr;
6666 }
@@ -67,7 +67,7 @@
6767
6868 HRESULT DllUnregister(LPCWSTR officeApplications[], WCHAR* progId, WCHAR* classId, WCHAR* version, RegisterMode mode, BOOL addinRegistration)
6969 {
70- NetOffice_ShimLoader_Analytics::WriteLog(L"Register32On64::DllUnregister::Enter");
70+ NetOffice_ShimLoader_Analytics::WriteUnRegisterLog(L"Register32On64::DllUnregister::Enter");
7171
7272 HRESULT hr = S_OK;
7373 HRESULT addin = S_OK;
@@ -75,7 +75,7 @@
7575 if (NULL == officeApplications || !progId || !progId[0] || !classId || !classId[0] || !version || !version[0])
7676 {
7777 hr = E_INVALIDARG;
78- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllUnregister::FailExit", hr);
78+ NetOffice_ShimLoader_Analytics::WriteUnRegisterError(L"Register32On64::DllUnregister::FailExit", hr);
7979 return hr;
8080 }
8181
@@ -86,7 +86,7 @@
8686 {
8787 if (!SUCCEEDED(UnRegisterCOMAddin(officeApplications[i], progId, 0 == mode)))
8888 {
89- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllUnregister::Error#UnRegisterCOMAddin");
89+ NetOffice_ShimLoader_Analytics::WriteUnRegisterError(L"Register32On64::DllUnregister::Error#UnRegisterCOMAddin", hr);
9090 addin = E_FAIL;
9191 }
9292 }
@@ -94,12 +94,12 @@
9494
9595 hr = UnregisterCOMComponent(progId, classId, version, mode);
9696 if(FAILED(hr))
97- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllUnregister::Error#UnregisterCOMComponent");
97+ NetOffice_ShimLoader_Analytics::WriteUnRegisterError(L"Register32On64::DllUnregister::Error#UnregisterCOMComponent", hr);
9898
9999 if(SUCCEEDED(addin != S_OK ? addin : hr))
100- NetOffice_ShimLoader_Analytics::WriteLog(L"Register32On64::DllUnregister::Exit");
100+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::DllUnregister::Exit");
101101 else
102- NetOffice_ShimLoader_Analytics::WriteError(L"Register32On64::DllUnregister::FailExit");
102+ NetOffice_ShimLoader_Analytics::WriteUnRegisterError(L"Register32On64::DllUnregister::FailExit", (addin != S_OK ? addin : hr));
103103
104104 return addin != S_OK ? addin : hr;
105105 }
@@ -106,6 +106,8 @@
106106
107107 HRESULT RegisterCOMComponent(HINSTANCE module, LPCWSTR progId, LPCWSTR classId, LPCWSTR version, LPCWSTR description, RegisterMode mode)
108108 {
109+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::RegisterCOMComponent::Enter");
110+
109111 HRESULT hr = S_OK;
110112 BOOL setKeyResult = FALSE;
111113
@@ -170,15 +172,19 @@
170172 goto Error;
171173 }
172174
175+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::RegisterCOMComponent::Exit");
173176 return hr;
174177
175178 Error:
176179
180+ NetOffice_ShimLoader_Analytics::WriteRegisterError(L"Register32On64::RegisterCOMComponent::FailExit", hr);
177181 return hr;
178182 }
179183
180184 HRESULT UnregisterCOMComponent(LPCWSTR progId, LPCWSTR classId, LPCWSTR version, RegisterMode mode)
181185 {
186+ NetOffice_ShimLoader_Analytics::WriteUnRegisterLog(L"Register32On64::UnregisterCOMComponent::Enter");
187+
182188 HRESULT hr = S_OK;
183189 LONG deleteKeyResult = 0;
184190
@@ -203,15 +209,19 @@
203209 deleteKeyResult = RecursiveDeleteKey(hKeyRoot, classIdKey);
204210 IfNotZeroGo(deleteKeyResult);
205211
212+ NetOffice_ShimLoader_Analytics::WriteUnRegisterLog(L"Register32On64::UnregisterCOMComponent::Exit");
206213 return hr;
207214
208215 Error:
209216
217+ NetOffice_ShimLoader_Analytics::WriteUnRegisterError(L"Register32On64::UnregisterCOMComponent::FailExit", hr);
210218 return hr;
211219 }
212220
213221 HRESULT RegisterCOMAddin(LPCWSTR pszOfficeApp, LPCWSTR pszProgID, LPCWSTR pszFriendlyName, LPCWSTR pszDescription, DWORD dwStartupContext, DWORD dwCommandLineSafe, bool registerPerMachine)
214222 {
223+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::RegisterCOMAddin::Enter");
224+
215225 HRESULT hr = S_OK;
216226 WCHAR szKeyBuf[1024];
217227 DWORD dwTemp = 0;
@@ -258,6 +268,7 @@
258268 }
259269
260270 RegCloseKey(hKey);
271+ NetOffice_ShimLoader_Analytics::WriteRegisterLog(L"Register32On64::RegisterCOMAddin::Exit");
261272 return hr;
262273
263274 Error:
@@ -267,11 +278,14 @@
267278 RegCloseKey(hKey);
268279 RegDeleteKey(hKey, szKeyBuf);
269280 }
281+ NetOffice_ShimLoader_Analytics::WriteRegisterError(L"Register32On64::RegisterCOMAddin::FailExit", hr);
270282 return hr;
271283 }
272284
273285 HRESULT UnRegisterCOMAddin(LPCWSTR pszOfficeApp, LPCWSTR pszProgID, bool registerPerMachine)
274286 {
287+ NetOffice_ShimLoader_Analytics::WriteUnRegisterLog(L"Register32On64::UnRegisterCOMAddin::Enter");
288+
275289 HRESULT hr = S_OK;
276290 HRESULT result = S_OK;
277291
@@ -283,6 +297,10 @@
283297 StringCchCat(szKeyBuf, 1024, pszProgID);
284298
285299 hr = RecursiveDeleteKey(root, szKeyBuf);
300+ if(SUCCEEDED(hr))
301+ NetOffice_ShimLoader_Analytics::WriteUnRegisterLog(L"Register32On64::UnRegisterCOMAddin::Exit");
302+ else
303+ NetOffice_ShimLoader_Analytics::WriteUnRegisterError(L"Register32On64::UnRegisterCOMAddin::FailExit", hr);
286304 return result;
287305 }
288306
--- NetOfficeShimLoader/ShimLoader/Vars.h (revision 194)
+++ NetOfficeShimLoader/ShimLoader/Vars.h (revision 195)
@@ -3,6 +3,12 @@
33
44 using namespace NetOffice_ShimLoader_Register;
55
6+extern WCHAR* LogFile_Path;
7+extern WCHAR* LogFile_Register_Path;
8+extern WCHAR* LogFile_UnRegister_Path;
9+
10+extern BOOL Internal_LogError_MessageBoxes_Enabled;
11+
612 //
713 // Managed Addin Aggregator
814 //
--- NetOfficeShimLoader/ShimLoader/Vars.hpp (revision 194)
+++ NetOfficeShimLoader/ShimLoader/Vars.hpp (revision 195)
@@ -3,6 +3,12 @@
33
44 using namespace NetOffice_ShimLoader_Register;
55
6+WCHAR* LogFile_Path;
7+WCHAR* LogFile_Register_Path;
8+WCHAR* LogFile_UnRegister_Path;
9+
10+BOOL Internal_LogError_MessageBoxes_Enabled;
11+
612 //
713 // Managed Addin Aggregator
814 //
--- NetOfficeShimLoader/ShimLoader/WriteLog.hpp (revision 194)
+++ NetOfficeShimLoader/ShimLoader/WriteLog.hpp (revision 195)
@@ -4,11 +4,36 @@
44 #include <fstream>
55 #include <iosfwd>
66 #include <iostream>
7+#include <ctime>
78
9+extern WCHAR* LogFile_Path;
10+extern WCHAR* LogFile_Register_Path;
11+extern WCHAR* LogFile_UnRegister_Path;
12+extern BOOL Internal_LogError_MessageBoxes_Enabled;
13+
814 namespace NetOffice_ShimLoader_Analytics
915 {
10- static WCHAR _logFilePath[MAX_PATH + 1];
16+ static const int _bufferSize = 1024;
1117
18+ static HRESULT GetModuleFileName(WCHAR* szPath, DWORD nPathBufferSize)
19+ {
20+ HMODULE hInstance = _AtlBaseModule.GetModuleInstance();
21+ if (0 == hInstance)
22+ {
23+ return E_FAIL;
24+ }
25+
26+ DWORD dwFLen = ::GetModuleFileName(hInstance, szPath, nPathBufferSize);
27+ if (0 != dwFLen)
28+ {
29+ return S_OK;
30+ }
31+ else
32+ {
33+ return E_FAIL;
34+ }
35+ }
36+
1237 static HRESULT GetDllDirectory(WCHAR* szPath, DWORD nPathBufferSize)
1338 {
1439 HMODULE hInstance = _AtlBaseModule.GetModuleInstance();
@@ -35,72 +60,246 @@
3560 return S_OK;
3661 }
3762
38- static void InitializeLog()
63+ static HRESULT InitializeLog()
3964 {
40- if (SUCCEEDED(GetDllDirectory(_logFilePath, MAX_PATH))
41- && SUCCEEDED(PathAppend(_logFilePath, L"ShimLoader.txt")))
65+ HRESULT hr = S_OK;
66+
67+ WCHAR moduleFolderPath[MAX_PATH];
68+ WCHAR moduleFileName[MAX_PATH];
69+ WCHAR logFileName[MAX_PATH];
70+ WCHAR logRegisterFileName[MAX_PATH];
71+ WCHAR logUnregisterFileName[MAX_PATH];
72+
73+ hr = GetDllDirectory(moduleFolderPath, MAX_PATH);
74+ if (FAILED(hr))
75+ goto Error;
76+ hr = GetModuleFileName(moduleFileName, MAX_PATH);
77+ if (FAILED(hr))
78+ goto Error;
79+ PathStripPath(moduleFileName);
80+
81+ StringCchCopy(logFileName, MAX_PATH, moduleFileName);
82+ StringCchCat(logFileName, MAX_PATH, L".log");
83+
84+ StringCchCopy(logRegisterFileName, MAX_PATH, moduleFileName);
85+ StringCchCat(logRegisterFileName, MAX_PATH, L".Register");
86+ StringCchCat(logRegisterFileName, MAX_PATH, L".log");
87+
88+ StringCchCopy(logUnregisterFileName, MAX_PATH, moduleFileName);
89+ StringCchCat(logUnregisterFileName, MAX_PATH, L".Unregister");
90+ StringCchCat(logUnregisterFileName, MAX_PATH, L".log");
91+
92+ PathAppend(LogFile_Path, moduleFolderPath);
93+ if (LogFile_Path && SUCCEEDED(PathAppend(LogFile_Path, logFileName)))
4294 {
43- if (PathFileExists(_logFilePath))
95+ if (PathFileExists(LogFile_Path))
4496 {
45- DeleteFile(_logFilePath);
97+ DeleteFile(LogFile_Path);
4698 }
4799 }
100+
101+ PathAppend(LogFile_Register_Path, moduleFolderPath);
102+ if (LogFile_Register_Path && SUCCEEDED(PathAppend(LogFile_Register_Path, logRegisterFileName)))
103+ {
104+ if (PathFileExists(LogFile_Register_Path))
105+ {
106+ DeleteFile(LogFile_Register_Path);
107+ }
108+ }
109+
110+ PathAppend(LogFile_UnRegister_Path, moduleFolderPath);
111+ if (LogFile_UnRegister_Path && SUCCEEDED(PathAppend(LogFile_UnRegister_Path, logUnregisterFileName)))
112+ {
113+ if (PathFileExists(LogFile_UnRegister_Path))
114+ {
115+ DeleteFile(LogFile_UnRegister_Path);
116+ }
117+ }
118+
119+ return hr;
120+
121+ Error:
122+
123+ return hr;
48124 }
49125
50- static void dump(LPCWSTR text)
126+ static void _Write(LPCWSTR text)
51127 {
52- std::wofstream myfile("C:\\myfile.txt", std::ios::app);
53- if (myfile.is_open())
128+ std::wofstream myfile(LogFile_Path, std::ios::app);
129+ if (LogFile_Path && myfile.is_open())
54130 {
55131 myfile << text << std::endl;
56132 myfile.close();
57133 }
134+ else
135+ {
136+ #ifdef DEBUG
137+ MessageBox(GetDesktopWindow(), LogFile_Path, L"WriteLog::_Write::OpenFileError", 0);
138+ #endif
139+ }
58140 }
59141
142+ static void _WriteRegister(LPCWSTR text)
143+ {
144+ std::wofstream myfile(LogFile_Register_Path, std::ios::app);
145+ if (LogFile_Register_Path && myfile.is_open())
146+ {
147+ myfile << text << std::endl;
148+ myfile.close();
149+ }
150+ else
151+ {
152+ #ifdef DEBUG
153+ MessageBox(GetDesktopWindow(), LogFile_Register_Path, L"WriteLog::_WriteRegister::OpenFileError", 0);
154+ #endif
155+ }
156+ }
157+
158+ static void _WriteUnRegister(LPCWSTR text)
159+ {
160+ MessageBox(NULL, LogFile_UnRegister_Path, text, 0);
161+ std::wofstream myfile(LogFile_UnRegister_Path, std::ios::app);
162+ if (LogFile_UnRegister_Path && myfile.is_open())
163+ {
164+ myfile << text << std::endl;
165+ myfile.close();
166+ }
167+ else
168+ {
169+ #ifdef DEBUG
170+ MessageBox(GetDesktopWindow(), LogFile_UnRegister_Path, L"WriteLog::_WriteUnRegister::OpenFileError", 0);
171+ #endif
172+ }
173+ }
174+
60175 static void WriteError(LPCWSTR text, ULONG value)
61176 {
62- MessageBox(GetDesktopWindow(), text, L"WriteError", 0);
177+ WCHAR buffer[_bufferSize];
178+ swprintf_s(buffer, _bufferSize, L"%s(%d)", text, value);
179+ _Write(text);
180+
181+ #ifdef DEBUG
182+
183+ if(Internal_LogError_MessageBoxes_Enabled)
184+ MessageBox(GetDesktopWindow(), buffer, L"WriteError", 0);
185+
186+ #endif
63187 }
64188
65- static void WriteError(LPCWSTR text, HRESULT hr)
189+ static void WriteRegisterError(LPCWSTR text, HRESULT value)
66190 {
67- MessageBox(GetDesktopWindow(), text, L"WriteError", 0);
191+ WCHAR buffer[_bufferSize];
192+ swprintf_s(buffer, _bufferSize, L"%s(HR:%d)", text, value);
193+ _WriteRegister(text);
194+
195+ #ifdef DEBUG
196+
197+ if (Internal_LogError_MessageBoxes_Enabled)
198+ MessageBox(GetDesktopWindow(), buffer, L"WriteError", 0);
199+
200+ #endif
68201 }
69202
203+ static void WriteUnRegisterError(LPCWSTR text, HRESULT value)
204+ {
205+ WCHAR buffer[_bufferSize];
206+ swprintf_s(buffer, _bufferSize, L"%s(HR:%d)", text, value);
207+ _WriteUnRegister(text);
208+
209+ #ifdef DEBUG
210+
211+ if (Internal_LogError_MessageBoxes_Enabled)
212+ MessageBox(GetDesktopWindow(), buffer, L"WriteError", 0);
213+
214+ #endif
215+ }
216+
217+ static void WriteError(LPCWSTR text, HRESULT value)
218+ {
219+ WCHAR buffer[_bufferSize];
220+ swprintf_s(buffer, _bufferSize, L"%s(HR:%d)", text, value);
221+ _Write(text);
222+
223+ #ifdef DEBUG
224+
225+ if (Internal_LogError_MessageBoxes_Enabled)
226+ MessageBox(GetDesktopWindow(), buffer, L"WriteError", 0);
227+
228+ #endif
229+ }
230+
70231 static void WriteError(LPCWSTR text)
71232 {
72- MessageBox(GetDesktopWindow(), text, L"WriteError", 0);
233+ _Write(text);
234+
235+ #ifdef DEBUG
236+
237+ if (Internal_LogError_MessageBoxes_Enabled)
238+ MessageBox(GetDesktopWindow(), text, L"WriteError", 0);
239+
240+ #endif
73241 }
74242
75243 static void WriteError(LPCWSTR text, LPCWSTR text2)
76244 {
77- //MessageBox(GetDesktopWindow(), text, L"WriteLog", 0);
245+ WCHAR buffer[_bufferSize];
246+ swprintf_s(buffer, _bufferSize, L"%s(%s)", text, text2);
247+ _Write(text);
248+
249+ #ifdef DEBUG
250+
251+ if (Internal_LogError_MessageBoxes_Enabled)
252+ MessageBox(GetDesktopWindow(), buffer, L"WriteError", 0);
253+
254+ #endif
78255 }
79- static void WriteLog(LPCWSTR text, HRESULT hr)
256+
257+ static void WriteLog(LPCWSTR text, HRESULT value)
80258 {
81- //MessageBox(GetDesktopWindow(), text, L"WriteLog", 0);
259+ WCHAR buffer[_bufferSize];
260+ swprintf_s(buffer, _bufferSize, L"%s(HR:%d)", text, value);
261+ _Write(text);
82262 }
83- static void WriteLog(LPCWSTR text)
263+
264+ static void WriteRegisterLog(LPCWSTR text)
84265 {
85- //MessageBox(GetDesktopWindow(), text, L"WriteLog", 0);
266+ _WriteRegister(text);
86267 }
87- static void WriteLog(LPCWSTR text, LPCWSTR text2)
268+
269+ static void WriteUnRegisterLog(LPCWSTR text)
88270 {
89- //MessageBox(GetDesktopWindow(), text, L"WriteLog", 0);
271+ _WriteUnRegister(text);
90272 }
91273
92- //static void WriteLog(const char* szString)
93- //{
94- // //MessageBox(GetDesktopWindow(), szString, L"WriteLog", 0);
274+ static void WriteLog(LPCWSTR text)
275+ {
276+ _Write(text);
277+ }
95278
96- // //ShimDebugMessageBox(L"", L"");
279+ static void WriteLogTimeStamp(LPCWSTR text)
280+ {
281+ time_t t = time(NULL);
282+ struct tm buf;
283+ WCHAR timeBuffer[256];
97284
98- // /*FILE* file = nullptr;
99- // auto result = _wfopen_s(&file, _logFilePath, L"a");
100- // if (NULL != result)
101- // {
102- // fprintf(file, "%s\n", szString);
103- // fclose(file);
104- // }*/
105- //}
285+ if (NULL == localtime_s(&buf, &t))
286+ {
287+ wcsftime(timeBuffer, 256, L"(%d-%m-%Y %I:%M:%S %p)", &buf);
288+ WCHAR buffer[_bufferSize];
289+ StringCchCopy(buffer, _bufferSize, text);
290+ StringCchCat(buffer, _bufferSize, timeBuffer);
291+ _Write(buffer);
292+ }
293+ else
294+ {
295+ _Write(text);
296+ }
297+ }
298+
299+ static void WriteLog(LPCWSTR text, LPCWSTR text2)
300+ {
301+ WCHAR buffer[_bufferSize];
302+ swprintf_s(buffer, _bufferSize, L"%s(%s)", text, text2);
303+ _Write(text);
304+ }
106305 }
--- NetOfficeShimLoader/ShimLoader/WriteRegisterLog.hpp (nonexistent)
+++ NetOfficeShimLoader/ShimLoader/WriteRegisterLog.hpp (revision 195)
@@ -0,0 +1 @@
1+#pragma once
--- NetOfficeShimLoader/ShimLoader/WriteUnRegisterLog.hpp (nonexistent)
+++ NetOfficeShimLoader/ShimLoader/WriteUnRegisterLog.hpp (revision 195)
@@ -0,0 +1 @@
1+#pragma once
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Show on old repository browser