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<JOB_OUTPUT>& aOutputsToHandle,
36 std::optional<wxString>& aResolvedOutputPath )
37{
38 aResolvedOutputPath.reset();
39
40 wxString outputPath = ExpandTextVars( m_outputPath, aProject );
41 outputPath = ExpandEnvVarSubstitutions( outputPath, aProject );
42
43 if( outputPath.StartsWith( "~" ) )
44 outputPath.Replace( "~", wxGetHomeDir(), false );
45
46 if( !wxFileName::DirExists( outputPath ) )
47 {
48 if( !wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
49 {
50 aResolvedOutputPath.reset();
51 return false;
52 }
53 }
54
55 wxString errors;
56
57 if( !CopyDirectory( baseTempPath, outputPath, errors ) )
58 {
59 aResolvedOutputPath.reset();
60 return false;
61 }
62
63 aResolvedOutputPath = outputPath;
64
65 return true;
66}
67
68
70{
71 if( m_outputPath.IsEmpty() )
72 return false;
73
74 return true;
75}
76
77
78void JOBS_OUTPUT_FOLDER::FromJson( const nlohmann::json& j )
79{
80 m_outputPath = j.value( "output_path", "" );
81}
82
83
84void JOBS_OUTPUT_FOLDER::ToJson( nlohmann::json& j ) const
85{
86 j["output_path"] = m_outputPath;
87}
88
89
91{
92 return _( "Folder" );
93}
bool OutputPrecheck() override
Checks if the output process can proceed before doing anything else This can include user prompts.
bool HandleOutputs(const wxString &aBaseTempPath, PROJECT *aProject, const std::vector< JOB_OUTPUT > &aOutputsToHandle, std::optional< wxString > &aResolvedOutputPath) override
void FromJson(const nlohmann::json &j) override
wxString GetDefaultDescription() const override
void ToJson(nlohmann::json &j) const override
Container for project specific data.
Definition project.h:66
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:365
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:60
The common library.
#define _(s)
bool CopyDirectory(const wxString &aSourceDir, const wxString &aDestDir, wxString &aErrors)
Copy a directory and its contents to another directory.
Definition gestfich.cpp:360