Exemplo n.º 1
0
//---------------------------------------------------------------------------
DWORD __fastcall TFileBuffer::ReadStream(TStream * Stream, const DWORD Len, bool ForceLen)
{
  DWORD Result;
  try
  {
    Size = Position + Len;
    // C++5
    // FMemory->SetSize(FMemory->Position + Len);
    if (ForceLen)
    {
      Stream->ReadBuffer(Data + Position, Len);
      Result = Len;
    }
    else
    {
      Result = Stream->Read(Data + Position, Len);
    }
    if (Result != Len)
    {
      Size = Size - Len + Result;
    }
    FMemory->Seek(Len, soCurrent);
  }
  catch(EReadError &)
  {
    RaiseLastOSError();
  }
  return Result;
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------
bool Win32Check(bool RetVal)
{
  if (!RetVal)
  {
    RaiseLastOSError();
  }
  return RetVal;
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------
int __fastcall TSafeHandleStream::Write(const void * Buffer, int Count)
{
  int Result = FileWrite(FHandle, Buffer, Count);
  if (Result == -1)
  {
    RaiseLastOSError();
  }
  return Result;
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
int __fastcall TSafeHandleStream::Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count)
{
  FAIL; // untested
  int Result = FileWrite(FHandle, Buffer, Offset, Count);
  if (Result == -1)
  {
    RaiseLastOSError();
  }
  return Result;
}
Exemplo n.º 5
0
//---------------------------------------------------------------------------
void __fastcall TFileBuffer::WriteToStream(TStream * Stream, const DWORD Len)
{
  try
  {
    Stream->WriteBuffer(Data + Position, Len);
    FMemory->Seek(Len, soCurrent);
  }
  catch(EWriteError &)
  {
    RaiseLastOSError();
  }
}
Exemplo n.º 6
0
// Read VERSIONINFO data from the file referred to
// by the "FileName" property.
void __fastcall TVersionInfo::ReadVersionInfoFromFile(void)
{
  UnicodeString VersionInfoFileName;
  DWORD FileVersionInfoSize;
  DWORD OldErrorMode;
  DWORD LastErrorCode;
  DWORD ApiResult;
  DWORD DummyDWORD;

  if (FFileName.Length() == 0)
  {
    // No file name is defined
	// -> current binary is VERSIONINFO container.
    VersionInfoFileName = Application->ExeName;

    // If there is no application ExeName
    // we are inside a DLL. Query the DLL.
    if (VersionInfoFileName.Length() == 0)
	  VersionInfoFileName = GetCurrentModuleFileName();
  }
  else
  {
    // Use the pre-defined file name.
    VersionInfoFileName = FFileName;
  }

  // Assume that no VERSIONINFO is present.
  FHasVersionInfo = false;

  ClearVersionInfoData();

  // Setting the error mode guarantees that the
  // pesky "File <this or that> could not be found"
  // dialog is not shown.
  OldErrorMode = SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
  try
  {
    if (!FileExists(VersionInfoFileName))
    {
      return;
    }

    // We only support 32 bit files, so test
    // the EXE file type.
    // Alert: NT 3.x is not supported.
    SHFILEINFO FileInfo;
    ApiResult = SHGetFileInfo(VersionInfoFileName.c_str(), 0, &FileInfo, sizeof(FileInfo), SHGFI_EXETYPE);

    bool IsWin32Application = false;

	// Check for Win32 console application

	IsWin32Application = (LOWORD(ApiResult) == IMAGE_NT_SIGNATURE);

	if (!IsWin32Application)
	{
	  if (LOWORD(ApiResult) == LOWORD(IMAGE_NT_SIGNATURE))
	  {
		if ( (HIWORD(ApiResult) == 0x0400) ||  // 4.0
             (HIWORD(ApiResult) == 0x0305) ||  // 3.5
             (HIWORD(ApiResult) == 0x3000)     // 3.0
            )
        {
          IsWin32Application = true;
        }
      }
    }
    if (!IsWin32Application)
      return;
  }
  __finally
  {
    SetErrorMode(OldErrorMode);
  }

  // Retrieve file version information based upon
  // component properties.
  FileVersionInfoSize = GetFileVersionInfoSize(VersionInfoFileName.c_str(), &DummyDWORD);
  if (FileVersionInfoSize == 0)
  {
    LastErrorCode = GetLastError();

    // So the API call failed.
    // There are a number of reasons for this happening;
    //
    // a) The specified image file did not contain a
    //    resource section: ERROR_RESOURCE_DATA_NOT_FOUND
    //
    // b) The specified resource type cannot be found
    //    in the image file: ERROR_RESOURCE_TYPE_NOT_FOUND
    //
    // c) The specified resource name cannot
    //    be found in the image file: ERROR_RESOURCE_NAME_NOT_FOUND
    //
    // d) The specified resource language ID cannot be found
    //    in the image file: ERROR_RESOURCE_LANG_NOT_FOUND

    switch (LastErrorCode)
    {
      case ERROR_RESOURCE_DATA_NOT_FOUND:
      case ERROR_RESOURCE_TYPE_NOT_FOUND:
      case ERROR_RESOURCE_NAME_NOT_FOUND:
      case ERROR_RESOURCE_LANG_NOT_FOUND:
      {
        // We just ignore foreseeable problems
        // and exit from this routine.
        return;
      }

	  default:
        // We hit none of the known problems, so
		// that's a bit exceptional:
		RaiseLastOSError(LastErrorCode);

	}
  }

  // Zero out all data - and immediately allocate new memory
  // to store the VERSIONINFO data in.
  // Note: FreeVersionInfoMemory() handles the situation where
  //       no memory was allocated gracefully.
  FreeVersionInfoMemory();
  FFileVersionInfoData = new char [FileVersionInfoSize];

  // Get VERSIONINFO data.
  Win32Check( GetFileVersionInfo(VersionInfoFileName.c_str(), 0, FileVersionInfoSize, FFileVersionInfoData) );

  // Initial processing...
  InitializeFixedFileInfoField();
  InitializeTranslationTable();

  // ...and if we made it down here, we definitely
  // do have VERSIONINFO in that binary.
  FHasVersionInfo = true;
}