23#include <wx/filename.h>
24#include <wx/stdpaths.h>
26#include <wx/tokenzr.h>
35#include <propvarutil.h>
36#if defined( __MINGW32__ )
39 #include <shobjidl_core.h>
45#if defined( __MINGW32__ )
48 #include <shlobj_core.h>
54#define INCLUDE_KICAD_VERSION
55#include <kicad_build_version.h>
60 ::SetCurrentProcessExplicitAppUserModelID( GetAppUserModelId().wc_str() );
67 wxString temp = aPath +
'\0';
69 SHFILEOPSTRUCT fileOp;
70 ::ZeroMemory( &fileOp,
sizeof( fileOp ) );
72 fileOp.hwnd =
nullptr;
73 fileOp.wFunc = FO_DELETE;
74 fileOp.pFrom = temp.c_str();
76 fileOp.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT;
78 int eVal = SHFileOperation( &fileOp );
82 aError = wxString::Format(
_(
"Error code: %d" ), eVal );
92 return ::PathIsNetworkPathW( aPath.wc_str() );
100 if( wxTheApp ==
nullptr )
103 return wxStandardPaths::Get().GetDocumentsDir();
106 return wxStandardPaths::Get().GetDocumentsDir();
114 if( wxTheApp ==
nullptr )
117 return wxStandardPaths::Get().GetUserConfigDir();
120 return wxStandardPaths::Get().GetUserConfigDir();
128 if( wxTheApp ==
nullptr )
131 return wxStandardPaths::Get().GetUserDataDir();
134 return wxStandardPaths::Get().GetUserDataDir();
142 if( wxTheApp ==
nullptr )
145 return wxStandardPaths::Get().GetUserLocalDataDir();
148 return wxStandardPaths::Get().GetUserLocalDataDir();
160 if( wxTheApp ==
nullptr )
163 wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
165 return wxStandardPaths::Get().GetUserLocalDataDir();
168 wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
170 return wxStandardPaths::Get().GetUserLocalDataDir();
178 bool autoProxyDetect =
false;
179 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = { 0 };
180 WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = { 0 };
181 WINHTTP_PROXY_INFO autoProxyInfo = { 0 };
182 HINTERNET proxyResolveSession = NULL;
183 bool success =
false;
187 LPWSTR proxyStr = NULL;
188 LPWSTR bypassProxyStr = NULL;
190 if( WinHttpGetIEProxyConfigForCurrentUser( &ieProxyConfig ) )
194 if( ieProxyConfig.fAutoDetect )
196 autoProxyDetect =
true;
199 if( ieProxyConfig.lpszAutoConfigUrl != NULL )
201 autoProxyDetect =
true;
202 autoProxyOptions.lpszAutoConfigUrl = ieProxyConfig.lpszAutoConfigUrl;
205 else if( GetLastError() == ERROR_FILE_NOT_FOUND )
208 autoProxyDetect =
true;
211 if( autoProxyDetect )
213 proxyResolveSession =
214 WinHttpOpen( NULL, WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, WINHTTP_NO_PROXY_NAME,
215 WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC );
217 if( proxyResolveSession )
220 if( autoProxyOptions.lpszAutoConfigUrl != NULL )
222 autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL;
226 autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
227 autoProxyOptions.dwAutoDetectFlags =
228 WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A;
233 autoProxyOptions.fAutoLogonIfChallenged = FALSE;
235 autoProxyDetect = WinHttpGetProxyForUrl( proxyResolveSession, aURL.c_str(),
236 &autoProxyOptions, &autoProxyInfo );
238 if( !autoProxyDetect && GetLastError() == ERROR_WINHTTP_LOGIN_FAILURE )
240 autoProxyOptions.fAutoLogonIfChallenged = TRUE;
243 autoProxyDetect = WinHttpGetProxyForUrl( proxyResolveSession, aURL.c_str(),
244 &autoProxyOptions, &autoProxyInfo );
247 if( autoProxyDetect )
249 if( autoProxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY )
251 proxyStr = autoProxyInfo.lpszProxy;
252 bypassProxyStr = autoProxyInfo.lpszProxyBypass;
256 WinHttpCloseHandle( proxyResolveSession );
260 if( !autoProxyDetect && ieProxyConfig.lpszProxy != NULL )
262 proxyStr = ieProxyConfig.lpszProxy;
263 bypassProxyStr = ieProxyConfig.lpszProxyBypass;
266 bool bypassed =
false;
267 if( bypassProxyStr != NULL )
269 wxStringTokenizer tokenizer( bypassProxyStr, wxT(
";" ) );
271 while( tokenizer.HasMoreTokens() )
273 wxString host = tokenizer.GetNextToken();
275 if( host == uri.GetServer() )
284 if( host ==
"<local>" )
286 if( !uri.GetServer().Contains(
"." ) )
296 if( !bypassed && proxyStr != NULL )
301 wxStringTokenizer tokenizer( proxyStr, wxT(
"; \t" ) );
303 while( tokenizer.HasMoreTokens() )
305 wxString entry = tokenizer.GetNextToken();
308 if( entry.Contains(
"=" ) )
310 wxString scheme = entry.BeforeFirst(
'=' ).Lower();
311 entry = entry.AfterFirst(
'=' );
314 if( scheme != uri.GetScheme().Lower() )
324 if( entry !=
"" && entry !=
":" && entry !=
"::" )
335 if( autoProxyInfo.lpszProxy )
337 GlobalFree( autoProxyInfo.lpszProxy );
338 autoProxyInfo.lpszProxy = NULL;
341 if( autoProxyInfo.lpszProxyBypass )
343 GlobalFree( autoProxyInfo.lpszProxyBypass );
344 autoProxyInfo.lpszProxyBypass = NULL;
347 if( ieProxyConfig.lpszAutoConfigUrl != NULL )
349 GlobalFree( ieProxyConfig.lpszAutoConfigUrl );
350 ieProxyConfig.lpszAutoConfigUrl = NULL;
353 if( ieProxyConfig.lpszProxy != NULL )
355 GlobalFree( ieProxyConfig.lpszProxy );
356 ieProxyConfig.lpszProxy = NULL;
359 if( ieProxyConfig.lpszProxyBypass != NULL )
361 GlobalFree( ieProxyConfig.lpszProxyBypass );
362 ieProxyConfig.lpszProxyBypass = NULL;
371 WINTRUST_FILE_INFO fileData;
372 memset( &fileData, 0,
sizeof( fileData ) );
373 fileData.cbStruct =
sizeof( WINTRUST_FILE_INFO );
374 fileData.pcwszFilePath = aPath.wc_str();
377 GUID policy = WINTRUST_ACTION_GENERIC_VERIFY_V2;
379 WINTRUST_DATA trustData;
380 memset( &trustData, 0,
sizeof( trustData ) );
382 trustData.cbStruct =
sizeof( trustData );
383 trustData.dwUIChoice = WTD_UI_NONE;
385 trustData.fdwRevocationChecks = WTD_REVOKE_NONE;
386 trustData.dwUnionChoice = WTD_CHOICE_FILE;
387 trustData.dwStateAction = WTD_STATEACTION_VERIFY;
388 trustData.pFile = &fileData;
391 bool verified =
false;
392 LONG status = WinVerifyTrust( NULL, &policy, &trustData );
394 verified = ( status == ERROR_SUCCESS );
397 trustData.dwStateAction = WTD_STATEACTION_CLOSE;
398 WinVerifyTrust( NULL, &policy, &trustData );
410 std::vector<wxString> modelIdComponents;
411 modelIdComponents.push_back( wxS(
"Kicad" ) );
412 modelIdComponents.push_back( wxS(
"Kicad" ) );
413 modelIdComponents.push_back( wxTheApp->GetAppName() );
414 modelIdComponents.push_back( KICAD_MAJOR_MINOR_VERSION );
417 for(
const auto& str : modelIdComponents )
420 modelId += wxS(
"." );
423 modelId.RemoveLast();
424 modelId.Replace( wxS(
" " ), wxS(
"_" ) );
433 const wxString& aRelaunchDisplayName )
436 HRESULT hr = ::SHGetPropertyStoreForWindow( aWindow->GetHWND(), IID_PPV_ARGS( &pps ) );
437 if( SUCCEEDED( hr ) )
444 if( SUCCEEDED( hr ) )
446 hr = pps->SetValue( PKEY_AppUserModel_ID, pv );
447 PropVariantClear( &pv );
451 if( !aRelaunchCommand.empty() )
453 hr = ::InitPropVariantFromString( aRelaunchCommand.wc_str(), &pv );
458 ::PropVariantInit( &pv );
461 if( SUCCEEDED( hr ) )
463 hr = pps->SetValue( PKEY_AppUserModel_RelaunchCommand, pv );
464 PropVariantClear( &pv );
467 if( !aRelaunchDisplayName.empty() )
469 hr = ::InitPropVariantFromString( aRelaunchDisplayName.wc_str(), &pv );
474 ::PropVariantInit( &pv );
477 if( SUCCEEDED( hr ) )
479 hr = pps->SetValue( PKEY_AppUserModel_RelaunchDisplayNameResource, pv );
480 PropVariantClear( &pv );
490 return ::GetCommandLine();
496 IShellItem* psi =
nullptr;
497 HRESULT hr = SHCreateItemFromParsingName( aPath.wc_str(), NULL, IID_PPV_ARGS( &psi ) );
499 if( SUCCEEDED( hr ) )
504 info.pszAppID = appID.wc_str();
505 ::SHAddToRecentDocs( SHARD_APPIDINFO, &
info );
510 ::SHAddToRecentDocs( SHARD_PATHW, aPath.wc_str() );
std::vector< FAB_LAYER_COLOR > dummy