Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Welche ist die aktuell gültige API um Systempfade zu bekomme? (https://www.delphipraxis.net/199818-welche-ist-die-aktuell-gueltige-api-um-systempfade-zu-bekomme.html)

Bernhard Geyer 22. Feb 2019 16:18

Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
SHGetSpecialFolderLocation
Zitat:

SHGetSpecialFolderLocation is not supported and may be altered or unavailable in the future. Instead, use SHGetFolderLocation.
SHGetFolderLocation
Zitat:

Deprecated. Retrieves the path of a folder as an ITEMIDLIST structure.
Häää :gruebel:

Könnte es ShGetKnownFolderPath sein?
Da steht noch nicht "Deprecated" ...

jaenicke 22. Feb 2019 16:33

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Ja, Known Folders sind der aktuelle Weg. Hier steht meines Wissens auch noch keine Änderung an.

Pfaffe 22. Feb 2019 18:28

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Alternative: TPath, z.b. TPath.GetDocumentsPath für Windows wird dann im Quellcode von System.IOUtils SHGetFolderPath aufgerufen.

Bernhard Geyer 22. Feb 2019 20:34

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Zitat:

Zitat von Pfaffe (Beitrag 1426273)
Alternative: TPath, z.b. TPath.GetDocumentsPath für Windows wird dann im Quellcode von System.IOUtils SHGetFolderPath aufgerufen.

SHGetFolderPath
Zitat:

Deprecated. Gets the path of a folder identified by a CSIDL value.
Also haben wir schon 3 abgekündigte Methoden für das gleiche Ziel :-)

Schokohase 22. Feb 2019 21:33

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Es kommt darauf an, welche Betriebssysteme du noch unterstützen musst.

Ist noch etwas vor Windows Vista dabei, dann musst du bei
Delphi-Quellcode:
SHGetFolderPath
bleiben.
Ab Windows Vista und neuer kannst du komplett auf
Delphi-Quellcode:
SHGetKnownFolderPath
setzen.

GPRSNerd 23. Feb 2019 16:59

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Da gibts schon was:

https://www.delphipraxis.net/135471-...olderpath.html

TurboMagic 24. Feb 2019 08:03

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Was spricht denn gegen die TPath.GetXXXX Methoden?

Sind in IOUtils drin und funktionieren soweit es diese Pfade jeweils gibt auch Cross Plattform.
Im jeweiligen Hilfetext steht auch jeweis drin, auf welches Verzeichnis unter welcher Plattform
das normalerweise verweist.

Also wozu das Rad neu erfinden bzw. zu plattform spezifisch in deinem Code werden?

Bernhard Geyer 24. Feb 2019 09:08

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Würde ich gerne machen.

Ich brauch (in zwei Fällen) CSIDL_PROFILE bzw. FOLDERID_Profile.
D.h. der "Rootpfad" des Profiles (i.d.R. c:\Users\<UserName>)

Und das ist (soweit ich bei TPath sehe) nicht abgebildet.
Also brauch ich eine eigene Methode mit der ich nur mit Delphi-Strings arbeite und den API-Aufruf kapsele.

Und ja. Ich weiß das man normalerweise die Anwendungsdaten nicht direkt im Profil-Hauptverzeichnis (bzw. direkt dort ein Verzeichnis) ablegt.
Wurde aber gemacht (ähnlich wie es z.B. IDEA oder Adobe Cloud)

Schokohase 24. Feb 2019 11:29

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Ich lasse mich da gerne von .Net inspirieren*

System.Environment.GetFolderPath (referencesource)

und dann käme ich z.B. auf
Delphi-Quellcode:
interface

{$SCOPEDENUMS ON}

const
  CSIDL_FLAG_CREATE = $8000;
  CSIDL_FLAG_DONT_VERIFY = $4000;
  CSIDL_ADMINTOOLS = $0030;
  CSIDL_PROFILE = $0028;

type
  TEnvironment = record
  public type
    TSpecialFolder = ( //
      AdminTools = CSIDL_ADMINTOOLS, //
      UserProfile = CSIDL_PROFILE);
    TSpecialFolderOption = ( //
      None = 0, //
      Create = CSIDL_FLAG_CREATE, //
      DoNotVerify = CSIDL_FLAG_DONT_VERIFY);
  private
    class function InternalGetFolder(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string; static;
  public
    class function GetFolderPath(AFolder: TSpecialFolder): string; overload; static;
    class function GetFolderPath(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string; overload; static;
  end;

implementation

uses
  Winapi.Windows,
  Winapi.SHFolder;

{ TEnvironment }

class function TEnvironment.GetFolderPath(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string;
begin
  Result := InternalGetFolder(AFolder, AOption);
end;

class function TEnvironment.InternalGetFolder(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string;
var
  LStr: array [0 .. MAX_PATH] of Char;
begin
  SetLastError(ERROR_SUCCESS);

  if SHGetFolderPath(0, Integer(AFolder) or Integer(AOption), 0, 0, @LStr) = S_OK then
    Result := LStr;
end;

class function TEnvironment.GetFolderPath(AFolder: TSpecialFolder): string;
begin
  Result := InternalGetFolder(AFolder, TSpecialFolderOption.None);
end;
Und der Aufruf ist sehr sprechend:
Delphi-Quellcode:
TEnvironment.GetFolderPath(TEnvironment.TSpecialFolder.UserProfile);
.

Und um auf wirklich alle SpecialFolder zuzugreifen muss man nur etwas Fleißarbeit investieren und
Delphi-Quellcode:
TEnvironment.TSpecialFolder
komplettieren.

* Was ich auch nicht verwerflich finden, gerade weil Emba das auch sehr gerne macht, allerdings hat man das Gefühl, dass die dabei meistens schielen.

EWeiss 24. Feb 2019 11:38

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?
 
Keine Ahnung was du uns mitteilen willst.
Aber warum das Rad neu erfinden es hat sich bzgl. der Frage in der API auch und besonders in Win10 nichts geändert.

Die Header bzw. der Aufruf von SHGetKnownFolderPath ist bestimmt schon seit D2009 seitens Emba in Delphi integriert und tut seine Arbeit.

just my 2 Cent.
Es ist nicht von Nöten dafür extra eine eigene Classe zu entwerfen.
Aber wie du willst.

gruss


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:22 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz