KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gestfich.h
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) 2009-2014 Jerry Jacobs
5 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <map>
24#include <filesystem>
25#include <string>
26#include <unordered_set>
27#include <kicommon.h>
28#include <wx/arrstr.h>
29#include <wx/dir.h>
30#include <wx/filename.h>
31#include <wx/process.h>
32#include <wx/zipstrm.h>
33
34
38#define UNIX_STRING_DIR_SEP wxT( "/" )
39#define WIN_STRING_DIR_SEP wxT( "\\" )
40
41/* Forward class declarations. */
42class EDA_LIST_DIALOG;
43
44
52KICOMMON_API bool OpenPDF( const wxString& file );
53
59KICOMMON_API void KiCopyFile( const wxString& aSrcPath, const wxString& aDestPath,
60 wxString& aErrors );
61
69KICOMMON_API void CopySexprFile( const wxString& aSrcPath, const wxString& aDestPath,
70 std::function<bool( const std::string& token, wxString& value )> aCallback,
71 wxString& aErrors );
72
83KICOMMON_API int ExecuteFile( const wxString& aEditorName,
84 const wxString& aFileName = wxEmptyString,
85 wxProcess* aCallback = nullptr, bool aFileForKicad = true );
86
99KICOMMON_API int ExecuteCommandThroughShell( const wxString& aCommand, wxProcess* aProcess = nullptr );
100
106KICOMMON_API void QuoteString( wxString& string );
107
118KICOMMON_API wxString FindKicadFile( const wxString& shortname );
119
130KICOMMON_API extern wxString QuoteFullPath( wxFileName& fn, wxPathFormat format = wxPATH_NATIVE );
131
132
137KICOMMON_API bool RmDirRecursive( const wxString& aDirName, wxString* aErrors = nullptr );
138
146KICOMMON_API bool CopyDirectory( const wxString& aSourceDir, const wxString& aDestDir,
147 const std::vector<wxString>& aOverwriteExclusions, wxString& aErrors );
148
149KICOMMON_API bool CopyFilesOrDirectory( const wxString& aSourceDir, const wxString& aDestDir, bool aAllowOverwrite,
150 wxString& aErrors, std::vector<wxString>& aPathsWritten );
151
160KICOMMON_API bool AddDirectoryToZip( wxZipOutputStream& aZip, const wxString& aSourceDir, wxString& aErrors,
161 const wxString& aParentDir = "" );
162
179KICOMMON_API void CollectFilesLoopSafe( const wxString& aRoot, wxArrayString& aFiles,
180 const wxString& aFileSpec = wxEmptyString,
181 int aFlags = wxDIR_DEFAULT );
182
194KICOMMON_API void CollectSubdirsLoopSafe( const wxString& aRoot, wxArrayString& aDirs,
195 int aFlags = wxDIR_DIRS );
196
197
198// how a symlink that resolves outside the scan root is treated
200{
201 CONFINE_TO_ROOT, // descend only into targets that stay inside the root subtree
202 BLOCK_ROOT_ESCAPE // descend anywhere except a link resolving to an ancestor of the root
203};
204
205
206// bounds a hand-rolled recursive dir walk against symlink cycles and root escapes
207// query ShouldDescend before recursing real dirs keyed by name links canonicalized
209{
210public:
211 explicit DIR_LOOP_GUARD( const wxString& aRoot,
213
214 // false when the root itself would not resolve caller must not walk
215 bool IsRooted() const { return !m_root.empty(); }
216
217 bool ShouldDescend( const wxString& aDir );
218
219private:
220 std::filesystem::path m_root;
222 std::unordered_set<std::string> m_visited;
223};
DIR_LOOP_POLICY m_policy
Definition gestfich.h:221
std::unordered_set< std::string > m_visited
Definition gestfich.h:222
bool IsRooted() const
Definition gestfich.h:215
DIR_LOOP_GUARD(const wxString &aRoot, DIR_LOOP_POLICY aPolicy=DIR_LOOP_POLICY::CONFINE_TO_ROOT)
Definition gestfich.cpp:814
std::filesystem::path m_root
Definition gestfich.h:220
A dialog which shows:
KICOMMON_API bool CopyFilesOrDirectory(const wxString &aSourceDir, const wxString &aDestDir, bool aAllowOverwrite, wxString &aErrors, std::vector< wxString > &aPathsWritten)
Definition gestfich.cpp:541
KICOMMON_API wxString QuoteFullPath(wxFileName &fn, wxPathFormat format=wxPATH_NATIVE)
Quote return value of wxFileName::GetFullPath().
Definition gestfich.cpp:433
KICOMMON_API bool CopyDirectory(const wxString &aSourceDir, const wxString &aDestDir, const std::vector< wxString > &aOverwriteExclusions, wxString &aErrors)
Copy a directory and its contents to another directory.
Definition gestfich.cpp:487
KICOMMON_API void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition gestfich.cpp:343
KICOMMON_API int ExecuteCommandThroughShell(const wxString &aCommand, wxProcess *aProcess=nullptr)
Run a user-supplied command line through the platform shell so glob expansion, pipes,...
Definition gestfich.cpp:272
KICOMMON_API bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.
Definition gestfich.cpp:307
KICOMMON_API void QuoteString(wxString &string)
Add un " to the start and the end of string (if not already done).
Definition gestfich.cpp:52
KICOMMON_API wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
Definition gestfich.cpp:62
KICOMMON_API void CollectSubdirsLoopSafe(const wxString &aRoot, wxArrayString &aDirs, int aFlags=wxDIR_DIRS)
Recursively collect every subdirectory under aRoot using the same loop detection as CollectFilesLoopS...
Definition gestfich.cpp:883
KICOMMON_API void CollectFilesLoopSafe(const wxString &aRoot, wxArrayString &aFiles, const wxString &aFileSpec=wxEmptyString, int aFlags=wxDIR_DEFAULT)
Recursively collect every file under aRoot, deduplicating subdirectories by their resolved path.
Definition gestfich.cpp:873
KICOMMON_API bool RmDirRecursive(const wxString &aDirName, wxString *aErrors=nullptr)
Remove the directory aDirName and all its contents including subdirectories and their files.
Definition gestfich.cpp:439
KICOMMON_API void CopySexprFile(const wxString &aSrcPath, const wxString &aDestPath, std::function< bool(const std::string &token, wxString &value)> aCallback, wxString &aErrors)
Definition gestfich.cpp:370
KICOMMON_API int ExecuteFile(const wxString &aEditorName, const wxString &aFileName=wxEmptyString, wxProcess *aCallback=nullptr, bool aFileForKicad=true)
Call the executable file aEditorName with the parameter aFileName.
Definition gestfich.cpp:161
DIR_LOOP_POLICY
Definition gestfich.h:200
KICOMMON_API bool AddDirectoryToZip(wxZipOutputStream &aZip, const wxString &aSourceDir, wxString &aErrors, const wxString &aParentDir="")
Add a directory and its contents to a zip file.
Definition gestfich.cpp:664
#define KICOMMON_API
Definition kicommon.h:27