KiCad PCB EDA Suite
wx_filename.cpp
Go to the documentation of this file.
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 
24 #include <wx_filename.h>
25 #include <macros.h>
26 
27 
28 WX_FILENAME::WX_FILENAME( const wxString& aPath, const wxString& aFilename )
29  : m_fn( aPath, aFilename ), m_path( aPath ), m_fullName( aFilename )
30 {
31 }
32 
33 
34 void WX_FILENAME::SetFullName( const wxString& aFileNameAndExtension )
35 {
36  m_fullName = aFileNameAndExtension;
37 }
38 
39 
40 wxString WX_FILENAME::GetName() const
41 {
42  size_t dot = m_fullName.find_last_of( wxT( '.' ) );
43  return m_fullName.substr( 0, dot );
44 }
45 
46 
47 wxString WX_FILENAME::GetFullName() const
48 {
49  return m_fullName;
50 }
51 
52 
53 wxString WX_FILENAME::GetPath() const
54 {
55  return m_path;
56 }
57 
58 
59 wxString WX_FILENAME::GetFullPath() const
60 {
61  return m_path + wxT( '/' ) + m_fullName;
62 }
63 
64 
65 // Write locally-cached values to the wxFileName. MUST be called before using m_fn.
67 {
68  size_t dot = m_fullName.find_last_of( wxT( '.' ) );
69  m_fn.SetName( m_fullName.substr( 0, dot ) );
70  m_fn.SetExt( m_fullName.substr( dot + 1 ) );
71 }
72 
73 
75 {
76  resolve();
77 
78  if( m_fn.FileExists() )
79  return m_fn.GetModificationTime().GetValue().GetValue();
80 
81  return 0;
82 }
83 
84 // Resolve possible symlink(s) in aFileName to an absolute path
85 void WX_FILENAME::ResolvePossibleSymlinks( wxFileName& aFilename )
86 {
87 #ifndef __WINDOWS__
88  if( aFilename.Exists( wxFILE_EXISTS_SYMLINK ) )
89  {
90  char buffer[PATH_MAX];
91  char* realPath = realpath( TO_UTF8( aFilename.GetFullPath() ), buffer );
92 
93  if( realPath )
94  aFilename.Assign( wxString::FromUTF8( realPath ) );
95  }
96 #endif
97 }
WX_FILENAME(const wxString &aPath, const wxString &aFilename)
Definition: wx_filename.cpp:28
wxString GetName() const
Definition: wx_filename.cpp:40
wxString GetFullName() const
Definition: wx_filename.cpp:47
wxString m_path
Definition: wx_filename.h:59
void SetFullName(const wxString &aFileNameAndExtension)
Definition: wx_filename.cpp:34
This file contains miscellaneous commonly used macros and functions.
wxFileName m_fn
Definition: wx_filename.h:58
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
long long GetTimestamp()
Definition: wx_filename.cpp:74
void resolve()
Definition: wx_filename.cpp:66
static void ResolvePossibleSymlinks(wxFileName &aFilename)
Definition: wx_filename.cpp:85
wxString GetPath() const
Definition: wx_filename.cpp:53
wxString GetFullPath() const
Definition: wx_filename.cpp:59
wxString m_fullName
Definition: wx_filename.h:60