diff --git a/Units/Misc/uMisc.pas b/Units/Misc/uMisc.pas index efd9b6f..eb41c48 100644 --- a/Units/Misc/uMisc.pas +++ b/Units/Misc/uMisc.pas @@ -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; @@ -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; diff --git a/Units/uSelectCompilerVersion.pas b/Units/uSelectCompilerVersion.pas index 4f39b55..88253f2 100644 --- a/Units/uSelectCompilerVersion.pas +++ b/Units/uSelectCompilerVersion.pas @@ -115,7 +115,7 @@ procedure TFrmSelCompilerVer.ListViewIDEsSelectItem(Sender: TObject; procedure TFrmSelCompilerVer.LoadInstalledVersions; var - item: TListItem; + LItem: TListItem; DelphiComp: TDelphiVersions; BorlandCppComp: TBorlandCppVersions; CSharpComp : TDotNetVersions; @@ -129,24 +129,6 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions; LVSIDEList : TObjectList; 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 @@ -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; @@ -195,14 +177,14 @@ 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; @@ -210,8 +192,21 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions; 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 @@ -219,14 +214,14 @@ procedure TFrmSelCompilerVer.LoadInstalledVersions; 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; @@ -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 @@ -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; @@ -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 @@ -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; diff --git a/Units/uVisualStudio.pas b/Units/uVisualStudio.pas index a431e32..d3664d6 100644 --- a/Units/uVisualStudio.pas +++ b/Units/uVisualStudio.pas @@ -33,17 +33,17 @@ interface type TVSVersion = ( - vs2005, //8.0 - vs2008, //9.0 - vs2010, //10.0 - vs2012, //11.0 - vs2013, //12.0 - vs2015 //14.0 + vs2005, //8.0 'Visual Studio 2005', + vs2008, //9.0 'Visual Studio 2008', + vs2010, //10.0 'Visual Studio 2010', + vs2012, //11.0 'Visual Studio 2012', + vs2013, //12.0 'Visual Studio 2013', + vs2015 //14.0 'Visual Studio 2015' ); - TVisualStudioInfo = class - private + TVisualStudioInfo = class + private FIDEFileName: string; FCompilerFileName: string; FCppCompiler: string; @@ -57,7 +57,10 @@ TVisualStudioInfo = class property CppCompiler : string read FCppCompiler write FCppCompiler; property Version : TVSVersion read FVSVersion write FVSVersion; property BaseRegistryKey : string read FBaseRegistryKey write FBaseRegistryKey; - end; + function CSharpInstalled : Boolean; + function CPPInstalled : Boolean; + end; + function GetVSIDEList : TObjectList; function CreateVsProject(const FileName, Path, ProjectTemplate: string; var NewFileName: string): boolean; @@ -79,14 +82,14 @@ implementation const - VSVersionsNames: array[TVSVersion] of string = ( - 'Visual Studio 2005', - 'Visual Studio 2008', - 'Visual Studio 2010', - 'Visual Studio 2012', - 'Visual Studio 2013', - 'Visual Studio 2015' - ); +// VSVersionsNames: array[TVSVersion] of string = ( +// 'Visual Studio 2005', +// 'Visual Studio 2008', +// 'Visual Studio 2010', +// 'Visual Studio 2012', +// 'Visual Studio 2013', +// 'Visual Studio 2015' +// ); VSRegBasePathsx86: array[TVSVersion] of string = ( '\SOFTWARE\Microsoft\VisualStudio\8.0\', @@ -107,35 +110,10 @@ implementation ); + VSKeyInstalled = 'Setup\VS'; + VSKeyCSharpInstalled = 'Languages\Language Services\CSharp'; + VSKeyCPPInstalled = 'InstalledProducts\Microsoft Visual C++'; - VSRegPathsx86: array[TVSVersion] of string = ( - '\SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS', - '\SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VS', - '\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VS', - '\SOFTWARE\Microsoft\VisualStudio\11.0\Setup\VS', - '\SOFTWARE\Microsoft\VisualStudio\12.0\Setup\VS', - '\SOFTWARE\Microsoft\VisualStudio\14.0\Setup\VS' - ); - - VSRegPathsx64: array[TVSVersion] of string = ( - '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\8.0\Setup\VS', - '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VS', - '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Setup\VS', - '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\Setup\VS', - '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0\Setup\VS', - '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\Setup\VS' - ); - - -const - VS14x64RegEntry = '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\Setup\VS'; - VS14x86RegEntry = '\SOFTWARE\Microsoft\VisualStudio\14.0\Setup\VS'; - VS11x64RegEntry = '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\Setup\VS'; - VS11x86RegEntry = '\SOFTWARE\Microsoft\VisualStudio\11.0\Setup\VS'; - VS2010x64RegEntry = '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Setup\VS'; - VS2010x86RegEntry = '\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VS'; - VS2008x64RegEntry = '\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VS'; - VS2008x86RegEntry = '\SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VS'; var VSIDEList : TObjectList; @@ -237,22 +215,23 @@ procedure LoadVSIDEList; for LVSVersion := Low(TVSVersion) to High(TVSVersion) do begin FileName := ''; + if LWow64 then - Found := RegKeyExists(VSRegPathsx64[LVSVersion], HKEY_LOCAL_MACHINE) + Found := RegKeyExists(VSRegBasePathsx64[LVSVersion] + VSKeyInstalled, HKEY_LOCAL_MACHINE) else - Found := RegKeyExists(VSRegPathsx86[LVSVersion], HKEY_LOCAL_MACHINE); + Found := RegKeyExists(VSRegBasePathsx86[LVSVersion] + VSKeyInstalled, HKEY_LOCAL_MACHINE); if Found and LWow64 then - Found := RegReadStr(VSRegPathsx64[LVSVersion], 'EnvironmentPath', FileName, HKEY_LOCAL_MACHINE) and FileExists(FileName) + Found := RegReadStr(VSRegBasePathsx64[LVSVersion]+ VSKeyInstalled, 'EnvironmentPath', FileName, HKEY_LOCAL_MACHINE) and FileExists(FileName) else - Found := RegReadStr(VSRegPathsx86[LVSVersion], 'EnvironmentPath', FileName, HKEY_LOCAL_MACHINE) and FileExists(FileName); + Found := RegReadStr(VSRegBasePathsx86[LVSVersion]+ VSKeyInstalled, 'EnvironmentPath', FileName, HKEY_LOCAL_MACHINE) and FileExists(FileName); if Found then begin LVisualStudioInfo:=TVisualStudioInfo.Create; LVisualStudioInfo.IDEFileName:=Filename; LVisualStudioInfo.Version := LVSVersion; - LVisualStudioInfo.IDEDescription:=VSVersionsNames[LVSVersion]; + LVisualStudioInfo.IDEDescription:= GetFileDescription(FileName); //VSVersionsNames[LVSVersion]; if LWow64 then LVisualStudioInfo.BaseRegistryKey:= VSRegBasePathsx64[LVSVersion] else @@ -266,6 +245,24 @@ procedure LoadVSIDEList; end; +{ TVisualStudioInfo } + +function TVisualStudioInfo.CPPInstalled: Boolean; +begin + if IsWow64 then + Result := RegKeyExists(VSRegBasePathsx64[Version] + VSKeyCPPInstalled, HKEY_LOCAL_MACHINE) + else + Result := RegKeyExists(VSRegBasePathsx86[Version] + VSKeyCPPInstalled, HKEY_LOCAL_MACHINE); +end; + +function TVisualStudioInfo.CSharpInstalled: Boolean; +begin + if IsWow64 then + Result := RegKeyExists(VSRegBasePathsx64[Version] + VSKeyCSharpInstalled, HKEY_LOCAL_MACHINE) + else + Result := RegKeyExists(VSRegBasePathsx86[Version] + VSKeyCSharpInstalled, HKEY_LOCAL_MACHINE); +end; + initialization VSIDEList := TObjectList.Create(True); LoadVSIDEList;