diff options
| author | Walker Thompson <walker.thompson@urz.uni-heidelberg.de> | 2026-01-27 17:28:59 +0000 |
|---|---|---|
| committer | Walker Thompson <walker.thompson@urz.uni-heidelberg.de> | 2026-01-27 19:39:34 +0000 |
| commit | 3d7ab959fb8fe8aec889650b20693ff88907f799 (patch) | |
| tree | f43d53fe15dffd0d54c87d03aa018a8ff2588c00 /wxgui.cpp | |
| parent | a2d7ebcdc396fcaa505251dd1625df34fdd00771 (diff) | |
Fix crash with non-ASCII filenames; change CSV to TSV
Diffstat (limited to 'wxgui.cpp')
| -rw-r--r-- | wxgui.cpp | 91 |
1 files changed, 49 insertions, 42 deletions
@@ -5,6 +5,12 @@ IMPLEMENT_APP(TranscodeGUI) bool TranscodeGUI::OnInit() { +#ifdef _WIN32 + setlocale(LC_ALL, ".UTF8"); + SetConsoleOutputCP(CP_UTF8); +#else + std::locale::global(std::locale("")); +#endif TranscodeFrame *transcodeFrame = new TranscodeFrame; transcodeFrame->Show(true); @@ -26,8 +32,8 @@ TranscodeFrame::TranscodeFrame(): + ".slavconvertrc"; #endif read_config_file(config_filepath, config_options); - config_params.do_greek = to_bool(config_options[L"greek"]); - config_params.do_font_select = to_bool(config_options[L"fontsel"]); + config_params.do_greek = to_bool(config_options["greek"]); + config_params.do_font_select = to_bool(config_options["fontsel"]); main_panel = new wxPanel(this, wxID_ANY); main_sizer = new wxBoxSizer(wxVERTICAL); @@ -44,28 +50,28 @@ TranscodeFrame::TranscodeFrame(): infile_sizer->Add(infile_field, 2, wxEXPAND | wxALL); infile_sizer->Add(infile_button, 0, wxALL | wxALIGN_CENTER_VERTICAL); main_sizer->Add(infile_sizer, 0, wxEXPAND | wxALL, 2); - wxString infile_from_cfg = config_options[L"in"]; + wxString infile_from_cfg = config_options["in"]; if (wxFileExists(infile_from_cfg)) { infile_path = infile_from_cfg; infile_field->ChangeValue(infile_path); } - csvfile_sizer = new wxBoxSizer(wxHORIZONTAL); - csvfile_label = new wxStaticText(main_panel, wxID_ANY, + tsvfile_sizer = new wxBoxSizer(wxHORIZONTAL); + tsvfile_label = new wxStaticText(main_panel, wxID_ANY, wxT("Character Table (TSV)"), wxDefaultPosition, wxDefaultSize); - csvfile_field = new wxTextCtrl(main_panel, wxID_ANY, wxEmptyString, + tsvfile_field = new wxTextCtrl(main_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCB_READONLY); - csvfile_button = new wxButton(main_panel, wxID_ANY, wxT("Select")); - main_sizer->Add(csvfile_label, 0, wxALL); - csvfile_sizer->Add(csvfile_field, 2, wxEXPAND | wxALL); - csvfile_sizer->Add(csvfile_button, 0, wxALL | wxALIGN_CENTER_VERTICAL); - main_sizer->Add(csvfile_sizer, 0, wxEXPAND | wxALL, 2); - wxString csvfile_from_cfg = config_options[L"csv"]; - if (wxFileExists(csvfile_from_cfg)) { - csvfile_path = csvfile_from_cfg; - csvfile_field->ChangeValue(csvfile_path); + tsvfile_button = new wxButton(main_panel, wxID_ANY, wxT("Select")); + main_sizer->Add(tsvfile_label, 0, wxALL); + tsvfile_sizer->Add(tsvfile_field, 2, wxEXPAND | wxALL); + tsvfile_sizer->Add(tsvfile_button, 0, wxALL | wxALIGN_CENTER_VERTICAL); + main_sizer->Add(tsvfile_sizer, 0, wxEXPAND | wxALL, 2); + wxString tsvfile_from_cfg = config_options["tsv"]; + if (wxFileExists(tsvfile_from_cfg)) { + tsvfile_path = tsvfile_from_cfg; + tsvfile_field->ChangeValue(tsvfile_path); } fontsel_sizer = new wxBoxSizer(wxHORIZONTAL); @@ -75,7 +81,7 @@ TranscodeFrame::TranscodeFrame(): fontsel_field = new wxTextCtrl(main_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCB_READONLY); - fontsel_name = config_options[L"font"]; + fontsel_name = config_options["font"]; if (fontsel_name.length() > 0) fontsel_field->ChangeValue(fontsel_name); fontsel_button = new wxButton(main_panel, wxID_ANY, wxT("Select")); @@ -85,7 +91,7 @@ TranscodeFrame::TranscodeFrame(): main_sizer->Add(fontsel_sizer, 0, wxEXPAND | wxALL, 2); infile_button->Bind(wxEVT_BUTTON, &TranscodeFrame::SelectDoc, this); - csvfile_button->Bind(wxEVT_BUTTON, &TranscodeFrame::SelectCSV, this); + tsvfile_button->Bind(wxEVT_BUTTON, &TranscodeFrame::SelectTSV, this); fontsel_button->Bind(wxEVT_BUTTON, &TranscodeFrame::DoFontDialog, this); check_greek = new wxCheckBox(main_panel, wxID_ANY, @@ -139,14 +145,14 @@ void TranscodeFrame::Reset(wxCommandEvent& WXUNUSED(event)) status_messages->Clear(); infile_field->Clear(); - config_options[L"in"] = L""; + config_options["in"] = ""; infile_path.Clear(); // wxString - csvfile_field->Clear(); - csvfile_path.Clear(); // wxString - config_options[L"csv"] = L""; + tsvfile_field->Clear(); + tsvfile_path.Clear(); // wxString + config_options["tsv"] = ""; fontsel_field->Clear(); fontsel_name.clear(); // wstring - config_options[L"font"] = L""; + config_options["font"] = ""; write_config_file(config_filepath, config_options); } @@ -161,31 +167,31 @@ void TranscodeFrame::SelectDoc(wxCommandEvent& WXUNUSED(event)) if (docx_dialog.ShowModal() == wxID_OK) { infile_path = docx_dialog.GetPath(); infile_field->ChangeValue(infile_path); - config_options[L"in"] = infile_path; + config_options["in"] = infile_path; write_config_file(config_filepath, config_options); } - else if ( !(csvfile_path.length() > 0 - && !wxFileExists(csvfile_path)) ) { + else if ( !(tsvfile_path.length() > 0 + && !wxFileExists(tsvfile_path)) ) { wxMessageBox(wxT("Please select a valid file!"), wxT("Error"), wxOK | wxICON_ERROR); } } -void TranscodeFrame::SelectCSV(wxCommandEvent& WXUNUSED(event)) +void TranscodeFrame::SelectTSV(wxCommandEvent& WXUNUSED(event)) { - wxFileDialog csv_dialog(this, wxT("Select Character Table File"), + wxFileDialog tsv_dialog(this, wxT("Select Character Table File"), wxEmptyString, wxEmptyString, "Tab-Separated Data (*.tsv)|*.tsv", wxFD_OPEN | wxFD_FILE_MUST_EXIST); - if (csv_dialog.ShowModal() == wxID_OK) { - csvfile_path = csv_dialog.GetPath(); - csvfile_field->ChangeValue(csvfile_path); - config_options[L"csv"] = csvfile_path; + if (tsv_dialog.ShowModal() == wxID_OK) { + tsvfile_path = tsv_dialog.GetPath(); + tsvfile_field->ChangeValue(tsvfile_path); + config_options["tsv"] = tsvfile_path; write_config_file(config_filepath, config_options); } - else if ( !(csvfile_path.length() > 0 - && wxFileExists(csvfile_path)) ) { + else if ( !(tsvfile_path.length() > 0 + && wxFileExists(tsvfile_path)) ) { wxMessageBox(wxT("Please select a valid file!"), wxT("Error"), wxOK | wxICON_ERROR); } @@ -244,7 +250,7 @@ void TranscodeFrame::DoFontDialog(wxCommandEvent& WXUNUSED(event)) fontsel_name = font_chosen.GetFaceName(); fontsel_field->ChangeValue(fontsel_name); } - config_options[L"font"] = fontsel_name; + config_options["font"] = fontsel_name; write_config_file(config_filepath, config_options); } @@ -252,10 +258,10 @@ void TranscodeFrame::ChkGrk(wxCommandEvent& WXUNUSED(event)) { if (check_greek->GetValue()) { config_params.do_greek = true; - config_options[L"greek"] = L"1"; + config_options["greek"] = "1"; } else { config_params.do_greek = false; - config_options[L"greek"] = L"0"; + config_options["greek"] = "0"; } write_config_file(config_filepath, config_options); @@ -265,10 +271,10 @@ void TranscodeFrame::ChkFontSel(wxCommandEvent& WXUNUSED(event)) { if (check_fontsel->GetValue()) { config_params.do_font_select = true; - config_options[L"fontsel"] = L"1"; + config_options["fontsel"] = "1"; } else { config_params.do_font_select = false; - config_options[L"fontsel"] = L"0"; + config_options["fontsel"] = "0"; } write_config_file(config_filepath, config_options); @@ -335,7 +341,7 @@ void TranscodeFrame::Transcode(wxCommandEvent& WXUNUSED(event)) cerr.rdbuf(cout.rdbuf()); wxStreamToTextRedirector redirect(status_messages); - if ( !(csvfile_path.length() > 0 && infile_path.length() > 0 + if ( !(tsvfile_path.length() > 0 && infile_path.length() > 0 && fontsel_name.length() > 0) ) { wxMessageBox(wxT("Please select input file, character table, and font!"), wxT("Error"), wxOK | wxICON_ERROR); @@ -357,7 +363,7 @@ void TranscodeFrame::Transcode(wxCommandEvent& WXUNUSED(event)) cout << "Processing file " << infile_path << endl; - TranscodeFrame::LoadCharmap(csvfile_path, L'\t', char_map, utf_chars); + TranscodeFrame::LoadCharmap(tsvfile_path, L'\t', char_map, utf_chars); wxString tempdir = wxFileName::GetTempDir(); wxString temp_path = tempdir + path_separator + random_anum_string(6); @@ -400,12 +406,13 @@ void TranscodeFrame::Transcode(wxCommandEvent& WXUNUSED(event)) for (const auto& convfile: convfiles) { if (!wxFileExists(convfile)) continue; cout << "Processing XML source file: " << convfile << endl; - process_xml(convfile, fontsel_name, doc_fonts_sel, doc_encs, + process_xml(convfile, fontsel_name.ToStdWstring(), + doc_fonts_sel, doc_encs, char_map, utf_chars, default_paragraph_font, config_params.do_greek); } - update_default_pfont(styles_xmlfile, fontsel_name, doc_fonts); + update_default_pfont(styles_xmlfile, fontsel_name.ToStdWstring(), doc_fonts); cout << "Conversion completed!" << endl; |
