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.

104 lines
2.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <wx_filename.h>
  24. #include <string_utils.h>
  25. WX_FILENAME::WX_FILENAME( const wxString& aPath, const wxString& aFilename )
  26. : m_fn( aPath, aFilename ), m_path( aPath ), m_fullName( aFilename )
  27. {
  28. }
  29. void WX_FILENAME::SetFullName( const wxString& aFileNameAndExtension )
  30. {
  31. m_fullName = aFileNameAndExtension;
  32. }
  33. void WX_FILENAME::SetPath( const wxString& aPath )
  34. {
  35. m_fn.SetPath( aPath );
  36. m_path = aPath;
  37. }
  38. wxString WX_FILENAME::GetName() const
  39. {
  40. size_t dot = m_fullName.find_last_of( wxT( '.' ) );
  41. return m_fullName.substr( 0, dot );
  42. }
  43. wxString WX_FILENAME::GetFullName() const
  44. {
  45. return m_fullName;
  46. }
  47. wxString WX_FILENAME::GetPath() const
  48. {
  49. return m_path;
  50. }
  51. wxString WX_FILENAME::GetFullPath() const
  52. {
  53. return m_path + wxT( '/' ) + m_fullName;
  54. }
  55. // Write locally-cached values to the wxFileName. MUST be called before using m_fn.
  56. void WX_FILENAME::resolve()
  57. {
  58. size_t dot = m_fullName.find_last_of( wxT( '.' ) );
  59. m_fn.SetName( m_fullName.substr( 0, dot ) );
  60. m_fn.SetExt( m_fullName.substr( dot + 1 ) );
  61. }
  62. long long WX_FILENAME::GetTimestamp()
  63. {
  64. resolve();
  65. if( m_fn.FileExists() )
  66. return m_fn.GetModificationTime().GetValue().GetValue();
  67. return 0;
  68. }
  69. // Resolve possible symlink(s) in aFileName to an absolute path
  70. void WX_FILENAME::ResolvePossibleSymlinks( wxFileName& aFilename )
  71. {
  72. #ifndef __WINDOWS__
  73. if( aFilename.Exists( wxFILE_EXISTS_SYMLINK ) )
  74. {
  75. char buffer[PATH_MAX];
  76. char* realPath = realpath( TO_UTF8( aFilename.GetFullPath() ), buffer );
  77. if( realPath )
  78. aFilename.Assign( wxString::FromUTF8( realPath ) );
  79. }
  80. #endif
  81. }