23#include <wx/filename.h>
24#include <wx/stdpaths.h>
26#include <wx/tokenzr.h>
33#if defined( __MINGW32__ )
36 #include <shobjidl_core.h>
44#define INCLUDE_KICAD_VERSION
45#include <kicad_build_version.h>
50 ::SetCurrentProcessExplicitAppUserModelID( GetAppUserModelId().wc_str() );
57 wxString temp = aPath +
'\0';
59 SHFILEOPSTRUCT fileOp;
60 ::ZeroMemory( &fileOp,
sizeof( fileOp ) );
62 fileOp.hwnd =
nullptr;
63 fileOp.wFunc = FO_DELETE;
64 fileOp.pFrom = temp.c_str();
66 fileOp.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT;
68 int eVal = SHFileOperation( &fileOp );
72 aError = wxString::Format(
_(
"Error code: %d" ), eVal );
82 return ::PathIsNetworkPathW( aPath.wc_str() );
90 if( wxTheApp ==
nullptr )
93 return wxStandardPaths::Get().GetDocumentsDir();
96 return wxStandardPaths::Get().GetDocumentsDir();
104 if( wxTheApp ==
nullptr )
107 return wxStandardPaths::Get().GetUserConfigDir();
110 return wxStandardPaths::Get().GetUserConfigDir();
118 if( wxTheApp ==
nullptr )
121 return wxStandardPaths::Get().GetUserDataDir();
124 return wxStandardPaths::Get().GetUserDataDir();
132 if( wxTheApp ==
nullptr )
135 return wxStandardPaths::Get().GetUserLocalDataDir();
138 return wxStandardPaths::Get().GetUserLocalDataDir();
150 if( wxTheApp ==
nullptr )
153 wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
155 return wxStandardPaths::Get().GetUserLocalDataDir();
158 wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
160 return wxStandardPaths::Get().GetUserLocalDataDir();
168 bool autoProxyDetect =
false;
169 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = { 0 };
170 WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = { 0 };
171 WINHTTP_PROXY_INFO autoProxyInfo = { 0 };
172 HINTERNET proxyResolveSession = NULL;
173 bool success =
false;
177 LPWSTR proxyStr = NULL;
178 LPWSTR bypassProxyStr = NULL;
180 if( WinHttpGetIEProxyConfigForCurrentUser( &ieProxyConfig ) )
184 if( ieProxyConfig.fAutoDetect )
186 autoProxyDetect =
true;
189 if( ieProxyConfig.lpszAutoConfigUrl != NULL )
191 autoProxyDetect =
true;
192 autoProxyOptions.lpszAutoConfigUrl = ieProxyConfig.lpszAutoConfigUrl;
195 else if( GetLastError() == ERROR_FILE_NOT_FOUND )
198 autoProxyDetect =
true;
201 if( autoProxyDetect )
203 proxyResolveSession =
204 WinHttpOpen( NULL, WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, WINHTTP_NO_PROXY_NAME,
205 WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC );
207 if( proxyResolveSession )
210 if( autoProxyOptions.lpszAutoConfigUrl != NULL )
212 autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL;
216 autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
217 autoProxyOptions.dwAutoDetectFlags =
218 WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A;
223 autoProxyOptions.fAutoLogonIfChallenged = FALSE;
225 autoProxyDetect = WinHttpGetProxyForUrl( proxyResolveSession, aURL.c_str(),
226 &autoProxyOptions, &autoProxyInfo );
228 if( !autoProxyDetect && GetLastError() == ERROR_WINHTTP_LOGIN_FAILURE )
230 autoProxyOptions.fAutoLogonIfChallenged = TRUE;
233 autoProxyDetect = WinHttpGetProxyForUrl( proxyResolveSession, aURL.c_str(),
234 &autoProxyOptions, &autoProxyInfo );
237 if( autoProxyDetect )
239 if( autoProxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY )
241 proxyStr = autoProxyInfo.lpszProxy;
242 bypassProxyStr = autoProxyInfo.lpszProxyBypass;
246 WinHttpCloseHandle( proxyResolveSession );
250 if( !autoProxyDetect && ieProxyConfig.lpszProxy != NULL )
252 proxyStr = ieProxyConfig.lpszProxy;
253 bypassProxyStr = ieProxyConfig.lpszProxyBypass;
256 bool bypassed =
false;
257 if( bypassProxyStr != NULL )
259 wxStringTokenizer tokenizer( bypassProxyStr, wxT(
";" ) );
261 while( tokenizer.HasMoreTokens() )
263 wxString host = tokenizer.GetNextToken();
265 if( host == uri.GetServer() )
274 if( host ==
"<local>" )
276 if( !uri.GetServer().Contains(
"." ) )
286 if( !bypassed && proxyStr != NULL )
291 wxStringTokenizer tokenizer( proxyStr, wxT(
"; \t" ) );
293 while( tokenizer.HasMoreTokens() )
295 wxString entry = tokenizer.GetNextToken();
298 if( entry.Contains(
"=" ) )
300 wxString scheme = entry.BeforeFirst(
'=' ).Lower();
301 entry = entry.AfterFirst(
'=' );
304 if( scheme != uri.GetScheme().Lower() )
314 if( entry !=
"" && entry !=
":" && entry !=
"::" )
325 if( autoProxyInfo.lpszProxy )
327 GlobalFree( autoProxyInfo.lpszProxy );
328 autoProxyInfo.lpszProxy = NULL;
331 if( autoProxyInfo.lpszProxyBypass )
333 GlobalFree( autoProxyInfo.lpszProxyBypass );
334 autoProxyInfo.lpszProxyBypass = NULL;
337 if( ieProxyConfig.lpszAutoConfigUrl != NULL )
339 GlobalFree( ieProxyConfig.lpszAutoConfigUrl );
340 ieProxyConfig.lpszAutoConfigUrl = NULL;
343 if( ieProxyConfig.lpszProxy != NULL )
345 GlobalFree( ieProxyConfig.lpszProxy );
346 ieProxyConfig.lpszProxy = NULL;
349 if( ieProxyConfig.lpszProxyBypass != NULL )
351 GlobalFree( ieProxyConfig.lpszProxyBypass );
352 ieProxyConfig.lpszProxyBypass = NULL;
361 WINTRUST_FILE_INFO fileData;
362 memset( &fileData, 0,
sizeof( fileData ) );
363 fileData.cbStruct =
sizeof( WINTRUST_FILE_INFO );
364 fileData.pcwszFilePath = aPath.wc_str();
367 GUID policy = WINTRUST_ACTION_GENERIC_VERIFY_V2;
369 WINTRUST_DATA trustData;
370 memset( &trustData, 0,
sizeof( trustData ) );
372 trustData.cbStruct =
sizeof( trustData );
373 trustData.dwUIChoice = WTD_UI_NONE;
375 trustData.fdwRevocationChecks = WTD_REVOKE_NONE;
376 trustData.dwUnionChoice = WTD_CHOICE_FILE;
377 trustData.dwStateAction = WTD_STATEACTION_VERIFY;
378 trustData.pFile = &fileData;
381 bool verified =
false;
382 LONG status = WinVerifyTrust( NULL, &policy, &trustData );
384 verified = ( status == ERROR_SUCCESS );
387 trustData.dwStateAction = WTD_STATEACTION_CLOSE;
388 WinVerifyTrust( NULL, &policy, &trustData );
400 std::vector<wxString> modelIdComponents;
401 modelIdComponents.push_back( wxS(
"Kicad" ) );
402 modelIdComponents.push_back( wxS(
"Kicad" ) );
403 modelIdComponents.push_back( wxTheApp->GetAppName() );
404 modelIdComponents.push_back( KICAD_MAJOR_MINOR_VERSION );
407 for(
const auto& str : modelIdComponents )
410 modelId += wxS(
"." );
413 modelId.RemoveLast();
414 modelId.Replace( wxS(
" " ), wxS(
"_" ) );
std::vector< FAB_LAYER_COLOR > dummy