Exemplo n.º 1
0
	Bool GetFileSizeTest()
	{
		Bool result = true;
		File* file;

		//File does not exists, GetFileSize returns 0
		File::Delete(_fileName);
		CHECK File::GetFileSize(_fileName) == 0;

		//File exists, but is empty, GetFileSize returns 0
		file = File::Create(_fileName);
		CHECK file->GetFileSize() == 0;
		DeletePtr(file)
		CHECK File::GetFileSize(_fileName) == 0;

		//File exists, and is not empty, GetFileSize returns size
		file = File::Open(_fileName);
		file->Write((VoidPtr)_fileName, 5);
		CHECK file->GetFileSize() == 5;
		DeletePtr(file)
		CHECK File::GetFileSize(_fileName) == 5;

		File::Delete(_fileName);

		return result;
	}
Exemplo n.º 2
0
	Bool OpenReadOnlyTest()
	{
		Bool result = true;
		File* file;
		String text;
		UInt fileSize;

		//File does not exists, open it and it will fail
		File::Delete(_fileName);
		file = File::OpenReadOnly(_fileName);
		CHECK file == 0;

		//File exists, open it and it will work, write to it and it will fail
		CHECK (file = File::Create(_fileName));
		file->Write((VoidPtr)_fileName, String::CStrByteSize(_fileName));
		DeletePtr(file);
		CHECK (file = File::OpenReadOnly(_fileName));
		fileSize = ToUInt(file->GetFileSize());
		text.Reserve(fileSize / sizeof(TChar));
		file->Read(text.DrivePointer(fileSize / sizeof(TChar)), fileSize);
		CHECK text == _fileName;
		DeletePtr(file);

		File::Delete(_fileName);

		return result;
	}
Exemplo n.º 3
0
		Bool TextFile::ReadAll(CStr fileName, String& text, Exception* out_ex)
		{
			ASSERT_PARAMETER(fileName);
			Bool result = false;

			File* file = File::Open(fileName, File::Disposition::OpenExisting, File::Access::AccessRead, File::Flags::ShareRead | File::Flags::OptimizeForSequentialAccess, out_ex);
			if(file)
			{
				UInt fileSize = ToUInt(file->GetFileSize());
				UInt length = fileSize / sizeof(TChar);

				//If fileSize is odd then +1 will compensate the division rounding
				if(fileSize % 2)
					++fileSize;

				text.Reserve(length);

				TChar* buffer = text.DrivePointer(length);
				result = file->Read(buffer, fileSize);
				GALATEA_DELETE_PTR(file);

				if(!result)
				{
					text.Clear();
					text.Shrink();
				}
			}

			return result;
		}
Exemplo n.º 4
0
	Bool CreateTest()
	{
		Bool result = true;
		File* file;

		//File does not exists, create it and size will be 0 and SeekPos will be 0
		File::Delete(_fileName);
		CHECK (file = File::Create(_fileName));
		CHECK file->GetFileSize() == 0;
		CHECK file->GetSeekPos() == 0;
		DeletePtr(file);

		//File exists, create it and it will be truncated and SeekPos will be 0
		CHECK (file = File::Create(_fileName));
		CHECK file->GetFileSize() == 0;
		CHECK file->GetSeekPos() == 0;
		DeletePtr(file);

		File::Delete(_fileName);

		return result;
	}
Exemplo n.º 5
0
WaveData* WaveData::Create(CStr filename)
{
    File* file;
    ASSERT(file = File::Open(filename, File::Disposition::OpenExisting, File::Access::AccessRead, File::Flags::ShareRead));

    auto buffer_size = file->GetFileSize();
    auto buffer = Memory::Alloc(buffer_size);

    ASSERT(file->Read(buffer, buffer_size));
    delete file;

    return Create(buffer, buffer_size);
    Memory::Free(buffer);
}
Exemplo n.º 6
0
		String TextFile::ReadAll(CStr fileName)
		{
			Assert(fileName);
			File* file;
			String text;
			UInt fileSize;
			UInt length;
			TChar* buffer;

			file = File::OpenReadOnly(fileName);
			if(file)
			{
				fileSize = ToUInt(file->GetFileSize());
				length = fileSize / sizeof(TChar);
				text.Reserve(length);
				buffer = text.DrivePointer(length);
				file->Read(buffer, fileSize);
				DeletePtr(file);
			}

			return text;
		}