bool COptionsPageEditAssociations::Validate() { wxString associations = GetText(XRCID("ID_ASSOCIATIONS")) + _T("\n"); associations.Replace(_T("\r"), _T("")); int pos; while ((pos = associations.Find('\n')) != -1) { wxString assoc = associations.Left(pos); associations = associations.Mid(pos + 1); if (assoc == _T("")) continue; wxString command; if (!UnquoteCommand(assoc, command)) return DisplayError(_T("ID_ASSOCIATIONS"), _("Improperly quoted association.")); if (assoc == _T("")) return DisplayError(_T("ID_ASSOCIATIONS"), _("Empty file extension.")); wxString args; if (!UnquoteCommand(command, args)) return DisplayError(_T("ID_ASSOCIATIONS"), _("Improperly quoted association.")); if (command == _T("")) return DisplayError(_T("ID_ASSOCIATIONS"), _("Empty command.")); if (!ProgramExists(command)) { wxString error = _("Associated program not found:"); error += '\n'; error += command; return DisplayError(_T("ID_ASSOCIATIONS"), error); } } return true; }
bool COptionsPageEdit::Validate() { bool failure = false; const bool custom = GetRCheck(XRCID("ID_DEFAULT_CUSTOM")); wxString editor; if (custom) { editor = GetText(XRCID("ID_EDITOR")); editor.Trim(true); editor.Trim(false); SetText(XRCID("EDITOR"), editor, failure); if (editor != _T("")) { wxString args; if (!UnquoteCommand(editor, args)) return DisplayError(_T("ID_EDITOR"), _("Default editor not properly quoted.")); if (editor == _T("")) return DisplayError(_T("ID_EDITOR"), _("Empty quoted string.")); if (!ProgramExists(editor)) return DisplayError(_T("ID_EDITOR"), _("The file selected as default editor does not exist.")); } } if (GetRCheck(XRCID("ID_USEDEFAULT"))) { if (GetRCheck(XRCID("ID_DEFAULT_NONE")) || (custom && editor.empty())) { return DisplayError(_T("ID_EDITOR"), _("A default editor needs to be set.")); } } return true; }
wxString GetSystemOpenCommand(wxString file, bool &program_exists) { wxFileName fn(file); const wxString& ext = fn.GetExt(); if (ext == _T("")) return _T(""); for (;;) { wxFileType* pType = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); if (!pType) return _T(""); wxString cmd; if (!pType->GetOpenCommand(&cmd, wxFileType::MessageParameters(file))) { delete pType; return _T(""); } delete pType; if (cmd.empty()) return wxEmptyString; program_exists = false; wxString editor; bool is_dde = false; #ifdef __WXMSW__ if (cmd.Left(7) == _T("WX_DDE#")) { // See wxWidget's wxExecute in src/msw/utilsexc.cpp // WX_DDE#<command>#DDE_SERVER#DDE_TOPIC#DDE_COMMAND editor = cmd.Mid(7); int pos = editor.Find('#'); if (pos < 1) return cmd; editor = editor.Left(pos); is_dde = true; } else #endif { editor = cmd; } wxString args; if (!UnquoteCommand(editor, args, is_dde) || editor.empty()) return cmd; if (!PathExpand(editor)) return cmd; if (ProgramExists(editor)) program_exists = true; #ifdef __WXGTK__ int pos = args.Find(file); if (pos != -1 && file.Find(' ') != -1 && file[0] != '\'' && file[0] != '"') { // Might need to quote filename, wxWidgets doesn't do it if ((!pos || (args[pos - 1] != '\'' && args[pos - 1] != '"')) && args[pos + file.Length()] != '\'' && args[pos + file.Length()] != '"') { // Filename in command arguments isn't quoted. Repeat with quoted filename file = _T("\"") + file + _T("\""); continue; } } #endif return cmd; } return wxEmptyString; }