|
6 | 6 | #include <string> // Required for std::wstring
|
7 | 7 | #include <cstdlib> // Required for _wpgmptr
|
8 | 8 | #include <cstring> // For memcmp
|
9 |
| -#include "app/src/include/firebase/log.h" //NOLINT |
| 9 | +#include "app/src/log.h" //NOLINT |
10 | 10 |
|
11 | 11 | namespace firebase {
|
12 | 12 | namespace analytics {
|
@@ -145,48 +145,18 @@ HMODULE VerifyAndLoadAnalyticsLibrary(
|
145 | 145 | return nullptr;
|
146 | 146 | }
|
147 | 147 |
|
148 |
| - // Get full path to the executable. |
149 |
| - std::wstring executable_path_str; |
150 |
| - wchar_t* wpgmptr_val = nullptr; |
151 |
| - |
152 |
| - // Prefer _get_wpgmptr() |
153 |
| - errno_t err_w = _get_wpgmptr(&wpgmptr_val); |
154 |
| - if (err_w == 0 && wpgmptr_val != nullptr && wpgmptr_val[0] != L'\0') { |
155 |
| - executable_path_str = wpgmptr_val; |
156 |
| - } else { |
157 |
| - // Fallback to _get_pgmptr() and convert to wide string |
158 |
| - char* pgmptr_val = nullptr; |
159 |
| - errno_t err_c = _get_pgmptr(&pgmptr_val); |
160 |
| - if (err_c == 0 && pgmptr_val != nullptr && pgmptr_val[0] != '\0') { |
161 |
| - // Convert narrow string to wide string using CP_ACP (system default ANSI code page) |
162 |
| - int wide_char_count = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, pgmptr_val, -1, NULL, 0); |
163 |
| - if (wide_char_count == 0) { // Failure if count is 0 |
164 |
| - DWORD conversion_error = GetLastError(); |
165 |
| - LogError("VerifyAndLoadAnalyticsLibrary: MultiByteToWideChar failed to calculate size for _get_pgmptr path. Error: %u", conversion_error); |
166 |
| - return nullptr; |
167 |
| - } |
168 |
| - |
169 |
| - std::vector<wchar_t> wide_path_buffer(wide_char_count); |
170 |
| - if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, pgmptr_val, -1, wide_path_buffer.data(), wide_char_count) == 0) { |
171 |
| - DWORD conversion_error = GetLastError(); |
172 |
| - LogError("VerifyAndLoadAnalyticsLibrary: MultiByteToWideChar failed to convert _get_pgmptr path. Error: %u", conversion_error); |
173 |
| - return nullptr; |
174 |
| - } |
175 |
| - executable_path_str = wide_path_buffer.data(); |
176 |
| - } else { |
177 |
| - // Both _get_wpgmptr and _get_pgmptr failed or returned empty/null |
178 |
| - LogError("VerifyAndLoadAnalyticsLibrary: Failed to retrieve executable path using both _get_wpgmptr (err: %d) and _get_pgmptr (err: %d).", err_w, err_c); |
179 |
| - return nullptr; |
180 |
| - } |
181 |
| - } |
| 148 | + std::wstring executable_path_str = GetExecutablePath(); |
182 | 149 |
|
183 | 150 | if (executable_path_str.empty()) {
|
184 |
| - LogError("VerifyAndLoadAnalyticsLibrary: Executable path resolved to an empty string."); |
| 151 | + // GetExecutablePath() is expected to log specific errors. |
| 152 | + // This log indicates the failure to proceed within this function. |
| 153 | + LogError("VerifyAndLoadAnalyticsLibrary: Failed to determine executable path via GetExecutablePath(), cannot proceed."); |
185 | 154 | return nullptr;
|
186 | 155 | }
|
187 | 156 |
|
188 | 157 | size_t last_slash_pos = executable_path_str.find_last_of(L"\\");
|
189 | 158 | if (last_slash_pos == std::wstring::npos) {
|
| 159 | + // Log message updated to avoid using %ls for executable_path_str |
190 | 160 | LogError("VerifyAndLoadAnalyticsLibrary: Could not determine executable directory from retrieved path (no backslash found).");
|
191 | 161 | return nullptr;
|
192 | 162 | }
|
|
0 commit comments