implemented new data location on linux, close #31

This commit is contained in:
Basile Burg 2015-08-25 08:23:41 +02:00
parent a57a0a69fa
commit 379d161a7b
2 changed files with 38 additions and 4 deletions

View File

@ -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/";
}
}

View File

@ -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;