bundle_runner.h 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#ifndef __BUNDLE_RUNNER_H__
#define __BUNDLE_RUNNER_H__


#include <cstdint>
#include "manifest.h"
#include "error_codes.h"

namespace bundle
{
    class bundle_runner_t
    {
    public:
        bundle_runner_t(const pal::string_t& bundle_path)
            :m_bundle_path(bundle_path),
            m_bundle_stream(nullptr),
            m_manifest(nullptr),
            m_num_embedded_files(0)
        {
        }

        pal::string_t get_extraction_dir()
        {
            return m_extraction_dir;
        }

        StatusCode extract();

        static void read(void* buf, size_t size, FILE* stream);
        static void write(const void* buf, size_t size, FILE* stream);
        static void read_string(pal::string_t& str, size_t size, FILE* stream);

    private:
        void reopen_host_for_reading();
        static void seek(FILE* stream, long offset, int origin);

        void process_manifest_footer(int64_t& header_offset);
        void process_manifest_header(int64_t header_offset);

        void determine_extraction_dir();
        void create_working_extraction_dir();
        bool can_reuse_extraction();

        FILE* create_extraction_file(const pal::string_t& relative_path);
        void extract_file(file_entry_t* entry);

        FILE* m_bundle_stream;
        manifest_t* m_manifest;
        int32_t m_num_embedded_files;
        pal::string_t m_bundle_path;
        pal::string_t m_bundle_id;
        pal::string_t m_extraction_dir;
        pal::string_t m_working_extraction_dir;
    };

}

#endif // __BUNDLE_RUNNER_H__