Einzelnen Beitrag anzeigen

Benutzerbild von t2000
t2000

Registriert seit: 15. Dez 2005
Ort: NRW
212 Beiträge
 
Delphi 11 Alexandria
 
#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