From 379d161a7becacf0ec2e3e141586ff8386f8f7a3 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Tue, 25 Aug 2015 08:23:41 +0200 Subject: [PATCH] implemented new data location on linux, close #31 --- cesetup/cesetup.d | 4 ++-- src/ce_common.pas | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cesetup/cesetup.d b/cesetup/cesetup.d index af274e4f..66379cbd 100644 --- a/cesetup/cesetup.d +++ b/cesetup/cesetup.d @@ -87,13 +87,13 @@ static this() if (asSu) { exePath = "/usr/bin"; - appDataPath = "/home/" ~ environment.get("SUDO_USER") ~ "/Coedit/"; + appDataPath = "/home/" ~ environment.get("SUDO_USER") ~ "/.config/Coedit/"; shortCutPath = "/usr/share/applications/"; } else { exePath = "/home/" ~ environment.get("USER") ~ "/bin/"; - appDataPath = "/home/" ~ environment.get("USER") ~ "/Coedit/"; + appDataPath = "/home/" ~ environment.get("USER") ~ "/.config/Coedit/"; shortCutPath = "/home/" ~ environment.get("USER") ~ "/.local/share/applications/"; } } diff --git a/src/ce_common.pas b/src/ce_common.pas index b0b29b00..24d1f295 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -11,7 +11,7 @@ uses Windows, JwaTlHelp32, {$ENDIF} {$IFDEF LINUX} - ExtCtrls, + ExtCtrls, FileUtil, {$ENDIF} dialogs, forms, process, asyncprocess; @@ -236,6 +236,36 @@ type implementation +{$IFDEF LINUX} +var + // flag that indicates that migration is to be done on first call to getCoeditData... + doneLinuxDataMigration: boolean = false; + +procedure MigrateOldData; +var + oldLocation: string; + newLocation: string; + err: boolean; +begin + err := false; + doneLinuxDataMigration := true; + oldLocation := sysutils.GetEnvironmentVariable('HOME') +'/Coedit'; + if not DirectoryExists(oldLocation) then exit; + newLocation := getUserDataPath + 'Coedit'; + try + try + CopyDirTree(oldLocation, newLocation, + [cffOverwriteFile,cffCreateDestDirectory,cffPreserveTime]); + except + err := true; + end; + finally + if not err then + FileUtil.DeleteDirectory(oldLocation, false); + end; +end; +{$ENDIF} + procedure TCEPersistentShortcut.assign(aValue: TPersistent); var src: TCEPersistentShortcut; @@ -521,7 +551,7 @@ begin result := sysutils.GetEnvironmentVariable('APPDATA'); {$ENDIF} {$IFDEF LINUX} - result := sysutils.GetEnvironmentVariable('HOME'); + result := sysutils.GetEnvironmentVariable('HOME') + '/.config'; {$ENDIF} {$IFDEF DARWIN} result := sysutils.GetEnvironmentVariable('HOME') + '/Library'; @@ -534,6 +564,10 @@ end; function getCoeditDocPath: string; begin + {$IFDEF LINUX} + if not doneLinuxDataMigration then + MigrateOldData; + {$ENDIF} result := getUserDataPath + 'Coedit' + directorySeparator; end;