KiCad PCB EDA Suite
Loading...
Searching...
No Matches
jobs_output_archive.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/fs_zip.h>
23#include <wx/wfstream.h>
24#include <wx/zipstrm.h>
25#include <gestfich.h>
26#include <common.h>
28
34
35
37{
38 if( m_outputPath.IsEmpty() )
39 return false;
40
41 return true;
42}
43
44
45bool JOBS_OUTPUT_ARCHIVE::HandleOutputs( const wxString& baseTempPath,
46 PROJECT* aProject,
47 const std::vector<JOB_OUTPUT>& aOutputsToHandle,
48 std::optional<wxString>& aResolvedOutputPath )
49{
50 bool success = true;
51 aResolvedOutputPath.reset();
52
53 wxString outputPath = ExpandTextVars( m_outputPath, aProject );
54 outputPath = ExpandEnvVarSubstitutions( outputPath, aProject );
55
56 if( outputPath.StartsWith( "~" ) )
57 outputPath.Replace( "~", wxGetHomeDir(), false );
58
59 outputPath = EnsureFileExtension( outputPath, FILEEXT::ArchiveFileExtension );
60
61 wxFFileOutputStream ostream( outputPath );
62
63 if( !ostream.IsOk() ) // issue to create the file. Perhaps not writable dir
64 {
65 //msg.Printf( _( "Failed to create file '%s'." ), aDestFile );
66 //aReporter.Report( msg, RPT_SEVERITY_ERROR );
67 aResolvedOutputPath.reset();
68 return false;
69 }
70
71 wxZipOutputStream zipstream( ostream, -1, wxConvUTF8 );
72 wxString errors;
73
74 if( !AddDirectoryToZip( zipstream, baseTempPath, errors ) )
75 success = false;
76
77 if( !zipstream.Close() )
78 success = false;
79
80 if( success )
81 aResolvedOutputPath = outputPath;
82 else
83 aResolvedOutputPath.reset();
84
85 return success;
86}
87
88
89void JOBS_OUTPUT_ARCHIVE::FromJson( const nlohmann::json& j )
90{
91 m_outputPath = j.value( "output_path", "" );
93}
94
95
96void JOBS_OUTPUT_ARCHIVE::ToJson( nlohmann::json& j ) const
97{
98 j["output_path"] = m_outputPath;
99 j["format"] = "zip";
100}
101
102
104{
105 return _( "Archive" );
106}
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
void ToJson(nlohmann::json &j) const override
wxString GetDefaultDescription() 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 EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
Definition common.cpp:439
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:60
The common library.
#define _(s)
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:547
static const std::string ArchiveFileExtension
Definition of file extensions used in Kicad.