diff --git a/ChangeLog b/ChangeLog index 471d14ea9..2b12bf87d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2003-09-17 Moritz Bunkus + * mmg: Added a lot of checks on the data given by the user so that + invalid data is reported by mmg and not by mkvmerge. + * mmg: Made the app a GUI app which gets rid of the "DOS box" on Windows. diff --git a/src/mkvmerge.cpp b/src/mkvmerge.cpp index 942e51872..128018b2d 100644 --- a/src/mkvmerge.cpp +++ b/src/mkvmerge.cpp @@ -627,7 +627,8 @@ static void parse_split(const char *arg) { split_after *= modifier; if (split_after <= (1024 * 1024)) - mxerror("Invalid split size in '--split %s'.\n", orig.c_str()); + mxerror("Invalid split size in '--split %s' (size too small).\n", + orig.c_str()); safefree(s); split_by_time = false; diff --git a/src/mmg/mmg.cpp b/src/mmg/mmg.cpp index 538e29705..c722b0bd9 100644 --- a/src/mmg/mmg.cpp +++ b/src/mmg/mmg.cpp @@ -246,7 +246,7 @@ mmg_dialog::mmg_dialog(): wxFrame(NULL, -1, "mkvmerge GUI v" VERSION, void mmg_dialog::on_browse_output(wxCommandEvent &evt) { wxFileDialog dlg(NULL, "Choose an output file", last_open_dir, "", _T("Matroska A/V files (*.mka;*.mkv)|*.mka;*.mkv|" - "All Files (*.*)|*.*"), wxSAVE | wxOVERWRITE_PROMPT); + ALLFILES), wxSAVE | wxOVERWRITE_PROMPT); if(dlg.ShowModal() == wxID_OK) { last_open_dir = dlg.GetDirectory(); tc_output->SetValue(dlg.GetPath()); @@ -374,13 +374,6 @@ void mmg_dialog::on_run(wxCommandEvent &evt) { update_command_line(); - if (!tracks_selected) { - wxMessageBox(_("You have not yet selected any input file and/or no " - "tracks."), - _("mkvmerge GUI: error"), wxOK | wxCENTER | wxICON_ERROR); - return; - } - if (tc_output->GetValue().Length() == 0) { wxMessageBox(_("You have not yet selected an output file."), _("mkvmerge GUI: error"), wxOK | wxCENTER | wxICON_ERROR); @@ -453,7 +446,7 @@ void mmg_dialog::on_update_command_line(wxTimerEvent &evt) { void mmg_dialog::update_command_line() { uint32_t fidx, tidx; - bool tracks_present_here; + bool tracks_selected_here; bool no_audio, no_video, no_subs; mmg_file_t *f; mmg_track_t *t; @@ -468,10 +461,9 @@ void mmg_dialog::update_command_line() { clargs.Add("-o"); clargs.Add(tc_output->GetValue()); - tracks_selected = false; for (fidx = 0; fidx < files.size(); fidx++) { f = &files[fidx]; - tracks_present_here = false; + tracks_selected_here = false; no_audio = true; no_video = true; no_subs = true; @@ -482,7 +474,7 @@ void mmg_dialog::update_command_line() { if (!t->enabled) continue; - tracks_present_here = true; + tracks_selected_here = true; fix_format("%lld", format); sid.Printf(format.c_str(), t->id); @@ -596,9 +588,7 @@ void mmg_dialog::update_command_line() { } - if (tracks_present_here) { - tracks_selected = true; - + if (tracks_selected_here) { if (f->no_chapters) { cmdline += "--no-chapters "; clargs.Add("--no-chapters"); diff --git a/src/mmg/mmg.h b/src/mmg/mmg.h index 179dc727c..5913de281 100644 --- a/src/mmg/mmg.h +++ b/src/mmg/mmg.h @@ -327,8 +327,6 @@ protected: tab_global *global_page; tab_settings *settings_page; - bool tracks_selected; - public: mmg_dialog(); diff --git a/src/mmg/mux_dialog.cpp b/src/mmg/mux_dialog.cpp index b58789449..817f8c93d 100644 --- a/src/mmg/mux_dialog.cpp +++ b/src/mmg/mux_dialog.cpp @@ -89,10 +89,8 @@ mux_dialog::mux_dialog(wxWindow *parent): wxArrayString &arg_list = static_cast(parent)->get_command_line_args(); char **args = (char **)safemalloc((arg_list.Count() + 1) * sizeof(char *)); - for (i = 0; i < arg_list.Count(); i++) { + for (i = 0; i < arg_list.Count(); i++) args[i] = safestrdup(arg_list[i].c_str()); - mxinfo("ARG %d: '%s'\n", i, args[i]); - } args[i] = NULL; pid = wxExecute(args, wxEXEC_ASYNC, process); diff --git a/src/mmg/tab_attachments.cpp b/src/mmg/tab_attachments.cpp index 1dfd66d78..ed8c1cdf8 100644 --- a/src/mmg/tab_attachments.cpp +++ b/src/mmg/tab_attachments.cpp @@ -269,7 +269,7 @@ bool tab_attachments::validate_settings() { a = &attachments[i]; if (a->mime_type->Length() == 0) { wxMessageBox(_T("No MIME type has been selected for the attachment '" + - *a->file_name + "."), _T("Missing input"), + *a->file_name + "'."), _T("Missing input"), wxOK | wxCENTER | wxICON_ERROR); return false; } diff --git a/src/mmg/tab_global.cpp b/src/mmg/tab_global.cpp index ae8d3386a..384f0fd49 100644 --- a/src/mmg/tab_global.cpp +++ b/src/mmg/tab_global.cpp @@ -350,6 +350,86 @@ void tab_global::save(wxConfigBase *cfg) { } bool tab_global::validate_settings() { + string s; + int64_t dummy_i, mod; + char c; + + if (cb_split->GetValue()) { + if (rb_split_by_size->GetValue()) { + s = cob_split_by_size->GetValue(); + strip(s); + if (s.length() == 0) { + wxMessageBox(_T("Splitting by size was selected, but no size has " + "been given."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + c = s[s.length() - 1]; + mod = 1; + if (tolower(c) == 'k') + mod = 1024; + else if (tolower(c) == 'm') + mod = 1024 * 1024; + else if (tolower(c) == 'g') + mod = 1024 * 1024 * 1024; + if (mod != 1) + s.erase(s.length() - 1); + else if (!isdigit(c)) { + wxMessageBox(_T("The format of the split size is invalid."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + if ((s.length() == 0) || !parse_int(s.c_str(), dummy_i)) { + wxMessageBox(_T("The format of the split size is invalid."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + if ((dummy_i * mod) < 1024 * 1024) { + wxMessageBox(_T("The format of the split size is invalid (size too " + "small)."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + + } else { + s = cob_split_by_time->GetValue(); + strip(s); + if (s.length() == 0) { + wxMessageBox(_T("Splitting by time was selected, but no time has " + "been given."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + c = s[s.length() - 1]; + if (tolower(c) == 's') { + s.erase(s.length() - 1); + if ((s.length() == 0) || !parse_int(s.c_str(), dummy_i) || + (dummy_i <= 0)) { + wxMessageBox(_T("The format of the split time is invalid."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | + wxICON_ERROR); + return false; + } + + } else if ((s.length() != 8) || (s[2] != ':') || (s[5] != ':') || + !isdigit(s[0]) || !isdigit(s[1]) || !isdigit(s[3]) || + !isdigit(s[4]) || !isdigit(s[6]) || !isdigit(s[7])) { + wxMessageBox(_T("The format of the split time is invalid."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + } + + s = tc_split_max_files->GetValue(); + strip(s); + if ((s.length() > 0) && (!parse_int(s.c_str(), dummy_i) || + (dummy_i <= 1))) { + wxMessageBox(_T("Invalid number of max. split files given."), + _T("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + } + return true; } diff --git a/src/mmg/tab_input.cpp b/src/mmg/tab_input.cpp index dcdc6cb5e..fd74bfc54 100644 --- a/src/mmg/tab_input.cpp +++ b/src/mmg/tab_input.cpp @@ -309,8 +309,8 @@ void tab_input::on_add_file(wxCommandEvent &evt) { "RealMedia Files (*.rm;*.rmvb)|*.rm;*.rmvb|" "SRT text subtitles (*.srt)|*.srt|" "SSA/ASS text subtitles (*.ssa;*.ass)|*.ssa;*.ass|" - "WAVE (uncompressed PCM) (*.wav)|*.wav|" - "All Files (*.*)|*.*"), wxOPEN); + "WAVE (uncompressed PCM) (*.wav)|*.wav|" ALLFILES), + wxOPEN); if(dlg.ShowModal() == wxID_OK) { last_open_dir = dlg.GetDirectory(); @@ -774,6 +774,119 @@ void tab_input::load(wxConfigBase *cfg) { } bool tab_input::validate_settings() { + uint32_t fidx, tidx, i; + mmg_file_t *f; + mmg_track_t *t; + bool tracks_selected, dot_present, ok; + int64_t dummy_i; + string s; + wxString sid; + + tracks_selected = false; + for (fidx = 0; fidx < files.size(); fidx++) { + f = &files[fidx]; + + for (tidx = 0; tidx < f->tracks->size(); tidx++) { + t = &(*f->tracks)[tidx]; + if (!t->enabled) + continue; + + tracks_selected = true; + sid.Printf("%lld", t->id); + + s = t->delay->c_str(); + strip(s); + if ((s.length() > 0) && !parse_int(s.c_str(), dummy_i)) { + wxMessageBox(_("The delay setting for track nr. " + sid + " in " + "file '" + *f->file_name + "' is invalid."), + _("mkvmerge GUI: error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + + s = t->stretch->c_str(); + strip(s); + if (s.length() > 0) { + dot_present = false; + i = 0; + while (i < s.length()) { + if (isdigit(s[i]) || + (!dot_present && ((s[i] == '.') || (s[i] == ',')))) { + if ((s[i] == '.') || (s[i] == ',')) + dot_present = true; + i++; + } else { + wxMessageBox(_("The stretch setting for track nr. " + sid + " in " + "file '" + *f->file_name + "' is invalid."), + _("mkvmerge GUI: error"), wxOK | wxCENTER | + wxICON_ERROR); + return false; + } + } + } + + s = t->fourcc->c_str(); + strip(s); + if ((s.length() > 0) && (s.length() != 4)) { + wxMessageBox(_("The FourCC setting for track nr. " + sid + " in " + "file '" + *f->file_name + "' is not excatly four " + "characters long."), + _("mkvmerge GUI: error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + + s = t->aspect_ratio->c_str(); + strip(s); + if (s.length() > 0) { + dot_present = false; + i = 0; + ok = true; + while (i < s.length()) { + if (isdigit(s[i]) || + (!dot_present && ((s[i] == '.') || (s[i] == ',')))) { + if ((s[i] == '.') || (s[i] == ',')) + dot_present = true; + i++; + } else { + ok = false; + break; + } + } + + if (!ok) { + dot_present = false; + i = 0; + ok = true; + while (i < s.length()) { + if (isdigit(s[i]) || + (!dot_present && (s[i] == '/'))) { + if (s[i] == '/') + dot_present = true; + i++; + } else { + ok = false; + break; + } + } + } + + if (!ok) { + wxMessageBox(_("The aspect ratio setting for track nr. " + sid + + " in file '" + *f->file_name + "' is invalid."), + _("mkvmerge GUI: error"), wxOK | wxCENTER | + wxICON_ERROR); + return false; + } + } + } + } + + if (!tracks_selected) { + wxMessageBox(_("You have not yet selected any input file and/or no " + "tracks."), + _("mkvmerge GUI: error"), wxOK | wxCENTER | wxICON_ERROR); + return false; + } + return true; }