Skip to content

Commit

Permalink
Improved VS detection support for C# and C++
Browse files Browse the repository at this point in the history
  • Loading branch information
RRUZ committed Dec 30, 2015
1 parent bab825e commit 7fe9d34
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 119 deletions.
76 changes: 76 additions & 0 deletions Units/Misc/uMisc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface
procedure MsgInformation(const Msg: string);
function MsgQuestion(const Msg: string):Boolean;
function GetFileVersion(const FileName: string): string;
function GetFileDescription(const FileName: string): string;
function GetTempDirectory: string;
function GetWindowsDirectory : string;
function GetSpecialFolder(const CSIDL: integer) : string;
Expand Down Expand Up @@ -70,6 +71,81 @@ implementation
Vcl.Controls,
Vcl.Dialogs;

type
TEXEVersionData = record
CompanyName,
FileDescription,
FileVersion,
InternalName,
LegalCopyright,
LegalTrademarks,
OriginalFileName,
ProductName,
ProductVersion,
Comments,
PrivateBuild,
SpecialBuild: string;
end;

function GetFileVersionData(const FileName: string): TEXEVersionData;
type
PLandCodepage = ^TLandCodepage;
TLandCodepage = record
wLanguage,
wCodePage: word;
end;
var
langCode : string;
lpdwHandle, lBlock: Cardinal;
pBlock, lplpBuffer: Pointer;
begin
lBlock := GetFileVersionInfoSize(PChar(FileName), lpdwHandle);
if lBlock = 0 then
RaiseLastOSError;
GetMem(pBlock, lBlock);
try
if not GetFileVersionInfo(PChar(FileName), 0, lBlock, pBlock) then
RaiseLastOSError;

