-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
zip.h
129 lines (108 loc) · 4.85 KB
/
zip.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// zip.h - zip interface
//
// leccore library, part of the liblec library
// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
//
// Released under the MIT license. For full details see the
// file LICENSE.txt
//
#pragma once
#if defined(LECCORE_EXPORTS)
#include "leccore.h"
#else
#include <liblec/leccore.h>
#endif
#include <string>
#include <vector>
namespace liblec {
namespace leccore {
/// <summary>Class for zipping files and folders into a zip archive.</summary>
class leccore_api zip {
public:
zip();
~zip();
/// <summary>The compression level to use.</summary>
enum class compression_level {
/// <summary>Balance between size and speed. The default.</summary>
normal,
/// <summary>For the smallest archive size, but takes longer.</summary>
maximum,
/// <summary>Compromises compression level in favor of speed.</summary>
fast,
/// <summary>Lowest compression level for super fast zipping.</summary>
superfast,
/// <summary>No compression. Use this for the ultimate speed when
/// you don't need any compression and just want to store files.</summary>
none,
};
/// <summary>Start zipping operation.</summary>
/// <param name="filename">The target filename, including the extension.</param>
/// <param name="entries">The archive entries (files, directories).</param>
/// <param name="level">The compression level, as defined in the
/// <see cref="compression_level"></see> enumeration.</param>
/// <remarks>This method returns almost immediately. The actual zipping is executed
/// on a seperate thread. To check the status of the zipping call the
/// <see cref="zipping"></see> method.</remarks>
void start(const std::string& filename,
const std::vector<std::string>& entries,
compression_level level = compression_level::normal);
/// <summary>Check whether the zipping operation is still underway.</summary>
/// <returns>Returns true if the zipping is still underway, else false.</returns>
/// <remarks>After calling <see cref="start"></see> call this method in a loop or a timer, depending on
/// your kind of app, then call <see cref="result"></see> once it returns false.</remarks>
bool zipping();
/// <summary>The result of the zipping operation.</summary>
/// <param name="error">Error information.</param>
/// <returns>Returns true if the operation was successful, else false. When false the
/// error information is written back to <see cref="error"></see>.</returns>
bool result(std::string& error);
private:
class impl;
impl& _d;
// Copying an object of this class is not allowed
zip(const zip&) = delete;
zip& operator=(const zip&) = delete;
};
/// <summary>Class for unzipping a zip archive.</summary>
class leccore_api unzip {
public:
unzip();
~unzip();
/// <summary>Unzip log.</summary>
using unzip_log = struct {
std::vector<std::string> message_list;
std::vector<std::string> error_list;
};
/// <summary>Start zipping operation.</summary>
/// <param name="filename">The full path to the zip archive, including the extension.</param>
/// <param name="directory">The directory to extract the zip archive to. Use an empty string to
/// extract to the current directory.</param>
/// <remarks>This method returns almost immediately. The actual unzipping is executed
/// on a seperate thread. To check the status of the unzipping call the
/// <see cref="unzipping"></see> method.</remarks>
void start(const std::string& filename,
const std::string& directory);
/// <summary>Check whether the unzipping operation is still underway.</summary>
/// <returns>Returns true if the unzipping is still underway, else false.</returns>
/// <remarks>After calling <see cref="start"></see> call this method in a loop or a timer, depending on
/// your kind of app, then call <see cref="result"></see> once it returns false.</remarks>
bool unzipping();
/// <summary>The result of the unzipping operation.</summary>
/// <param name="log">Unzip log as defined in the <see cref="unzip_log"></see> type. This may contain
/// error messages for individual entries regardless of whether the method returns true or false. For example
/// if one of the files already existed and was marked as read-only the unzipping operation continues
/// and this method will return true yet an error will have actually occurred for that one entry.</param>
/// <param name="error">Error information.</param>
/// <returns>Returns true if the operation was successful, else false. When false the
/// error information is written back to <see cref="error"></see>.</returns>
bool result(unzip_log& log, std::string& error);
private:
class impl;
impl& _d;
// Copying an object of this class is not allowed
unzip(const unzip&) = delete;
unzip& operator=(const unzip&) = delete;
};
}
}