MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / sValidateStagedFileDialogPaths

Function sValidateStagedFileDialogPaths

source/MRViewer/MRFileDialog.cpp:398–432  ·  view source on GitHub ↗

Validate paths staged by `MR::UI::TestEngine::stageFileDialogPaths` against the dialog's `Parameters`. Empty error means OK. Rules: - paths must be non-empty. - if !multiselect: exactly one path. - saveDialog: target is always a file (no save-folder API). Skip existence check (file may be brand-new), but reject paths that already exist as a directory. - else folderDialog: each path must be an exis

Source from the content-addressed store, hash-verified

396// - else folderDialog: each path must be an existing directory.
397// - else (open file): each path must be an existing regular file.
398MR::Expected<void> sValidateStagedFileDialogPaths(
399 const std::vector<std::filesystem::path>& paths,
400 const MR::FileDialog::Parameters& parameters )
401{
402 if ( paths.empty() )
403 return MR::unexpected( std::string( "no paths were staged" ) );
404
405 if ( !parameters.multiselect && paths.size() > 1 )
406 return MR::unexpected( fmt::format( "dialog expects a single path but {} were staged", paths.size() ) );
407
408 if ( parameters.saveDialog )
409 {
410 std::error_code ec;
411 if ( std::filesystem::is_directory( paths[0], ec ) )
412 return MR::unexpected( fmt::format(
413 "save target '{}' exists and is a directory, expected a file path",
414 MR::utf8string( paths[0] ) ) );
415 return {};
416 }
417
418 for ( const auto& p : paths )
419 {
420 std::error_code ec;
421 const bool ok = parameters.folderDialog
422 ? std::filesystem::is_directory( p, ec )
423 : std::filesystem::is_regular_file( p, ec );
424 if ( !ok )
425 {
426 return MR::unexpected( fmt::format( "staged path '{}' is not an existing {}",
427 MR::utf8string( p ),
428 parameters.folderDialog ? "directory" : "file" ) );
429 }
430 }
431 return {};
432}
433
434std::vector<std::filesystem::path> runDialog( const MR::FileDialog::Parameters& parameters )
435{

Callers 1

runDialogFunction · 0.85

Calls 4

utf8stringFunction · 0.85
unexpectedFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected