1 #include "../StdAfx.h"
\r
3 #include <common/exception/exceptions.h>
\r
5 #include <boost/property_tree/ptree.hpp>
\r
6 #include <boost/property_tree/xml_parser.hpp>
\r
7 #include <boost/algorithm/string/replace.hpp>
\r
12 #include <streambuf>
\r
14 namespace caspar { namespace flash {
\r
16 std::vector<char> decompress_one_file(const std::vector<char>& in_data, uLong buf_size = 5000000)
\r
18 if(buf_size > 300*1000000)
\r
19 BOOST_THROW_EXCEPTION(file_read_error());
\r
21 std::vector<char> out_data(buf_size, 0);
\r
23 auto ret = uncompress((Bytef*)out_data.data(), &buf_size, (Bytef*)in_data.data(), in_data.size());
\r
25 if(ret == Z_BUF_ERROR)
\r
26 return decompress_one_file(in_data, buf_size*2);
\r
29 BOOST_THROW_EXCEPTION(file_read_error());
\r
31 out_data.resize(buf_size);
\r
36 std::string read_template_meta_info(const std::wstring& filename)
\r
38 auto file = std::fstream(filename, std::ios::in | std::ios::binary);
\r
41 BOOST_THROW_EXCEPTION(file_read_error());
\r
46 std::vector<char> data;
\r
48 file.seekg(0, std::ios::end);
\r
49 data.reserve(static_cast<size_t>(file.tellg()));
\r
50 file.seekg(0, std::ios::beg);
\r
52 if(strcmp(head, "CWS") == 0)
\r
54 file.seekg(8, std::ios::beg);
\r
55 std::copy((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>(), std::back_inserter(data));
\r
56 data = decompress_one_file(data);
\r
60 file.seekg(0, std::ios::end);
\r
61 data.reserve(static_cast<size_t>(file.tellg()));
\r
62 file.seekg(0, std::ios::beg);
\r
64 std::copy((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>(), std::back_inserter(data));
\r
67 std::string beg_str = "<template version";
\r
68 std::string end_str = "</template>";
\r
69 auto beg_it = std::find_end(data.begin(), data.end(), beg_str.begin(), beg_str.end());
\r
70 auto end_it = std::find_end(beg_it, data.end(), end_str.begin(), end_str.end());
\r
72 if(beg_it == data.end() || end_it == data.end())
\r
73 BOOST_THROW_EXCEPTION(file_read_error());
\r
75 return std::string(beg_it, end_it+end_str.size());
\r