Audacity  2.2.0
DirManager Class Referencefinal

Creates and manages BlockFile objects. More...

#include <DirManager.h>

Inheritance diagram for DirManager:
XMLTagHandler

Classes

struct  BalanceInfo
 

Public Member Functions

 DirManager ()
 
virtual ~DirManager ()
 
bool SetProject (wxString &newProjPath, wxString &newProjName, const bool bCreate)
 
wxString GetProjectDataDir ()
 
wxString GetProjectName ()
 
wxLongLong GetFreeDiskSpace ()
 
BlockFilePtr NewSimpleBlockFile (samplePtr sampleData, size_t sampleLen, sampleFormat format, bool allowDeferredWrite=false)
 
BlockFilePtr NewAliasBlockFile (const wxString &aliasedFile, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 
BlockFilePtr NewODAliasBlockFile (const wxString &aliasedFile, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 
BlockFilePtr NewODDecodeBlockFile (const wxString &aliasedFile, sampleCount aliasStart, size_t aliasLen, int aliasChannel, int decodeType)
 
bool ContainsBlockFile (const BlockFile *b) const
 Returns true if the blockfile pointed to by b is contained by the DirManager. More...
 
bool ContainsBlockFile (const wxString &filepath) const
 Check for existing using filename using complete filename. More...
 
BlockFilePtr CopyBlockFile (const BlockFilePtr &b)
 
BlockFileLoadBlockFile (const wxChar **attrs, sampleFormat format)
 
void SaveBlockFile (BlockFile *f, int depth, FILE *fp)
 
std::pair< bool, wxString > CopyToNewProjectDirectory (BlockFile *f)
 
bool EnsureSafeFilename (const wxFileName &fName)
 
void SetLoadingTarget (BlockArray *pArray, unsigned idx)
 
void SetLoadingFormat (sampleFormat format)
 
void SetLoadingBlockLength (size_t len)
 
void SetLoadingMaxSamples (size_t max)
 
bool HandleXMLTag (const wxChar *tag, const wxChar **attrs) override
 
XMLTagHandlerHandleXMLChild (const wxChar *WXUNUSED(tag)) override
 
bool AssignFile (wxFileNameWrapper &filename, const wxString &value, bool check)
 
int ProjectFSCK (const bool bForceError, const bool bAutoRecoverMode)
 
void FindMissingAliasedFiles (BlockHash &missingAliasedFileAUFHash, BlockHash &missingAliasedFilePathHash)
 
void FindMissingAUFs (BlockHash &missingAUFHash)
 
void FindMissingAUs (BlockHash &missingAUHash)
 
void FindOrphanBlockFiles (const wxArrayString &filePathArray, wxArrayString &orphanFilePathArray)
 
void RemoveOrphanBlockfiles ()
 
wxString GetDataFilesDir () const
 
void SetLocalTempDir (const wxString &path)
 
void WriteCacheToDisk ()
 
void FillBlockfilesCache ()
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const wxChar *tag)=0
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Static Public Member Functions

static void SetTempDir (const wxString &_temp)
 
static void CleanTempDir ()
 
static void CleanDir (const wxString &path, const wxString &dirSpec, const wxString &fileSpec, const wxString &msg, int flags=0)
 
static void SetDontDeleteTempFiles ()
 

Private Member Functions

wxFileNameWrapper MakeBlockFileName ()
 
wxFileNameWrapper MakeBlockFilePath (const wxString &value)
 
BalanceInfoGetBalanceInfo ()
 
void BalanceInfoDel (const wxString &)
 
void BalanceInfoAdd (const wxString &)
 
void BalanceFileAdd (int)
 
int BalanceMidAdd (int, int)
 

Private Attributes

BlockHash mBlockFileHash
 
struct DirManager::BalanceInfo mBalanceInfo
 
wxString projName
 
wxString projPath
 
wxString projFull
 
wxString lastProject
 
wxArrayString aliasList
 
BlockArraymLoadingTarget
 
unsigned mLoadingTargetIdx
 
sampleFormat mLoadingFormat
 
size_t mLoadingBlockLen
 
size_t mMaxSamples
 
unsigned long mLastBlockFileDestructionCount { 0 }
 
wxString mytemp
 

Static Private Attributes

static wxString globaltemp
 
static int numDirManagers = 0
 
static bool dontDeleteTempFiles = false
 

Friends

class SequenceTest
 

Detailed Description

Creates and manages BlockFile objects.

This class manages the files that a project uses to store most of its data. It creates NEW BlockFile objects, which can be used to store any type of data. BlockFiles support all of the common file operations, but they also support reference counting, so two different parts of a project can point to the same block of data.

For example, a track might contain 10 blocks of data representing its audio. If you copy the last 5 blocks and paste at the end of the file, no NEW blocks need to be created - we just store pointers to NEW ones. When part of a track is deleted, the affected blocks decrement their reference counts, and when they reach zero they are deleted. This same mechanism is also used to implement Undo.

The DirManager, besides mapping filenames to absolute paths, also hashes all of the block names used in a project, so that when reading a project from disk, multiple copies of the same block still get mapped to the same BlockFile object.

The blockfile/directory scheme is rather complicated with two different schemes. The current scheme uses two levels of subdirectories - up to 256 'eXX' and up to 256 'dYY' directories within each of the 'eXX' dirs, where XX and YY are hex chars. In each of the dXX directories there are up to 256 audio files (e.g. .au or .auf). They have a filename scheme of 'eXXYYZZZZ', where XX and YY refers to the subdirectories as above. The 'ZZZZ' component is generated randomly for some reason. The XX and YY components are sequential. DirManager fills up the current dYY subdir until 256 are created, and moves on to the next one.

So for example, the first blockfile created may be 'e00/d00/e0000a23b.au' and the next 'e00/d00/e000015e8.au', and the 257th may be 'e00/d01/e0001f02a.au'. On close the blockfiles that are no longer referenced by the project (edited or deleted) are removed, along with the consequent empty directories.

Constructor & Destructor Documentation

DirManager::~DirManager ( )
virtual

Member Function Documentation

void DirManager::BalanceFileAdd ( int  midkey)
private

References GetBalanceInfo().

Referenced by BalanceInfoAdd(), and MakeBlockFileName().

void DirManager::BalanceInfoAdd ( const wxString &  file)
private
void DirManager::BalanceInfoDel ( const wxString &  file)
private
int DirManager::BalanceMidAdd ( int  topnum,
int  midkey 
)
private

References GetBalanceInfo().

Referenced by BalanceInfoAdd(), and MakeBlockFileName().

void DirManager::CleanDir ( const wxString &  path,
const wxString &  dirSpec,
const wxString &  fileSpec,
const wxString &  msg,
int  flags = 0 
)
static
void DirManager::CleanTempDir ( )
static
bool DirManager::ContainsBlockFile ( const BlockFile b) const

Returns true if the blockfile pointed to by b is contained by the DirManager.

References BlockFile::GetFileName(), and mBlockFileHash.

Referenced by FindOrphanBlockFiles(), and MakeBlockFileName().

bool DirManager::ContainsBlockFile ( const wxString &  filepath) const

Check for existing using filename using complete filename.

References mBlockFileHash.

BlockFilePtr DirManager::CopyBlockFile ( const BlockFilePtr b)
bool DirManager::EnsureSafeFilename ( const wxFileName &  fName)
void DirManager::FillBlockfilesCache ( )
void DirManager::FindMissingAliasedFiles ( BlockHash &  missingAliasedFileAUFHash,
BlockHash &  missingAliasedFilePathHash 
)

References _(), and mBlockFileHash.

Referenced by ProjectFSCK().

void DirManager::FindMissingAUFs ( BlockHash &  missingAUFHash)

References _(), MakeBlockFilePath(), and mBlockFileHash.

Referenced by ProjectFSCK().

void DirManager::FindMissingAUs ( BlockHash &  missingAUHash)

References _(), MakeBlockFilePath(), and mBlockFileHash.

Referenced by ProjectFSCK().

void DirManager::FindOrphanBlockFiles ( const wxArrayString &  filePathArray,
wxArrayString &  orphanFilePathArray 
)
auto DirManager::GetBalanceInfo ( )
private
wxString DirManager::GetDataFilesDir ( ) const

References mytemp, and projFull.

Referenced by MakeBlockFilePath().

wxLongLong DirManager::GetFreeDiskSpace ( )

References mytemp, and projPath.

wxString DirManager::GetProjectName ( )

References projName.

XMLTagHandler* DirManager::HandleXMLChild ( const wxChar *  WXUNUSEDtag)
inlineoverride
BlockFile* DirManager::LoadBlockFile ( const wxChar **  attrs,
sampleFormat  format 
)
wxFileNameWrapper DirManager::MakeBlockFilePath ( const wxString &  value)
private

References _(), and GetDataFilesDir().

Referenced by AssignFile(), FindMissingAUFs(), and FindMissingAUs().

BlockFilePtr DirManager::NewAliasBlockFile ( const wxString &  aliasedFile,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel 
)
BlockFilePtr DirManager::NewODAliasBlockFile ( const wxString &  aliasedFile,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel 
)
BlockFilePtr DirManager::NewODDecodeBlockFile ( const wxString &  aliasedFile,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
int  decodeType 
)
BlockFilePtr DirManager::NewSimpleBlockFile ( samplePtr  sampleData,
size_t  sampleLen,
sampleFormat  format,
bool  allowDeferredWrite = false 
)
void DirManager::RemoveOrphanBlockfiles ( )
void DirManager::SaveBlockFile ( BlockFile f,
int  depth,
FILE *  fp 
)
static void DirManager::SetDontDeleteTempFiles ( )
inlinestatic

Referenced by AudacityApp::OnInit().

void DirManager::SetLoadingBlockLength ( size_t  len)
inline

Referenced by Sequence::HandleXMLTag().

void DirManager::SetLoadingFormat ( sampleFormat  format)
inline

References format.

Referenced by Sequence::HandleXMLChild().

void DirManager::SetLoadingMaxSamples ( size_t  max)
inline

Referenced by Sequence::HandleXMLTag().

void DirManager::SetLoadingTarget ( BlockArray pArray,
unsigned  idx 
)
inline

Referenced by Sequence::HandleXMLTag().

void DirManager::SetLocalTempDir ( const wxString &  path)

References mytemp.

bool DirManager::SetProject ( wxString &  newProjPath,
wxString &  newProjName,
const bool  bCreate 
)
static void DirManager::SetTempDir ( const wxString &  _temp)
inlinestatic
void DirManager::WriteCacheToDisk ( )

Friends And Related Function Documentation

friend class SequenceTest
friend

Member Data Documentation

wxArrayString DirManager::aliasList
private
bool DirManager::dontDeleteTempFiles = false
staticprivate

Referenced by CleanDir().

wxString DirManager::globaltemp
staticprivate

Referenced by CleanTempDir(), and DirManager().

wxString DirManager::lastProject
private
struct DirManager::BalanceInfo DirManager::mBalanceInfo
private

Referenced by BalanceInfoDel(), and DirManager().

unsigned long DirManager::mLastBlockFileDestructionCount { 0 }
private

Referenced by DirManager().

size_t DirManager::mLoadingBlockLen
private

Referenced by HandleXMLTag().

sampleFormat DirManager::mLoadingFormat
private

Referenced by HandleXMLTag().

BlockArray* DirManager::mLoadingTarget
private

Referenced by DirManager(), and HandleXMLTag().

unsigned DirManager::mLoadingTargetIdx
private

Referenced by DirManager(), and HandleXMLTag().

size_t DirManager::mMaxSamples
private

Referenced by DirManager(), and HandleXMLTag().

int DirManager::numDirManagers = 0
staticprivate

Referenced by DirManager(), and ~DirManager().

wxString DirManager::projName
private
wxString DirManager::projPath
private

The documentation for this class was generated from the following files: