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;
268 if( bypassProxyStr != NULL )
270 wxStringTokenizer tokenizer( bypassProxyStr,
";" );
272 while( tokenizer.HasMoreTokens() )
274 wxString host = tokenizer.GetNextToken();
276 if( host == uri.GetServer() )
285 if( host ==
"<local>" )
287 if( !uri.GetServer().Contains(
"." ) )
297 if( !bypassed && proxyStr != NULL )
302 wxStringTokenizer tokenizer( proxyStr,
"; \t" );
304 while( tokenizer.HasMoreTokens() )
306 wxString entry = tokenizer.GetNextToken();
309 if( entry.Contains(
"=" ) )
311 wxString scheme = entry.BeforeFirst(
'=' ).Lower();
312 entry = entry.AfterFirst(
'=' );
315 if( scheme != uri.GetScheme().Lower() )
325 if( entry !=
"" && entry !=
":" && entry !=
"::" )
336 if( autoProxyInfo.lpszProxy )
338 GlobalFree( autoProxyInfo.lpszProxy );
339 autoProxyInfo.lpszProxy = NULL;
342 if( autoProxyInfo.lpszProxyBypass )
344 GlobalFree( autoProxyInfo.lpszProxyBypass );
345 autoProxyInfo.lpszProxyBypass = NULL;
348 if( ieProxyConfig.lpszAutoConfigUrl != NULL )
350 GlobalFree( ieProxyConfig.lpszAutoConfigUrl );
351 ieProxyConfig.lpszAutoConfigUrl = NULL;
354 if( ieProxyConfig.lpszProxy != NULL )
356 GlobalFree( ieProxyConfig.lpszProxy );
357 ieProxyConfig.lpszProxy = NULL;
360 if( ieProxyConfig.lpszProxyBypass != NULL )
362 GlobalFree( ieProxyConfig.lpszProxyBypass );
363 ieProxyConfig.lpszProxyBypass = NULL;
372 WINTRUST_FILE_INFO fileData;
373 memset( &fileData, 0,
sizeof( fileData ) );
374 fileData.cbStruct =
sizeof( WINTRUST_FILE_INFO );
375 fileData.pcwszFilePath = aPath.wc_str();
378 GUID policy = WINTRUST_ACTION_GENERIC_VERIFY_V2;
380 WINTRUST_DATA trustData;
381 memset( &trustData, 0,
sizeof( trustData ) );
383 trustData.cbStruct =
sizeof( trustData );
384 trustData.dwUIChoice = WTD_UI_NONE;
386 trustData.fdwRevocationChecks = WTD_REVOKE_NONE;
387 trustData.dwUnionChoice = WTD_CHOICE_FILE;
388 trustData.dwStateAction = WTD_STATEACTION_VERIFY;
389 trustData.pFile = &fileData;
392 bool verified =
false;
393 LONG status = WinVerifyTrust( NULL, &policy, &trustData );
395 verified = ( status == ERROR_SUCCESS );
398 trustData.dwStateAction = WTD_STATEACTION_CLOSE;
399 WinVerifyTrust( NULL, &policy, &trustData );
411 std::vector<wxString> modelIdComponents;
412 modelIdComponents.push_back( wxS(
"Kicad" ) );
413 modelIdComponents.push_back( wxS(
"Kicad" ) );
414 modelIdComponents.push_back( wxTheApp->GetAppName() );
415 modelIdComponents.push_back( KICAD_MAJOR_MINOR_VERSION );
418 for(
const auto& str : modelIdComponents )
421 modelId += wxS(
"." );
424 modelId.RemoveLast();
425 modelId.Replace( wxS(
" " ), wxS(
"_" ) );
434 const wxString& aRelaunchDisplayName )
437 HRESULT hr = ::SHGetPropertyStoreForWindow( aWindow->GetHWND(), IID_PPV_ARGS( &pps ) );
438 if( SUCCEEDED( hr ) )
445 if( SUCCEEDED( hr ) )
447 hr = pps->SetValue( PKEY_AppUserModel_ID, pv );
448 PropVariantClear( &pv );
452 if( !aRelaunchCommand.empty() )
454 hr = ::InitPropVariantFromString( aRelaunchCommand.wc_str(), &pv );
459 ::PropVariantInit( &pv );
462 if( SUCCEEDED( hr ) )
464 hr = pps->SetValue( PKEY_AppUserModel_RelaunchCommand, pv );
465 PropVariantClear( &pv );
468 if( !aRelaunchDisplayName.empty() )
470 hr = ::InitPropVariantFromString( aRelaunchDisplayName.wc_str(), &pv );
475 ::PropVariantInit( &pv );
478 if( SUCCEEDED( hr ) )
480 hr = pps->SetValue( PKEY_AppUserModel_RelaunchDisplayNameResource, pv );
481 PropVariantClear( &pv );
491 return ::GetCommandLine();
497 IShellItem* psi =
nullptr;
498 HRESULT hr = SHCreateItemFromParsingName( aPath.wc_str(), NULL, IID_PPV_ARGS( &psi ) );
500 if( SUCCEEDED( hr ) )
505 info.pszAppID = appID.wc_str();
506 ::SHAddToRecentDocs( SHARD_APPIDINFO, &
info );
511 ::SHAddToRecentDocs( SHARD_PATHW, aPath.wc_str() );
std::vector< FAB_LAYER_COLOR > dummy