winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

CheckpointManager.h (1960B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include "ExecutionContextData.h"
      5 #include "ExecutionContext.h"
      6 #include <winget/Checkpoint.h>
      7 #include <guiddef.h>
      8 
      9 namespace AppInstaller::Checkpoints
     10 {
     11     // Reads the command arguments from the automatic checkpoint and populates the context.
     12     void LoadCommandArgsFromAutomaticCheckpoint(CLI::Execution::Context& context, Checkpoint<AutomaticCheckpointData>& automaticCheckpoint);
     13 
     14     // Owns the lifetime of a checkpoint data base and creates the checkpoints.
     15     struct CheckpointManager
     16     {
     17         // Constructor that generates a new resume id and creates the checkpoint database.
     18         CheckpointManager();
     19 
     20         // Constructor that loads the resume id and opens an existing checkpoint database.
     21         CheckpointManager(const std::string& resumeId);
     22 
     23         ~CheckpointManager() = default;
     24 
     25         // Gets the file path of the checkpoint database.
     26         static std::filesystem::path GetCheckpointDatabasePath(const std::string_view& resumeId, bool createCheckpointDirectory = false);
     27 
     28         // Gets the resume id.
     29         std::string GetResumeId() { return m_resumeId; };
     30 
     31         // Gets the automatic checkpoint.
     32         std::optional<Checkpoint<AutomaticCheckpointData>> GetAutomaticCheckpoint();
     33 
     34         // Creates an automatic checkpoint using the provided context.
     35         void CreateAutomaticCheckpoint(CLI::Execution::Context& context);
     36 
     37         // Gets all context data checkpoints.
     38         std::vector<Checkpoint<CLI::Execution::Data>> GetCheckpoints();
     39 
     40         // Creates a new context data checkpoint.
     41         Checkpoint<CLI::Execution::Data> CreateCheckpoint(std::string_view checkpointName);
     42 
     43         // Cleans up the checkpoint database.
     44         void CleanUpDatabase();
     45 
     46     private:
     47         std::string m_resumeId;
     48         std::shared_ptr<AppInstaller::Repository::Microsoft::CheckpointDatabase> m_checkpointDatabase;
     49     };
     50 }