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 (C) 2024 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
28 m_format( FORMAT::ZIP )
29{
30}
31
32
34{
35 if( m_outputPath.IsEmpty() )
36 {
37 return false;
38 }
39
40 return true;
41}
42
43
44bool JOBS_OUTPUT_ARCHIVE::HandleOutputs( const wxString& baseTempPath,
45 const std::vector<JOB_OUTPUT>& aOutputsToHandle )
46{
47 bool success = true;
48
49 wxFFileOutputStream ostream( m_outputPath );
50 if( !ostream.IsOk() ) // issue to create the file. Perhaps not writable dir
51 {
52 //msg.Printf( _( "Failed to create file '%s'." ), aDestFile );
53 //aReporter.Report( msg, RPT_SEVERITY_ERROR );
54 return false;
55 }
56
57 wxZipOutputStream zipstream( ostream, -1, wxConvUTF8 );
58 wxString errors;
59
60
61 if( !AddDirectoryToZip( zipstream, baseTempPath, errors ) )
62 {
63 success = false;
64 }
65
66
67 if( !zipstream.Close() )
68 {
69 success = false;
70 }
71
72
73 return success;
74}
75
76
77void JOBS_OUTPUT_ARCHIVE::FromJson( const nlohmann::json& j )
78{
79 m_outputPath = j.value( "output_path", "" );
81}
82
83
84void JOBS_OUTPUT_ARCHIVE::ToJson( nlohmann::json& j ) const
85{
86 j["output_path"] = m_outputPath;
87 j["format"] = "zip";
88}
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
void ToJson(nlohmann::json &j) const override
bool HandleOutputs(const wxString &baseTempPath, const std::vector< JOB_OUTPUT > &aOutputsToHandle) override
wxString m_outputPath
Definition: jobs_output.h:54
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:426