if not VerQueryValue(pBlock, '\VarFileInfo\Translation\', lplpBuffer, lBlock) then
RaiseLastOSError;

langCode := Format('%.4x%.4x', [PLandCodepage(lplpBuffer)^.wLanguage, PLandCodepage(lplpBuffer)^.wCodePage]);

if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\CompanyName'), lplpBuffer, lBlock) then
result.CompanyName := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\FileDescription'), lplpBuffer, lBlock) then
result.FileDescription := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\FileVersion'), lplpBuffer, lBlock) then
result.FileVersion := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\InternalName'), lplpBuffer, lBlock) then
result.InternalName := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\LegalCopyright'), lplpBuffer, lBlock) then
result.LegalCopyright := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\LegalTrademarks'), lplpBuffer, lBlock) then
result.LegalTrademarks := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\OriginalFileName'), lplpBuffer, lBlock) then
result.OriginalFileName := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\ProductName'), lplpBuffer, lBlock) then
result.ProductName := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\ProductVersion'), lplpBuffer, lBlock) then
result.ProductVersion := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\Comments'), lplpBuffer, lBlock) then
result.Comments := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\PrivateBuild'), lplpBuffer, lBlock) then
result.PrivateBuild := PChar(lplpBuffer);
if VerQueryValue(pBlock, PChar('\StringFileInfo\' + langCode + '\SpecialBuild'), lplpBuffer, lBlock) then
result.SpecialBuild := PChar(lplpBuffer);
finally
FreeMem(pBlock);
end;
end;

function GetFileDescription(const FileName: string): string;
begin
Result:= GetFileVersionData(FileName).FileDescription;
end;

procedure CheckForUpdates(Silent : Boolean);
var
LBinaryPath, LUpdaterPath : string;
Expand Down
146 changes: 77 additions & 69 deletions Units/uSelectCompilerVersion.pas
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ procedure TFrmSelCompilerVer.ListViewIDEsSelectItem(Sender: TObject;

procedure TFrmSelCompilerVer.LoadInstalledVersions;
var
item: TListItem;
LItem: TListItem;
DelphiComp: TDelphiVersions;
BorlandCppComp: TBorlandCppVersions;
CSharpComp : TDotNetVersions;
Expand All @@ -129,24 +129,6 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
LVSIDEList : TObjectList<TVisualStudioInfo>;
i : Integer;

procedure RegisterVSIDE;
var
i : Integer;
begin
LVSIDEList := GetVSIDEList;
for i:=0 to LVSIDEList.Count-1 do
begin
item := ListViewIDEs.Items.Add;
Filename := LVSIDEList[i].IDEFileName;
item.Caption := LVSIDEList[i].IDEDescription;
item.SubItems.Add(FileName);
item.SubItems.Add(LVSIDEList[i].CompilerFileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(LVSIDEList[i]);
end;
end;

begin
case FLanguageSource of
Expand All @@ -160,25 +142,25 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
if RegReadStr(DelphiRegPaths[DelphiComp],
'App', FileName, HKEY_CURRENT_USER) and FileExists(FileName) then
begin
item := ListViewIDEs.Items.Add;
item.Caption := DelphiVersionsNames[DelphiComp];
item.SubItems.Add(FileName);
item.SubItems.Add(ExtractFilePath(FileName) + 'Dcc32.exe');
LItem := ListViewIDEs.Items.Add;
LItem.Caption := DelphiVersionsNames[DelphiComp];
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(ExtractFilePath(FileName) + 'Dcc32.exe');
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(Ord(Lng_Delphi));
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(Ord(Lng_Delphi));

if (DelphiComp>=DelphiXE2) and FShow64BitsCompiler then
begin
item := ListViewIDEs.Items.Add;
item.Caption := DelphiVersionsNames[DelphiComp] +' 64 Bits Compiler';
item.SubItems.Add(FileName);
item.SubItems.Add(ExtractFilePath(FileName) + 'Dcc64.exe');
LItem := ListViewIDEs.Items.Add;
LItem.Caption := DelphiVersionsNames[DelphiComp] +' 64 Bits Compiler';
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(ExtractFilePath(FileName) + 'Dcc64.exe');
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(Ord(Lng_Delphi));
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(Ord(Lng_Delphi));
end;

end;
Expand All @@ -195,38 +177,51 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
if RegReadStr(BorlandCppRegPaths[BorlandCppComp],
'App', FileName, RootKey) and FileExists(FileName) then
begin
item := ListViewIDEs.Items.Add;
item.Caption := BorlandCppVersionsNames[BorlandCppComp];
item.SubItems.Add(FileName);
item.SubItems.Add(ExtractFilePath(FileName) + 'bcc32.exe');
LItem := ListViewIDEs.Items.Add;
LItem.Caption := BorlandCppVersionsNames[BorlandCppComp];
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(ExtractFilePath(FileName) + 'bcc32.exe');
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(Ord(Lng_BorlandCpp));
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(Ord(Lng_BorlandCpp));
end;
end;

end;

Lng_CSharp:
begin
LVSIDEList:=GetVSIDEList;

RegisterVSIDE;
for i:=0 to LVSIDEList.Count-1 do
if LVSIDEList[i].CSharpInstalled then
begin
LItem := ListViewIDEs.Items.Add;
Filename := LVSIDEList[i].IDEFileName;
LItem.Caption := LVSIDEList[i].IDEDescription;
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(LVSIDEList[i].CompilerFileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(LVSIDEList[i]);
end;

if ShowCompiler then
for CSharpComp :=Low(TDotNetVersions) to High(TDotNetVersions) do
begin
FileName:=IncludeTrailingPathDelimiter(NetFrameworkPath(CSharpComp))+'csc.exe';
if FileExists(FileName) then
begin
item := ListViewIDEs.Items.Add;
item.Caption := DotNetNames[CSharpComp];
item.SubItems.Add(ExtractFilePath(FileName) );
item.SubItems.Add(FileName);
LItem := ListViewIDEs.Items.Add;
LItem.Caption := DotNetNames[CSharpComp];
LItem.SubItems.Add(ExtractFilePath(FileName) );
LItem.SubItems.Add(FileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(Ord(CSharpComp));
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(Ord(CSharpComp));
end;
end;

Expand All @@ -238,20 +233,33 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
if IsLazarusInstalled then
begin
FileName := GetLazarusIDEFileName;
item := ListViewIDEs.Items.Add;
item.Caption := 'Lazarus';
item.SubItems.Add(FileName);
item.SubItems.Add(GetLazarusCompilerFileName);
LItem := ListViewIDEs.Items.Add;
LItem.Caption := 'Lazarus';
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(GetLazarusCompilerFileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(Ord(Lng_FPC));
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(Ord(Lng_FPC));
end;
end;

Lng_VSCpp :
begin
RegisterVSIDE;
LVSIDEList:=GetVSIDEList;
for i:=0 to LVSIDEList.Count-1 do
if LVSIDEList[i].CPPInstalled then
begin
LItem := ListViewIDEs.Items.Add;
Filename := LVSIDEList[i].IDEFileName;
LItem.Caption := LVSIDEList[i].IDEDescription;
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(LVSIDEList[i].CompilerFileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(LVSIDEList[i]);
end;

if ShowCompiler then
begin
Expand All @@ -261,14 +269,14 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
FileName :=LVSIDEList[i].CppCompiler;
if FileExists(FileName) then
begin
item := ListViewIDEs.Items.Add;
item.Caption := 'Microsoft C++ Compiler '+uMisc.GetFileVersion(FileName);
item.SubItems.Add(FileName);
item.SubItems.Add(FileName);
LItem := ListViewIDEs.Items.Add;
LItem.Caption := 'Microsoft C++ Compiler '+uMisc.GetFileVersion(FileName);
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(FileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(LVSIDEList[i]);
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(LVSIDEList[i]);
end;
end;
end;
Expand All @@ -283,15 +291,15 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
if FShowCompiler then
begin
FileName := GetDelphiPrismCompilerFileName;
item := ListViewIDEs.Items.Add;
item.Caption := 'Oxygene';
item.SubItems.Add(FileName);
item.SubItems.Add(FileName);
LItem := ListViewIDEs.Items.Add;
LItem.Caption := 'Oxygene';
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(FileName);
ExtractIconFileToImageList(ImageList1, Filename);
//ExtractIconFileToImageList(ImageList1,ExtractFilePath(ParamStr(0))+'Extras\MonoDevelop.ico');
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(Ord(Lng_Oxygen));
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(Ord(Lng_Oxygen));
end
else
begin
Expand All @@ -317,14 +325,14 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions;
if RegKeyExists(LVSIDEList[i].BaseRegistryKey + 'InstalledProducts\RemObjects Oxygene', HKEY_LOCAL_MACHINE) then
begin
FileName := LVSIDEList[i].IDEFileName;
item := ListViewIDEs.Items.Add;
item.Caption := LVSIDEList[i].IDEDescription;
item.SubItems.Add(FileName);
item.SubItems.Add(GetDelphiPrismCompilerFileName);
LItem := ListViewIDEs.Items.Add;
LItem.Caption := LVSIDEList[i].IDEDescription;
LItem.SubItems.Add(FileName);
LItem.SubItems.Add(GetDelphiPrismCompilerFileName);
ExtractIconFileToImageList(ImageList1, Filename);
ImageIndex := ImageList1.Count - 1;
item.ImageIndex := ImageIndex;
item.Data := Pointer(LVSIDEList[i]);
LItem.ImageIndex := ImageIndex;
LItem.Data := Pointer(LVSIDEList[i]);
end;
end;

Expand Down
Loading

0 comments on commit 7fe9d34

Please sign in to comment.