diff --git a/libs/kiplatform/msw/environment.cpp b/libs/kiplatform/msw/environment.cpp index 06af716701..3d36f9b65b 100644 --- a/libs/kiplatform/msw/environment.cpp +++ b/libs/kiplatform/msw/environment.cpp @@ -28,6 +28,8 @@ #include #include +#include + void KIPLATFORM::ENV::Init() { @@ -69,12 +71,28 @@ bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath ) wxString KIPLATFORM::ENV::GetDocumentsPath() { + // If called by a python script in stand-alone (outside kicad), wxStandardPaths::Get() + // complains about not existing app. so use a dummy app + if( wxTheApp == nullptr ) + { + wxApp dummy; + return wxStandardPaths::Get().GetDocumentsDir(); + } + return wxStandardPaths::Get().GetDocumentsDir(); } wxString KIPLATFORM::ENV::GetUserConfigPath() { + // If called by a python script in stand-alone (outside kicad), wxStandardPaths::Get() + // complains about not existing app. so use a dummy app + if( wxTheApp == nullptr ) + { + wxApp dummy; + return wxStandardPaths::Get().GetUserConfigDir(); + } + return wxStandardPaths::Get().GetUserConfigDir(); } @@ -84,6 +102,17 @@ wxString KIPLATFORM::ENV::GetUserCachePath() // Unfortunately AppData/Local is the closest analog to "Cache" directories of other platforms // Make sure we dont include the "appinfo" (appended app name) + + // If called by a python script in stand-alone (outside kicad), wxStandardPaths::Get() + // complains about not existing app. so use a dummy app + if( wxTheApp == nullptr ) + { + wxApp dummy; + wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None ); + + return wxStandardPaths::Get().GetUserLocalDataDir(); + } + wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None ); return wxStandardPaths::Get().GetUserLocalDataDir();