File indexing completed on 2024-05-05 05:48:52

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk>
0005 
0006     SPDX-License-Identifier: GPL-3.0-or-later
0007 */
0008 
0009 #ifndef KPMCORE_RESTOREOPERATION_H
0010 #define KPMCORE_RESTOREOPERATION_H
0011 
0012 #include "util/libpartitionmanagerexport.h"
0013 
0014 #include "ops/operation.h"
0015 
0016 #include <QString>
0017 
0018 class Partition;
0019 class Device;
0020 class OperationStack;
0021 class Report;
0022 class PartitionNode;
0023 
0024 class CreatePartitionJob;
0025 class RestoreFileSystemJob;
0026 class CheckFileSystemJob;
0027 class ResizeFileSystemJob;
0028 
0029 /** Restore a Partition.
0030 
0031     Restores the FileSystem from a file to the given Partition on the given Device, handling overwriting
0032     a previous Partition in case that is necessary.
0033 
0034     @author Volker Lanz <vl@fidra.de>
0035 */
0036 class LIBKPMCORE_EXPORT RestoreOperation : public Operation
0037 {
0038     friend class OperationStack;
0039 
0040     Q_DISABLE_COPY(RestoreOperation)
0041 
0042 public:
0043     RestoreOperation(Device& d, Partition* p, const QString& filename);
0044     ~RestoreOperation();
0045 
0046 public:
0047     QString iconName() const override {
0048         return QStringLiteral("document-import");
0049     }
0050     QString description() const override;
0051     bool execute(Report& parent) override;
0052     void undo() override;
0053 
0054     void preview() override;
0055 
0056     bool targets(const Device& d) const override;
0057     bool targets(const Partition& p) const override;
0058 
0059     static bool canRestore(const Partition* p);
0060     static Partition* createRestorePartition(const Device& device, PartitionNode& parent, qint64 start, const QString& fileName);
0061 
0062 protected:
0063     Device& targetDevice() {
0064         return m_TargetDevice;
0065     }
0066     const Device& targetDevice() const {
0067         return m_TargetDevice;
0068     }
0069 
0070     Partition& restorePartition() {
0071         return *m_RestorePartition;
0072     }
0073     const Partition& restorePartition() const {
0074         return *m_RestorePartition;
0075     }
0076 
0077     const QString& fileName() const {
0078         return m_FileName;
0079     }
0080 
0081     Partition* overwrittenPartition() {
0082         return m_OverwrittenPartition;
0083     }
0084     const Partition* overwrittenPartition() const {
0085         return m_OverwrittenPartition;
0086     }
0087     void setOverwrittenPartition(Partition* p);
0088 
0089     void cleanupOverwrittenPartition();
0090     bool mustDeleteOverwritten() const {
0091         return m_MustDeleteOverwritten;
0092     }
0093 
0094     qint64 imageLength() const {
0095         return m_ImageLength;
0096     }
0097 
0098     CreatePartitionJob* createPartitionJob() {
0099         return m_CreatePartitionJob;
0100     }
0101     RestoreFileSystemJob* restoreJob() {
0102         return m_RestoreJob;
0103     }
0104     CheckFileSystemJob* checkTargetJob() {
0105         return m_CheckTargetJob;
0106     }
0107     ResizeFileSystemJob* maximizeJob() {
0108         return m_MaximizeJob;
0109     }
0110 
0111 private:
0112     Device& m_TargetDevice;
0113     Partition* m_RestorePartition;
0114     const QString m_FileName;
0115     Partition* m_OverwrittenPartition;
0116     bool m_MustDeleteOverwritten;
0117     qint64 m_ImageLength;
0118     CreatePartitionJob* m_CreatePartitionJob;
0119     RestoreFileSystemJob* m_RestoreJob;
0120     CheckFileSystemJob* m_CheckTargetJob;
0121     ResizeFileSystemJob* m_MaximizeJob;
0122 };
0123 
0124 #endif