REVIEW: This function is believed to report an error to the user in all cases of failure. Callers are believed not to need to do so if they receive 'false'. LLL: All failures checks should now be displaying an error.
| 2157 | // of failure. Callers are believed not to need to do so if they receive 'false'. |
| 2158 | // LLL: All failures checks should now be displaying an error. |
| 2159 | bool ProjectFileIO::SaveProject( |
| 2160 | const FilePath &fileName, const TrackList *lastSaved) |
| 2161 | { |
| 2162 | // In the case where we're saving a temporary project to a permanent project, |
| 2163 | // we'll try to simply rename the project to save a bit of time. We then fall |
| 2164 | // through to the normal Save (not SaveAs) processing. |
| 2165 | if (IsTemporary() && mFileName != fileName) |
| 2166 | { |
| 2167 | FilePath savedName = mFileName; |
| 2168 | if (CloseConnection()) |
| 2169 | { |
| 2170 | bool reopened = false; |
| 2171 | bool moved = false; |
| 2172 | if (true == (moved = MoveProject(savedName, fileName))) |
| 2173 | { |
| 2174 | if (OpenConnection(fileName)) |
| 2175 | reopened = true; |
| 2176 | else { |
| 2177 | MoveProject(fileName, savedName); |
| 2178 | moved = false; // No longer moved |
| 2179 | |
| 2180 | reopened = OpenConnection(savedName); |
| 2181 | } |
| 2182 | } |
| 2183 | else { |
| 2184 | // Rename can fail -- if it's to a different device, requiring |
| 2185 | // real copy of contents, which might exhaust space |
| 2186 | reopened = OpenConnection(savedName); |
| 2187 | } |
| 2188 | |
| 2189 | // Warning issued in MoveProject() |
| 2190 | if (reopened && !moved) { |
| 2191 | return false; |
| 2192 | } |
| 2193 | |
| 2194 | if (!reopened) { |
| 2195 | BasicUI::CallAfter([this]{ |
| 2196 | ShowError( {}, |
| 2197 | XO("Warning"), |
| 2198 | XO( |
| 2199 | "The project's database failed to reopen, " |
| 2200 | "possibly because of limited space on the storage device."), |
| 2201 | "Error:_Disk_full_or_not_writable" |
| 2202 | ); |
| 2203 | Publish(ProjectFileIOMessage::ReconnectionFailure); |
| 2204 | }); |
| 2205 | |
| 2206 | return false; |
| 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | // If we're saving to a different file than the current one, then copy the |
| 2212 | // current to the new file and make it the active file. |
| 2213 | if (mFileName != fileName) |
| 2214 | { |
| 2215 | // Do NOT prune here since we need to retain the Undo history |
| 2216 | // after we switch to the new file. |