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
18 * along with this program. If not, see <https://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 = ResolveOutputPath( m_outputPath, aProject );
42
43 if( !wxFileName::DirExists( outputPath ) )
44 {
45 if( !wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
46 {
47 aResolvedOutputPath.reset();
48 return false;
49 }
50 }
51
52 wxString errors;
53
54 if( !CopyDirectory( baseTempPath, outputPath, aPathsWithOverwriteDisallowed, errors ) )
55 {
56 aResolvedOutputPath.reset();
57 return false;
58 }
59
60 aResolvedOutputPath = outputPath;
61
62 return true;
63}
64
65
67{
68 if( m_outputPath.IsEmpty() )
69 return false;
70
71 return true;
72}
73
74
75void JOBS_OUTPUT_FOLDER::FromJson( const nlohmann::json& j )
76{
77 m_outputPath = j.value( "output_path", "" );
78}
79
80
81void JOBS_OUTPUT_FOLDER::ToJson( nlohmann::json& j ) const
82{
83 j["output_path"] = m_outputPath;
84}
85
86
88{
89 return _( "Folder" );
90}
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
static wxString ResolveOutputPath(const wxString &aPath, const PROJECT *aProject)
Expand variables and a leading '~' in a destination path, then anchor a relative result at the projec...
Container for project specific data.
Definition project.h:63
#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:505