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

Method LoadProject

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

Source from the content-addressed store, hash-verified

2034}
2035
2036auto ProjectFileIO::LoadProject(const FilePath &fileName, bool ignoreAutosave)
2037 -> std::optional<TentativeConnection>
2038{
2039 auto now = std::chrono::high_resolution_clock::now();
2040
2041 std::optional<TentativeConnection> result{ *this };
2042
2043 bool success = false;
2044
2045 // Open the project file
2046 if (!OpenConnection(fileName))
2047 return {};
2048
2049 int64_t rowId = -1;
2050
2051 bool useAutosave =
2052 !ignoreAutosave &&
2053 GetValue("SELECT ROWID FROM main.autosave WHERE id = 1;", rowId, true);
2054
2055 int64_t rowsCount = 0;
2056 // If we didn't have an autosave doc, load the project doc instead
2057 if (
2058 !useAutosave &&
2059 (!GetValue("SELECT COUNT(1) FROM main.project;", rowsCount, true) || rowsCount == 0))
2060 {
2061 // Missing both the autosave and project docs. This can happen if the
2062 // system were to crash before the first autosave into a temporary file.
2063 // This should be a recoverable scenario.
2064 mRecovered = true;
2065 mModified = true;
2066
2067 return result;
2068 }
2069
2070 if (!useAutosave && !GetValue("SELECT ROWID FROM main.project WHERE id = 1;", rowId, false))
2071 return {};
2072 else
2073 {
2074 // Load 'er up
2075 BufferedProjectBlobStream stream(
2076 DB(), "main", useAutosave ? "autosave" : "project", rowId);
2077
2078 success = ProjectSerializer::Decode(stream, this);
2079
2080 if (!success)
2081 {
2082 SetError(
2083 XO("Unable to parse project information.")
2084 );
2085 return {};
2086 }
2087
2088 // Check for orphans blocks...sets mRecovered if any were deleted
2089
2090 auto blockids = WaveTrackFactory::Get( mProject )
2091 .GetSampleBlockFactory()
2092 ->GetActiveBlockIDs();
2093 if (blockids.size() > 0)

Callers 4

SyncCloudSnapshotMethod · 0.80
ReadProjectFileMethod · 0.80
ImportProjectFunction · 0.80
loadMethod · 0.80

Calls 6

SetErrorFunction · 0.85
GetFunction · 0.85
SetFileNameMethod · 0.80
GetActiveBlockIDsMethod · 0.45
sizeMethod · 0.45
IsSameAsMethod · 0.45

Tested by

no test coverage detected