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.

103 lines
2.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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. void WX_FILENAME::resolve()
  56. {
  57. size_t dot = m_fullName.find_last_of( wxT( '.' ) );
  58. m_fn.SetName( m_fullName.substr( 0, dot ) );
  59. m_fn.SetExt( m_fullName.substr( dot + 1 ) );
  60. }
  61. long long WX_FILENAME::GetTimestamp()
  62. {
  63. resolve();
  64. if( m_fn.FileExists() )
  65. return m_fn.GetModificationTime().GetValue().GetValue();
  66. return 0;
  67. }
  68. void WX_FILENAME::ResolvePossibleSymlinks( wxFileName& aFilename )
  69. {
  70. #ifndef __WINDOWS__
  71. if( aFilename.Exists( wxFILE_EXISTS_SYMLINK ) )
  72. {
  73. char buffer[PATH_MAX];
  74. char* realPath = realpath( TO_UTF8( aFilename.GetFullPath() ), buffer );
  75. if( realPath )
  76. aFilename.Assign( wxString::FromUTF8( realPath ) );
  77. }
  78. #endif
  79. }