Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.186 Beiträge
 
Delphi 12 Athens
 
#1

FileInfo (Dateiversion und andere Resourcen)

  Alt 2. Jun 2010, 09:36
Diese "Klasse" ließt Dateiversion, das Kompilierungsdatum und die Versionsresource aus.
Delphi-Quellcode:
// vsLong 1.2.3.4
// vsCompact 1.2-34
// vsShort 1.2
// vsNatural 1.2c if patch=0 then 1.2 | if patch>26 then 1.2.3
// vsNaturalBuild 1.2c (4)
// Prefix v

TVersionStr = (vsLong, vsCompact, vsShort, vsNatural, vsNaturalBuild,
  vsLongPrefix, vsCompactPrefix, vsShortPrefix, vsNaturalPrefix, vsNaturalBuildPrefix);
TVersion = Record
Private
  Function Get(Mode: TVersionStr): String;
Public
  Property asString[Mode: TVersionStr]: String Read Get; Default;
  Case Integer of
    0: (VersionMS, VersionLS: LongWord);
    1: (Minor, Major: Word;
        Build, Patch: Word);
    2: (MinorRelease, MajorRelease: Word;
        BuildNumber, PatchLevel: Word);
End;
TFileFlags = Set of (ffDebug, ffPrerelease, ffPatched, ffPrivateBuild, ffInfoInferred, ffSpecialBuild);
{$MINENUMSIZE 2}
TInfoKeyType = (ktBinary, ktText);
{$MINENUMSIZE 1}
TInfoLanguage = Record
Private
  Function Get(Format: Integer): Word;
Public
  Value: LongWord;

  Property LangID: Word Index $10FFFF Read Get;
  Property MajorLang: Word Index $1003FF Read Get;
  Property SubLang: Word Index $1AFC00 Read Get;

  Property Codepage: Word Index $00FFFF Read Get;
End;
TStringTable = Record
  Key: String;
  Typ: TInfoKeyType;
  Text: String;
End;
TStringFileInfo = Record
  Lang: TInfoLanguage;
  Table: Array of TStringTable;
End;

TFileInfo = Record
Private
  FLang: LangID;
  ...
Public
  FileVersion: TVersion;
  ProductVersion: TVersion;
  FileFlags: TFileFlags;
  FileOS: LongWord; // Windows.VOS_…
  FileType: LongWord; // Windows.VFT_…
  FileSubtype: LongWord; // Windows.VFT2_…
  FileDate: TDateTime;
  Strings: Array of TStringFileInfo;

  Class Function Get (Filename: String = ''): TFileInfo; Static;
  Function Load(Filename: String = ''): Boolean;

  Property Version[Mode: TVersionStr]: String Read GetVersion; // FileVersion + FileFlags
  Property Typ: String Read GetType;

  Function LanguagesCount: Integer;
  Property Languages[i: Integer]: LANGID Read GetLang;

  Property Language: LANGID Read FLang Write FLang;
  Property CompanyName: String Index 0 Read GetStr;
  Property ProductName: String Index 1 Read GetStr;
  Property ProductVersion_Str: String Index 2 Read GetStr;
  Property FileVersion_Str: String Index 3 Read GetStr;
  Property FileDescription: String Index 4 Read GetStr;
  Property InternalName: String Index 5 Read GetStr;
  Property OriginalFilename: String Index 6 Read GetStr;
  Property LegalCopyright: String Index 7 Read GetStr;
  Property LegalTrademarks: String Index 8 Read GetStr;
  Property Comments: String Index 9 Read GetStr;
  Property PrivateBuild: String Index 10 Read GetStr;
  Property SpecialBuild: String Index 11 Read GetStr;
End;
Beispiel:
Delphi-Quellcode:
var Info: TFileInfo;

Info.Load; // ohne Dateiname wird die eigene Anwendung ausgelesen
ShowMessage(Info.Version[vsLong] + ' ' + DateTimeToStr(Info.FileDate));
// Freigeben nicht nötig (außer wenn man den Record zur Klasse umgebaut hat)
wobei auch sowas möglich ist
x := TFileInfo.Get.FileDate; Noar, das Ganze ist zwar nicht als Klasse erstellt, aber es läßt sich notfalls umrüsten, indem man
Delphi-Quellcode:
Class Function Get (Filename: String = ''): TFileInfo; Static;
Function Load(Filename: String = ''): Boolean;
durch dieses ersetzt
Constructor Create(Filename: String = '');
@Manager der CL:
Wir haben hierzu schon zwei sehr ähnliche Eintäge, in verschiedenen Rubriken.

Code-Library -> Sonstiges -> Versionsinformationen einer EXE- oder DLL-Datei abfragen
Code-Library -> Dateien / Laufwerke -> Dateiversionsinformationen auslesen
Angehängte Dateien
Dateityp: pas fileinfo__dateiversion_und_andere_resourcen__202.pas (14,3 KB, 85x aufgerufen)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat