API Documentation
Loading...
Searching...
No Matches
NDVArchiveManager.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/FileFormat.h>
3#include <NDEVR/BinaryFile.h>
4#include <NDEVR/Translator.h>
5namespace NDEVR
6{
8 {
9 public:
10 static void AddFilesToArchive(const Buffer<File>& files, BinaryFile& archive, CompressionMode mode)
11 {
12 for (File f : files)
13 {
15 if (f.isDirectory())
16 AddFilesToArchive(f.getChildren(), archive, mode);
17 else
18 archive.write(f.getData(), mode);
19 }
21 }
22 static Buffer<File> PullFilesFromArchive(const File& target_parent, BinaryFile& archive)
23 {
24 String file_name;
25 archive.readNow(file_name);
26 Buffer<File> files;
27 while (file_name != "./")
28 {
29 File f = File(target_parent).appendPath(file_name);
30 f.create(false);
31 if (f.isDirectory())
32 {
33 files.addAll(PullFilesFromArchive(f, archive));
34 }
35 else
36 {
38 Buffer<uint01> bytes;
39 archive.readNow(bytes);
40 f << bytes;
41 f.close();
42 }
43 files.add(f);
44 archive.readNow(file_name);
45 }
46 return files;
47 }
48 static void AddFilesToArchive(const Buffer<File>& files, File& archive_file, CompressionMode mode)
49 {
50 BinaryFile archive(archive_file);
51 archive.setUseLargeCompression(true);
52 archive.open(false, false);
53 AddFilesToArchive(files, archive, mode);
54 }
55
56 static Buffer<File> PullFilesFromArchive(const File& target_parent, File archive_file)
57 {
58 BinaryFile archive(archive_file);
59 archive.setUseLargeCompression(true);
60 archive.open(true, false);
61 return PullFilesFromArchive(target_parent, archive);
62 }
63
65 {
66 FileFormat format(UUID::CreateUUID("archive_format"));
67 format.extension = ".lndv";
68 format.name = _t("NDEVR File Template");
69 format.write_supported = true;
70 format.read_supported = true;
71 return format;
72 }
73 };
74}
#define _t(english_string)
Definition Translator.h:87
Definition BinaryFile.h:51
void setUseLargeCompression(bool use_large_compression)
Definition BinaryFile.h:475
void write(const t_type &data)
Definition BinaryFile.h:115
void open(bool read, bool safe)
Definition BinaryFile.h:61
void readNow(Buffer< t_type, t_index_type, t_memory_allocator, t_memory_manager > &data)
Definition BinaryFile.h:327
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
void addAll(const Buffer< t_type, t_other_index_type, t_other_memory_allocator, t_other_memory_manager > &buffer)
Definition Buffer.hpp:248
Definition FileFormat.h:38
bool read_supported
Definition FileFormat.h:49
TranslatedString name
Definition FileFormat.h:44
String extension
Definition FileFormat.h:47
bool write_supported
Definition FileFormat.h:50
Definition File.h:47
NDEVR_BASE_API FILE * open(OpenMode mode, bool append=false)
Definition File.cpp:1419
NDEVR_BASE_API void close()
Definition File.cpp:1610
NDEVR_BASE_API void create(bool override_file) const
Definition File.cpp:1744
@ e_file_name
Definition File.h:73
@ e_file_extension
Definition File.h:74
NDEVR_BASE_API bool isDirectory() const
Definition File.cpp:250
@ e_binary_write
Definition File.h:52
NDEVR_BASE_API File & appendPath(const String &cs)
Definition File.cpp:786
Definition NDVArchiveManager.h:8
static void AddFilesToArchive(const Buffer< File > &files, BinaryFile &archive, CompressionMode mode)
Definition NDVArchiveManager.h:10
static Buffer< File > PullFilesFromArchive(const File &target_parent, File archive_file)
Definition NDVArchiveManager.h:56
static Buffer< File > PullFilesFromArchive(const File &target_parent, BinaryFile &archive)
Definition NDVArchiveManager.h:22
static FileFormat ArchiveFormat()
Definition NDVArchiveManager.h:64
static void AddFilesToArchive(const Buffer< File > &files, File &archive_file, CompressionMode mode)
Definition NDVArchiveManager.h:48
Definition String.h:40
static NDEVR_BASE_API UUID CreateUUID()
Definition UUID.cpp:150
Definition ACIColor.h:37
CompressionMode
Definition Compressor.h:12
@ e_no_compression
Definition Compressor.h:13