KiCad PCB EDA Suite
Loading...
Searching...
No Matches
jobs_output_folder.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) 2024 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <wx/filename.h>
23#include <gestfich.h>
24#include <common.h>
25
31
32
33bool JOBS_OUTPUT_FOLDER::HandleOutputs( const wxString& baseTempPath,
34 PROJECT* aProject,
35 const std::vector<wxString>& aPathsWithOverwriteDisallowed,
36 const std::vector<JOB_OUTPUT>& aOutputsToHandle,
37 std::optional<wxString>& aResolvedOutputPath )
38{
39 aResolvedOutputPath.reset();
40
41 wxString outputPath = ExpandTextVars( m_outputPath, aProject );
42 outputPath = ExpandEnvVarSubstitutions( outputPath, aProject );
43
44 if( outputPath.StartsWith( "~" ) )
45 outputPath.Replace( "~", wxGetHomeDir(), false );
46
47 if( !wxFileName::DirExists( outputPath ) )
48 {
49 if( !wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
50 {
51 aResolvedOutputPath.reset();
52 return false;
53 }
54 }
55
56 wxString errors;
57
58 if( !CopyDirectory( baseTempPath, outputPath, aPathsWithOverwriteDisallowed, errors ) )
59 {
60 aResolvedOutputPath.reset();
61 return false;
62 }
63
64 aResolvedOutputPath = outputPath;
65
66 return true;
67}
68
69
71{
72 if( m_outputPath.IsEmpty() )
73 return false;
74
75 return true;
76}
77
78
79void JOBS_OUTPUT_FOLDER::FromJson( const nlohmann::json& j )
80{
81 m_outputPath = j.value( "output_path", "" );
82}
83
84
85void JOBS_OUTPUT_FOLDER::ToJson( nlohmann::json& j ) const
86{
87 j["output_path"] = m_outputPath;
88}
89
90
92{
93 return _( "Folder" );
94}
bool OutputPrecheck() override
Checks if the output process can proceed before doing anything else This can include user prompts.
void FromJson(const nlohmann::json &j) override
bool HandleOutputs(const wxString &aBaseTempPath, PROJECT *aProject, const std::vector< wxString > &aPathsWithOverwriteDisallowed, const std::vector< JOB_OUTPUT > &aOutputsToHandle, std::optional< wxString > &aResolvedOutputPath) override
wxString GetDefaultDescription() const override
void ToJson(nlohmann::json &j) const override
Container for project specific data.
Definition project.h:65
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:558
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:62
The common library.
#define _(s)
bool CopyDirectory(const wxString &aSourceDir, const wxString &aDestDir, const std::vector< wxString > &aPathsWithOverwriteDisallowed, wxString &aErrors)
Copy a directory and its contents to another directory.
Definition gestfich.cpp:435