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

Method Compact

src/ProjectFileManager.cpp:1669–1753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1667}
1668
1669void ProjectFileManager::Compact()
1670{
1671 auto &project = mProject;
1672 auto &undoManager = UndoManager::Get(project);
1673 auto &clipboard = Clipboard::Get();
1674 auto &projectFileIO = ProjectFileIO::Get(project);
1675 bool isBatch = project.mBatchMode > 0;
1676
1677 // Purpose of this is to remove the -wal file.
1678 projectFileIO.ReopenProject();
1679
1680 auto savedState = undoManager.GetSavedState();
1681 const auto currentState = undoManager.GetCurrentState();
1682 if (savedState < 0) {
1683 undoManager.StateSaved();
1684 savedState = undoManager.GetSavedState();
1685 if (savedState < 0) {
1686 wxASSERT(false);
1687 savedState = 0;
1688 }
1689 }
1690 const auto least = std::min<size_t>(savedState, currentState);
1691 const auto greatest = std::max<size_t>(savedState, currentState);
1692 std::vector<const TrackList*> trackLists;
1693 auto fn = [&](const UndoStackElem& elem) {
1694 if (auto pTracks = UndoTracks::Find(elem))
1695 trackLists.push_back(pTracks);
1696 };
1697 undoManager.VisitStates(fn, least, 1 + least);
1698 if (least != greatest)
1699 undoManager.VisitStates(fn, greatest, 1 + greatest);
1700
1701 int64_t total = projectFileIO.GetTotalUsage();
1702 int64_t used = projectFileIO.GetCurrentUsage(trackLists);
1703
1704 auto before = wxFileName::GetSize(projectFileIO.GetFileName());
1705
1706 CompactDialog dlg(
1707 XO("Compacting this project will free up disk space by removing unused bytes within the file.\n\n"
1708 "There is %s of free disk space and this project is currently using %s.\n"
1709 "\n"
1710 "If you proceed, the current Undo/Redo History and clipboard contents will be discarded "
1711 "and you will recover approximately %s of disk space.\n"
1712 "\n"
1713 "Do you want to continue?")
1714 .Format(Internat::FormatSize(projectFileIO.GetFreeDiskSpace()),
1715 Internat::FormatSize(before.GetValue()),
1716 Internat::FormatSize(total - used)));
1717 if (isBatch || dlg.ShowModal() == wxYES)
1718 {
1719 // We can remove redo states, if they are after the saved state.
1720 undoManager.RemoveStates(1 + greatest, undoManager.GetNumStates());
1721
1722 // We can remove all states between the current and the last saved.
1723 if (least < greatest)
1724 undoManager.RemoveStates(least + 1, greatest);
1725
1726 // We can remove all states before the current and the last saved.

Callers 3

CompactProjectOnCloseMethod · 0.45
OnCompactMethod · 0.45
OnCompactFunction · 0.45

Calls 15

GetFunction · 0.85
FindFunction · 0.85
AudacityMessageBoxFunction · 0.85
ReopenProjectMethod · 0.80
GetSavedStateMethod · 0.80
GetCurrentStateMethod · 0.80
StateSavedMethod · 0.80
VisitStatesMethod · 0.80
GetTotalUsageMethod · 0.80
GetCurrentUsageMethod · 0.80
GetFreeDiskSpaceMethod · 0.80
RemoveStatesMethod · 0.80

Tested by

no test coverage detected