Commit 981ba25d authored by Daniel Elstner's avatar Daniel Elstner
Browse files

New exception class.

* src/fileio.h (ErrorBinaryFile): New exception class.

* src/fileio.cc (load_iochannel): Throw ErrorBinaryFile if the
input stream contains '\0' bytes, rather than just returning a
null pointer.
(load_file): Throw ErrorBinaryFile if the file could not be
loaded in either of the specified encodings.

* src/filetree.cc (FileTree::load_file_with_fallback): Handle
the ErrorBinaryFile exception.
parent 30dce6a1
2004-05-21 Daniel Elstner <daniel.elstner@gmx.net>
* src/fileio.h (ErrorBinaryFile): New exception class.
* src/fileio.cc (load_iochannel): Throw ErrorBinaryFile if the
input stream contains '\0' bytes, rather than just returning a
null pointer.
(load_file): Throw ErrorBinaryFile if the file could not be
loaded in either of the specified encodings.
* src/filetree.cc (FileTree::load_file_with_fallback): Handle
the ErrorBinaryFile exception.
2004-05-21 Daniel Elstner <daniel.elstner@gmx.net>
* src/filetree.cc (FileTree::replace_all_matches): Substitute
......
......@@ -46,7 +46,7 @@ Glib::RefPtr<FileBuffer> load_iochannel(const Glib::RefPtr<Glib::IOChannel>& inp
while (input->read(inbuf.get(), BUFSIZE, bytes_read) == Glib::IO_STATUS_NORMAL)
{
if (std::memchr(inbuf.get(), '\0', bytes_read)) // binary file?
return Glib::RefPtr<FileBuffer>();
throw Regexxer::ErrorBinaryFile();
text_end = text_buffer->insert(text_end, inbuf.get(), inbuf.get() + bytes_read);
}
......@@ -147,14 +147,14 @@ void load_file(const FileInfoPtr& fileinfo, const std::string& fallback_encoding
buffer = load_try_encoding(fileinfo->fullname, encoding);
}
if (buffer)
{
buffer->set_modified(false);
if (!buffer)
throw ErrorBinaryFile();
fileinfo->load_failed = false;
fileinfo->encoding = encoding;
fileinfo->buffer = buffer;
}
buffer->set_modified(false);
fileinfo->load_failed = false;
fileinfo->encoding = encoding;
fileinfo->buffer = buffer;
}
void save_file(const FileInfoPtr& fileinfo)
......
......@@ -61,6 +61,7 @@ typedef Util::SharedPtr<FileInfoBase> FileInfoBasePtr;
typedef Util::SharedPtr<DirInfo> DirInfoPtr;
typedef Util::SharedPtr<FileInfo> FileInfoPtr;
class ErrorBinaryFile {}; // exception type
void load_file(const FileInfoPtr& fileinfo, const std::string& fallback_encoding);
void save_file(const FileInfoPtr& fileinfo);
......
......@@ -1003,16 +1003,14 @@ void FileTree::load_file_with_fallback(const Gtk::TreeModel::iterator& iter,
fileinfo->buffer = FileBuffer::create_with_error_message(
render_icon(Gtk::Stock::DIALOG_ERROR, Gtk::ICON_SIZE_DIALOG), error.what());
}
if (!fileinfo->buffer)
catch (const ErrorBinaryFile&)
{
g_assert(fileinfo->load_failed);
const Glib::ustring message = Util::compose(_("\"%1\" seems to be a binary file."),
Util::filename_to_utf8_fallback(Glib::path_get_basename(fileinfo->fullname)));
const Glib::ustring filename =
Util::filename_to_utf8_fallback(Glib::path_get_basename(fileinfo->fullname));
fileinfo->buffer = FileBuffer::create_with_error_message(
render_icon(Gtk::Stock::DIALOG_ERROR, Gtk::ICON_SIZE_DIALOG), message);
render_icon(Gtk::Stock::DIALOG_ERROR, Gtk::ICON_SIZE_DIALOG),
Util::compose(_("\"%1\" seems to be a binary file."), filename));
}
if (old_load_failed != fileinfo->load_failed)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment