AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Appdata, Roaming, etc.

Ein Thema von freimatz · begonnen am 4. Apr 2020 · letzter Beitrag vom 25. Apr 2020
 
Benutzerbild von t2000
t2000

Registriert seit: 15. Dez 2005
Ort: NRW
247 Beiträge
 
Delphi 12 Athens
 
#15

AW: Appdata, Roaming, etc.

  Alt 18. Apr 2020, 11:27
Hier mal die Pfade, die wir benutzen:

Delphi-Quellcode:
var
  CompanyDataPath : string; // Pfad für Programmdateien FEST auf company z.B. C:\ProgramData\CompanyName\
  ProgramDataPath : string; // Pfad für Programmdateien z.B. C:\ProgramData\CompanyName\ProgramName\
  AppDataRoamingPath : string; // Pfad für Programmdateien-Benutzer (Netzwerk) z.B. C:\Users\Benutzer\AppData\Roaming\CompanyName\ProgramName\
  AppDataLocalPath : string; // Pfad für Programmdateien-Benutzer (lokaler PC) z.B. C:\Users\Benutzer\AppData\Local\CompanyName\ProgramName\
  DocumentsPath : string; // Pfad für Benutzerdateien z.B. C:\Users\Benutzer\Documents\CompanyName\ProgramName\
  TempPath : string; // Pfad für Temp-Ordner z.B. C:\Users\Benutzer\AppData\Local\Temp\

const
  // https://docs.microsoft.com/de-de/windows/win32/shell/knownfolderid
  FOLDERID_ProgramData : TGUID = '{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}';
  FOLDERID_RoamingAppData : TGUID = '{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}';
  FOLDERID_LocalAppData : TGUID = '{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}';
  FOLDERID_Documents : TGUID = '{FDD39AD0-238F-46AF-ADB4-6C85480369C7}';
und dazu die Initialisierung

Delphi-Quellcode:
function GetFolderPath( folderId: TGUID): string;
var
  path: LPWSTR;
begin
  if SHGetKnownFolderPath( folderId, KF_FLAG_DEFAULT, 0, path) = S_OK then
  begin
    result := path;
    if copy(result, length(result), 1) <> '\then
      result := result + '\';
  end else
    result := '';
end;

procedure InitPaths( app: string);
begin
  CompanyDataPath := GetFolderPath( FOLDERID_ProgramData) + company + '\';
  ProgramDataPath := GetFolderPath( FOLDERID_ProgramData) + company + '\' + app + '\';
  AppDataRoamingPath := GetFolderPath( FOLDERID_RoamingAppData) + company + '\' + app + '\';
  AppDataLocalPath := GetFolderPath( FOLDERID_LocalAppData) + company + '\' + app + '\';
  DocumentsPath := GetFolderPath( FOLDERID_Documents) + company + '\' + app + '\';
  TempPath := TPath.GetTempPath;
end;
und noch ein paar Hilfsroutinen

Delphi-Quellcode:
function IsDirectoryWriteable(const Directory: string): Boolean;
var
  FileName: String;
  H: THandle;
begin
  FileName := IncludeTrailingPathDelimiter(Directory) + '_check_write.tmp';
  H := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE, 0, nil, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE, 0);
  Result := H <> INVALID_HANDLE_VALUE;
  if Result then
    CloseHandle(H);
end;

function IsFileReadOnly(const Filename: string): boolean;
begin
  if FileExists(Filename) then begin
    result := ((GetFileAttributes( PChar(FileName)) and FILE_ATTRIBUTE_READONLY) = FILE_ATTRIBUTE_READONLY);
    if not result then
      result := not IsDirectoryWriteable( ExtractFilePath( Filename));
  end else begin
    result := false; // damit keine Compilerwarung kommt
    Exception.Create('File: '+Filename+' does not exists.');
  end;
end;
Thomas
(Wir suchen eine(n) Entwickler(in) mit Ambitionen später ggf. die Softwarefirma zu leiten)
Aktuell nicht mehr. Aber ab vielleicht 2024/2025 wird das wieder sehr interessant!
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz