MCPcopy Create free account
hub / github.com/MediaArea/MediaInfo / ExtractUrlFromShortcut

Function ExtractUrlFromShortcut

Source/WindowsShellExtension/dllmain.cpp:191–228  ·  view source on GitHub ↗

Adapted from code generated with Google Gemini 2.0 Flash

Source from the content-addressed store, hash-verified

189
190 // Adapted from code generated with Google Gemini 2.0 Flash
191 _Check_return_ _Success_return_
192 bool ExtractUrlFromShortcut(_In_ const std::filesystem::path& filePath, _Out_ std::string& url) {
193 // Check if file exists and is readable
194 if (!std::filesystem::exists(filePath) || !std::filesystem::is_regular_file(filePath))
195 return false;
196
197 // Open the file in binary mode
198 std::ifstream file(filePath, std::ios::binary);
199
200 // Check if file opened successfully
201 if (!file.is_open())
202 return false;
203
204 // Read the entire file content
205 std::string content;
206 file.seekg(0, std::ios::end);
207 if (file.tellg() > 4096) { // Leave if file is too large
208 file.close();
209 return false;
210 }
211 content.resize(static_cast<size_t>(file.tellg()));
212 file.seekg(0, std::ios::beg);
213 file.read(content.data(), content.size());
214 file.close();
215
216 // Check if the content starts with the expected header for a .url file
217 if (content.size() < 20 || (content.substr(0, 20) != "[InternetShortcut]\r\n"))
218 return false;
219
220 // Use regular expression to extract the URL
221 std::regex urlRegex(R"(URL=(.*?)\r?\n)");
222 std::smatch match;
223 if (std::regex_search(content, match, urlRegex)) {
224 url = match[1].str();
225 return true;
226 }
227 return false;
228 }
229
230 // Adapted from code generated with Google Gemini 2.0 Flash
231 std::string ExtractFileExtensionFromUrl(_In_ const std::string& url) {

Callers 1

dllmain.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected