From 4a5c3e1d3e265040afa49d944f1a67acd7eef081 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Fri, 14 Sep 2012 14:53:24 +0800 Subject: [PATCH] show warning when file cannot be opened --- src/HTMLRenderer/export.cc | 6 +++++- src/HTMLRenderer/general.cc | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index 04c3e3f..f957756 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -23,7 +23,11 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff auto fn = str_fmt("f%llx%s", info.id, suffix.c_str()); if(param->single_html) { - css_fout << "'data:font/opentype;base64," << base64stream(ifstream(param->tmp_dir + "/" + (char*)fn, ifstream::binary)) << "'"; + auto path = param->tmp_dir + "/" + (char*)fn; + ifstream fin(path, ifstream::binary); + if(!fin) + throw "Cannot locate font file: " + path; + css_fout << "'data:font/" + fontfileformat + ";base64," << base64stream(fin) << "'"; } else { diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 67718ce..5e9aa28 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -193,6 +193,8 @@ void HTMLRenderer::post_process() // apply manifest ifstream manifest_fin((char*)str_fmt("%s/%s", param->data_dir.c_str(), MANIFEST_FILENAME.c_str())); + if(!manifest_fin) + throw "Cannot open the manifest file"; bool embed_string = false; string line; @@ -228,7 +230,10 @@ void HTMLRenderer::post_process() } else if (line == "$pages") { - output << ifstream(html_path, ifstream::binary).rdbuf(); + ifstream fin(html_path, ifstream::binary); + if(!fin) + throw "Cannot open read the pages"; + output << fin.rdbuf(); } else { @@ -257,7 +262,11 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state) { if(param->single_html) { - html_fout << "'data:image/png;base64," << base64stream(ifstream((char*)str_fmt("%s/p%x.png", param->tmp_dir.c_str(), pageNum) , ifstream::binary)) << "'"; + auto path = str_fmt("%s/p%x.png", param->tmp_dir.c_str(), pageNum); + ifstream fin((char*)path, ifstream::binary); + if(!fin) + throw string("Cannot read background image ") + (char*)path; + html_fout << "'data:image/png;base64," << base64stream(fin) << "'"; } else { @@ -346,8 +355,11 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string & if(param->single_html) { + ifstream fin(path, ifstream::binary); + if(!fin) + throw string("Cannot open file for embedding: ") + path; out << iter->second.first << endl - << ifstream(path, ifstream::binary).rdbuf() + << fin.rdbuf() << iter->second.second << endl; } else @@ -358,7 +370,10 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string & if(copy) { - ofstream(param->dest_dir + "/" + fn, ofstream::binary) << ifstream(path, ifstream::binary).rdbuf(); + ifstream fin(path, ifstream::binary); + if(!fin) + throw string("Cannot copy file: ") + path; + ofstream(param->dest_dir + "/" + fn, ofstream::binary) << fin.rdbuf(); } } }