MCPcopy Create free account
hub / github.com/audacity/audacity / OpenConnection

Method OpenConnection

libraries/lib-project-file-io/ProjectFileIO.cpp:487–543  ·  view source on GitHub ↗

! @pre *CurConn() does not exist @post *CurConn() exists or return value is false */

Source from the content-addressed store, hash-verified

485 @post *CurConn() exists or return value is false
486 */
487bool ProjectFileIO::OpenConnection(FilePath fileName /* = {} */)
488{
489 auto &curConn = CurrConn();
490 wxASSERT(!curConn);
491 bool isTemp = false;
492
493 if (fileName.empty())
494 {
495 fileName = GetFileName();
496 if (fileName.empty())
497 {
498 fileName = TempDirectory::UnsavedProjectFileName();
499 isTemp = true;
500 }
501 }
502 else
503 {
504 // If this project resides in the temporary directory, then we'll mark it
505 // as temporary.
506 wxFileName temp(TempDirectory::TempDir(), wxT(""));
507 wxFileName file(fileName);
508 file.SetFullName(wxT(""));
509 if (file == temp)
510 {
511 isTemp = true;
512 }
513 }
514
515 // Pass weak_ptr to project into DBConnection constructor
516 curConn = std::make_unique<DBConnection>(
517 mProject.shared_from_this(), mpErrors, [this]{ OnCheckpointFailure(); } );
518 auto rc = curConn->Open(fileName);
519 if (rc != SQLITE_OK)
520 {
521 // Must use SetError() here since we do not have an active DB
522 SetError(
523 XO("Failed to open database file:\n\n%s").Format(fileName),
524 {},
525 rc
526 );
527 curConn.reset();
528 return false;
529 }
530
531 if (!CheckVersion())
532 {
533 CloseConnection();
534 curConn.reset();
535 return false;
536 }
537
538 mTemporary = isTemp;
539
540 SetFileName(fileName);
541
542 return true;
543}
544

Callers

nothing calls this directly

Calls 4

SetErrorFunction · 0.85
emptyMethod · 0.45
OpenMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected