// Display disc space used by modules in the current project
/*
*/
pragma runLim, 0
const string DATA_DIRECTORY_PATH = "E:\\v6data"
const int BLOCK_SIZE = 4096
Skip moduleSkip = null
Skip directorySkip = null
Project currProj = null
/******************************************************************************
fillModuleList
fills a skip list with all formal modules in the current project,
indexed by the uniqueID of the module.
******************************************************************************/
void fillModuleList(Project p)
{
Item itm
string mName = ""
for itm in p do
{
if (null itm) continue
if (isDeleted(itm)) continue
if (type (itm) == "Formal")
{
put(moduleSkip, uniqueID(itm), fullName(itm))
}
}
//print("Modules in project " fullName(p) ":\n")
//for mName in moduleSkip do
//{
// print((string key moduleSkip) " " mName "\n")
//}
}
/******************************************************************************
isDirectory
Returns true if string parameter is a valid directory
******************************************************************************/
bool isDirectory(string dn)
{
Stat s = create dn
if (null s) return false
if (directory s)
{
delete s
return true
}
delete s
return false
}
/******************************************************************************
getFileSize
returns the size (in bytes) of a file. note that files smaller than
the block size on the disc still take up a whole block.
******************************************************************************/
int getFileSize(string fn)
{
int fSize = 0
Stat s = create fn
if (null s) return(0)
fSize = size(s)
if (fSize < BLOCK_SIZE) fSize = BLOCK_SIZE
delete s
return(fSize)
}
/******************************************************************************
getDirectorySize
returns the disc space consumed by a directory (in bytes)
******************************************************************************/
int getDirectorySize(string dName)
{
string strFile = ""
string fullPathName = ""
int dSize = 0
for strFile in directory dName do
{
if (strFile[0] == '.') continue
fullPathName = dName "\\" strFile
if (isDirectory(fullPathName))
{
dSize += getDirectorySize(fullPathName)
}
else
{
dSize += getFileSize(fullPathName)
}
}
return(dSize)
}
/******************************************************************************
fillDirectoryList
fills a skip list with directories corresponding to modules.
i.e. of the form "m00000000.mod", where "00000000" is the uniqueID of
the module and is used as the key so to match the module skip list.
******************************************************************************/
void fillDirectoryList(string dirPath)
{
string strFile = ""
string fullPathName = ""
for strFile in directory dirPath do
{
if (strFile[0] == '.') continue // don't want to scan myself or parent!
fullPathName = dirPath "\\" strFile
if (isDirectory(fullPathName))
{
if ((length(strFile) == 13) && (strFile[0] == 'm') && (strFile[9:12] == ".mod"))
{
put(directorySkip, strFile[1:8], fullPathName)
}
fillDirectoryList(fullPathName)
}
}
}
/******************************************************************************
getModuleSizes
loops through a list of formal modules.
for each module, finds the corresponding directory path from the
directory skip list and then gets the size of that module on disc.
******************************************************************************/
void getModuleSizes()
{
string mString = ""
string dirName = ""
string modID = ""
int dirSize = 0
int projectSize = 0
for mString in moduleSkip do
{
modID = (string key moduleSkip)
//print(mString "\n")
if (find(directorySkip, modID, dirName))
{
delete(directorySkip, modID)
dirSize = getDirectorySize(dirName)
projectSize += dirSize
print("Module Size=" dirSize " ID='" modID "' Name='" mString "'\n")
}
}
print("Project Size=" projectSize " ID='" uniqueID(currProj) "' Name='" fullName(currProj) "'\n")
}
/******************************************************************************
MAIN
******************************************************************************/
currProj = current Project
if (null currProj)
{
infoBox("No current Project")
halt
}
if (!confirm("Calculate size on disc of current project\nThis may take some time\nDo you wish to continue?"))
{
halt
}
moduleSkip = createString
directorySkip = createString
fillModuleList(currProj)
fillDirectoryList(DATA_DIRECTORY_PATH)
getModuleSizes()
//string s = ""
//for s in directorySkip do
//{
// print((string key directorySkip) " " s "\n")
//}
delete(moduleSkip)
delete(directorySkip)
sitemap