My Project  + 80db3
slice.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2019 Daniel Scharrer
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the author(s) be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
26 #ifndef INNOEXTRACT_STREAM_SLICE_HPP
27 #define INNOEXTRACT_STREAM_SLICE_HPP
28 
29 #include <ios>
30 #include <string>
31 
32 #include <boost/iostreams/concepts.hpp>
33 #include <boost/filesystem/path.hpp>
34 
35 #include "util/fstream.hpp"
36 
37 namespace stream {
38 
40 struct slice_error : public std::ios_base::failure {
41 
42  explicit slice_error(const std::string & msg) : std::ios_base::failure(msg) { }
43 
44 };
45 
57 class slice_reader : public boost::iostreams::source {
58 
59  typedef boost::filesystem::path path_type;
60 
61  // Information for reading embedded setup data
62  const boost::uint32_t data_offset;
63 
64  // Information for eading external setup data
65  path_type dir;
66  std::string base_file;
67  std::string base_file2;
68  const size_t slices_per_disk;
69 
70  // Information about the current slice
71  size_t current_slice;
72  boost::uint32_t slice_size;
73 
74  // Streams
75  util::ifstream ifs;
76  std::istream * is;
77 
78  void seek(size_t slice);
79  bool open_file(const path_type & file);
80  bool open_file_case_insensitive(const path_type & dirname, const path_type & filename);
81  void open(size_t slice);
82 
83 public:
84 
85  static std::string slice_filename(const std::string & basename, size_t slice,
86  size_t slices_per_disk = 1);
87 
100  slice_reader(std::istream * istream, boost::uint32_t offset);
101 
117  slice_reader(const path_type & dirname, const std::string & basename, const std::string & basename2,
118  size_t disk_slice_count);
119 
129  bool seek(size_t slice, boost::uint32_t offset);
130 
146  std::streamsize read(char * buffer, std::streamsize bytes);
147 
149  size_t slice() { return current_slice; }
150 
152  bool is_open() { return (is != &ifs || ifs.is_open()); }
153 
154 };
155 
156 } // namespace stream
157 
158 #endif // INNOEXTRACT_STREAM_SLICE_HPP
boost::filesystem::{i,o,}fstream doesn't support unicode names on windows Implement our own wrapper u...
Abstraction for reading either data embedded inside the setup executable or from multiple external sl...
Definition: slice.hpp:57
static std::string slice_filename(const std::string &basename, size_t slice, size_t slices_per_disk=1)
Definition: slice.cpp:137
Definition: block.cpp:49
boost::filesystem::ifstream ifstream
Definition: fstream.hpp:36
slice_error(const std::string &msg)
Definition: slice.hpp:42
std::streamsize read(char *buffer, std::streamsize bytes)
Read a number of bytes starting at the current slice and offset within that slice.
Definition: slice.cpp:222
slice_reader(std::istream *istream, boost::uint32_t offset)
Construct a slice_reader to read from data inside the setup file.
Definition: slice.cpp:47
Error thrown by slice_reader if there was a problem.
Definition: slice.hpp:40
Information specifying a single file inside a compressed chunk.
Definition: file.hpp:53