| 542 | } |
| 543 | |
| 544 | void Project::SaveOGRDataSource() |
| 545 | { |
| 546 | wxLogMessage("Project::SaveOGRDataSource()"); |
| 547 | // This function will only be called to save file or directory (OGR) |
| 548 | wxString tmp_prefix = "GdaTmp_"; |
| 549 | wxArrayString all_tmp_files; |
| 550 | |
| 551 | try{ |
| 552 | bool is_update = false; |
| 553 | |
| 554 | // save to a new tmp file(s) to backup original file(s) |
| 555 | wxString ds_name = datasource->GetOGRConnectStr(); |
| 556 | wxFileName fn(ds_name); |
| 557 | wxString tmp_ds_name = ds_name; |
| 558 | if (wxFileExists(ds_name) && fn.GetExt().CmpNoCase("sqlite")!=0) { |
| 559 | // for existing sqlite file, we add or replace layer |
| 560 | tmp_ds_name = fn.GetPathWithSep()+tmp_prefix+fn.GetFullName(); |
| 561 | if ( wxFileExists(tmp_ds_name) ) { |
| 562 | wxRemoveFile(tmp_ds_name); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | // special cases that saves by update original datasource |
| 567 | if ( fn.GetExt().CmpNoCase("sqlite")==0 ) { |
| 568 | is_update = true; |
| 569 | } |
| 570 | |
| 571 | SaveDataSourceAs(tmp_ds_name, is_update); |
| 572 | |
| 573 | // replace old file with tmp files, then delete tmp files |
| 574 | if (tmp_ds_name!=ds_name && wxFileExists(tmp_ds_name)) { |
| 575 | wxString tmp_name = fn.GetName(); |
| 576 | wxString dirname = fn.GetPath(); |
| 577 | wxString filename; |
| 578 | |
| 579 | wxDir wdir; |
| 580 | |
| 581 | if ( wdir.Open( dirname ) ) |
| 582 | { |
| 583 | bool cont = wdir.GetFirst(&filename); |
| 584 | while ( cont ) |
| 585 | { |
| 586 | if (filename.Contains(tmp_prefix)) { |
| 587 | wxString path = dirname; |
| 588 | path << wxFileName::GetPathSeparator() << filename; |
| 589 | all_tmp_files.push_back(path); |
| 590 | } |
| 591 | cont = wdir.GetNext(&filename); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | for (size_t i=0; i< all_tmp_files.size(); i++) { |
| 596 | wxString orig_fname = all_tmp_files[i]; |
| 597 | orig_fname.Replace(tmp_prefix, ""); |
| 598 | wxCopyFile(all_tmp_files[i], orig_fname); |
| 599 | wxRemoveFile(all_tmp_files[i]); |
| 600 | } |
| 601 | } |
nothing calls this directly
no test coverage detected