#include <common/diskinfo.hpp>

WORD DiskInfo::getLogicalDrives(Block<String> &driveStrings)const
{
	DWORD driveMask(::GetLogicalDrives());
	BYTE driveChar('A');
	DWORD maskValue(1);

  driveStrings.remove();
	if(!driveMask)return driveMask;
	for(DWORD itemIndex=0;itemIndex<sizeof(DWORD)*8;itemIndex++)
	{
		if(maskValue&driveMask)
		{
			String driveString((char)driveChar);
			driveString+=":\\";
			driveStrings.insert(&driveString);
		}
		maskValue<<=1;
		driveChar++;
	}
	return driveStrings.size();
}

WORD DiskInfo::getFixedLogicalDrives(Block<String> &driveStrings)const
{
	DWORD driveMask(::GetLogicalDrives());
	BYTE driveChar('A');
	DWORD maskValue(1);

  driveStrings.remove();
	if(!driveMask)return driveMask;
	for(DWORD itemIndex=0;itemIndex<sizeof(DWORD)*8;itemIndex++)
	{
		if(maskValue&driveMask)
		{
			String driveString((char)driveChar);
			driveString+=":\\";
			if(DriveFixed==getDriveType())driveStrings.insert(&driveString);
		}
		maskValue<<=1;
		driveChar++;
	}
	return driveStrings.size();
}

DWORD DiskInfo::getCurrentDirectory(String &currentDirectory)const
{
	String currDir;
	DWORD returnCode;

	returnCode=::GetCurrentDirectory(String::MaxString,(LPSTR)currDir);
	currentDirectory=currDir;
	return returnCode;
}

BOOL DiskInfo::copyFile(const String &strExistingFile,const String &strNewFile,BOOL overwrite)
{
  if(strExistingFile.isNull()||strNewFile.isNull())return FALSE;
	return ::CopyFile((String&)strExistingFile,(String&)strNewFile,!overwrite);
}

BOOL DiskInfo::rename(const String &strExistingFileName,const String &strNewFile)
{
  return ::MoveFile(strExistingFileName,strNewFile);
}



