KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <wx_filename.h>
21#include <string_utils.h>
22
23
24WX_FILENAME::WX_FILENAME( const wxString& aPath, const wxString& aFilename )
25 : m_fn( aPath, aFilename ), m_path( aPath ), m_fullName( aFilename )
26{
27}
28
29
30void WX_FILENAME::SetFullName( const wxString& aFileNameAndExtension )
31{
32 m_fullName = aFileNameAndExtension;
33}
34
35
36void WX_FILENAME::SetPath( const wxString& aPath )
37{
38 m_fn.SetPath( aPath );
39 m_path = aPath;
40}
41
42
43wxString WX_FILENAME::GetName() const
44{
45 size_t dot = m_fullName.find_last_of( wxT( '.' ) );
46 return m_fullName.substr( 0, dot );
47}
48
49
51{
52 return m_fullName;
53}
54
55
56wxString WX_FILENAME::GetPath() const
57{
58 return m_path;
59}
60
61
63{
64 return m_path + wxT( '/' ) + m_fullName;
65}
66
67
69{
70 size_t dot = m_fullName.find_last_of( wxT( '.' ) );
71 m_fn.SetName( m_fullName.substr( 0, dot ) );
72 m_fn.SetExt( m_fullName.substr( dot + 1 ) );
73}
74
75
77{
78 resolve();
79
80 if( m_fn.FileExists() )
81 return m_fn.GetModificationTime().GetValue().GetValue();
82
83 return 0;
84}
85
86
87void WX_FILENAME::ResolvePossibleSymlinks( wxFileName& aFilename )
88{
89#ifndef __WINDOWS__
90 if( aFilename.Exists( wxFILE_EXISTS_SYMLINK ) )
91 {
92 char buffer[PATH_MAX];
93 char* realPath = realpath( TO_UTF8( aFilename.GetFullPath() ), buffer );
94
95 if( realPath )
96 aFilename.Assign( wxString::FromUTF8( realPath ) );
97 }
98#endif
99}
WX_FILENAME(const wxString &aPath, const wxString &aFilename)
void SetFullName(const wxString &aFileNameAndExtension)
static void ResolvePossibleSymlinks(wxFileName &aFilename)
wxString GetPath() const
void SetPath(const wxString &aPath)
wxString m_path
Definition wx_filename.h:69
wxFileName m_fn
Definition wx_filename.h:68
wxString GetName() const
wxString GetFullPath() const
long long GetTimestamp()
wxString GetFullName() const
wxString m_fullName
Definition wx_filename.h:70
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.