You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <kiplatform/environment.h>
  21. #import <Cocoa/Cocoa.h>
  22. #include <wx/osx/core/cfstring.h>
  23. #include <wx/filefn.h>
  24. #include <wx/stdpaths.h>
  25. void KIPLATFORM::ENV::Init()
  26. {
  27. // Disable the automatic window tabbing OSX does
  28. [NSWindow setAllowsAutomaticWindowTabbing:NO];
  29. // No tasks for this platform
  30. }
  31. bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
  32. {
  33. bool isDirectory = wxDirExists( aPath );
  34. NSURL* url = [NSURL fileURLWithPath:wxCFStringRef( aPath ).AsNSString() isDirectory:isDirectory];
  35. NSError* err = nullptr;
  36. BOOL result = [[NSFileManager defaultManager] trashItemAtURL:url resultingItemURL:nil error:&err];
  37. // Extract the error string if the operation failed
  38. if( result == NO )
  39. {
  40. NSString* errmsg;
  41. if( err.localizedRecoverySuggestion == nil )
  42. {
  43. errmsg = err.localizedFailureReason;
  44. }
  45. else
  46. {
  47. errmsg = [err.localizedFailureReason stringByAppendingFormat:@"\n\n%@",
  48. err.localizedRecoverySuggestion];
  49. }
  50. aError = wxCFStringRef::AsString( (CFStringRef) errmsg );
  51. return false;
  52. }
  53. return true;
  54. }
  55. bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
  56. {
  57. // placeholder, we "nerf" behavior if its a network path so return false by default
  58. return false;
  59. }
  60. wxString KIPLATFORM::ENV::GetDocumentsPath()
  61. {
  62. return wxStandardPaths::Get().GetDocumentsDir();
  63. }
  64. wxString KIPLATFORM::ENV::GetUserConfigPath()
  65. {
  66. return wxStandardPaths::Get().GetUserConfigDir();
  67. }
  68. wxString KIPLATFORM::ENV::GetUserDataPath()
  69. {
  70. return wxStandardPaths::Get().GetUserDataDir();
  71. }
  72. wxString KIPLATFORM::ENV::GetUserLocalDataPath()
  73. {
  74. return wxStandardPaths::Get().GetUserLocalDataDir();
  75. }
  76. wxString KIPLATFORM::ENV::GetUserCachePath()
  77. {
  78. NSURL* url = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory
  79. inDomain:NSUserDomainMask
  80. appropriateForURL:nil
  81. create:NO error:nil];
  82. return wxCFStringRef::AsString( ( CFStringRef) url.path );
  83. }
  84. bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& aCfg )
  85. {
  86. return false;
  87. }
  88. bool KIPLATFORM::ENV::VerifyFileSignature( const wxString& aPath )
  89. {
  90. return true;
  91. }
  92. wxString KIPLATFORM::ENV::GetAppUserModelId()
  93. {
  94. return wxEmptyString;
  95. }