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