From: Ben Hutchings Date: Mon, 5 Dec 2005 00:24:59 +0000 (+0000) Subject: Cleaned up filename and URI handling, adding support for use of page filenames on... X-Git-Tag: 0.4~1 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=videolink.git;a=commitdiff_plain;h=083fe0658d0b592061ec1332706fa852c4cf13e8 Cleaned up filename and URI handling, adding support for use of page filenames on the command line. --- diff --git a/webdvd.cpp b/webdvd.cpp index 58c849a..6fb547f 100644 --- a/webdvd.cpp +++ b/webdvd.cpp @@ -2,6 +2,7 @@ // See the file "COPYING" for licence details. #include +#include #include #include #include @@ -215,11 +216,9 @@ namespace video_paths_.size() + 1))) .second) { - // FIXME: Should accept some slightly different URI prefixes - // (e.g. file://localhost/) and decode any URI-escaped - // characters in the path. - assert(uri.compare(0, 8, "file:///") == 0); - video_paths_.push_back(uri.substr(7)); + Glib::ustring hostname; + video_paths_.push_back(Glib::filename_from_uri(uri, hostname)); + // FIXME: Should check the hostname } } @@ -905,8 +904,10 @@ int main(int argc, char ** argv) { video::frame_params frame_params = video::pal_params; bool preview_mode = false; + std::string menu_url; + std::string output_dir; - // Do initial argument parsing. We have to do this before + // Do initial option parsing. We have to do this before // letting Gtk parse the arguments since we may need to spawn // Xvfb first. int argi = 1; @@ -958,7 +959,7 @@ int main(int argc, char ** argv) // Initialise Gtk Gtk::Main kit(argc, argv); - // Complete argument parsing with Gtk's options out of the way. + // Complete option parsing with Gtk's options out of the way. argi = 1; while (argi != argc) { @@ -986,18 +987,35 @@ int main(int argc, char ** argv) break; } } - if (argc - argi != (preview_mode ? 1 : 2)) + + // Look for a starting URL or filename and (except in preview + // mode) an output directory after the options. + if (argc - argi != (preview_mode ? 1 : 2)) { print_usage(std::cerr, argv[0]); return EXIT_FAILURE; } + if (std::strstr(argv[argi], "://")) + { + // It appears to be an absolute URL, so use it as-is. + menu_url = argv[argi]; + } + else + { + // Assume it's a filename. Resolve it to an absolute URL. + std::string path(argv[argi]); + if (!Glib::path_is_absolute(path)) + path = Glib::build_filename(Glib::get_current_dir(), path); + menu_url = Glib::filename_to_uri(path); + } + if (!preview_mode) + output_dir = argv[argi + 1]; // Initialise Mozilla BrowserWidget::init(); - WebDvdWindow window(frame_params, - argv[argi], - preview_mode ? "" : argv[argi + 1]); + // Run the browser/converter + WebDvdWindow window(frame_params, menu_url, output_dir); Gtk::Main::run(window); } catch (std::exception & e)