Skip to content

Commit

Permalink
Конец рефакторинга путей?
Browse files Browse the repository at this point in the history
  • Loading branch information
zamtmn committed Jan 4, 2025
1 parent c6fcd60 commit 390d5bd
Showing 9 changed files with 91 additions and 34 deletions.
58 changes: 51 additions & 7 deletions cad_source/components/zebase/uzbpaths.pas
Original file line number Diff line number Diff line change
@@ -74,7 +74,12 @@ function GetSupportPaths:String;
//путь к бинарнику
function GetBinaryPath:String;
//путь к дистрибутиву
function GetDistribPath:String;
procedure SetDistribPath(const APath:String);
//путь к конфигам программы
function GetRoCfgsPath:String;
//путь к конфигам юзера
function GetWrCfgsPath:String;
//путь к папке временных файлов
function GetTempPath:String;
//дополнительные пути с файлами поддержки, сюда рути добавляются скриптами при
@@ -95,8 +100,11 @@ procedure FromDirsIterator(const APath,AMask,AFirstLoadFileName:String;
AProc:TFromDirIterator;AMethod:TFromDirIteratorObj;
APData:pointer=nil;AIgnoreDoubles:Boolean=False);

//поиск расположения дистрибутива, см. вариант 2 выше про DataPaths
function FindDistroPath(const CF:TDataFilesExistChecFunc):string;
//поиск расположения конфигов
function FindDistribPath(const CF:TDataFilesExistChecFunc):string;

//поиск расположения дистрибутива
function FindConfigsPath(const CF:TDataFilesExistChecFunc):string;

var
//SupportPath сохраняется и настраивается, поэтому в интерфейсе с доступом
@@ -106,6 +114,10 @@ function FindDistroPath(const CF:TDataFilesExistChecFunc):string;
implementation

var
//доступ геттером и сеттером
DistribPath:String;
//DistribPath переопределен
DistribPathOverride:boolean;
//остальные переменные с доступом только по геттеру
BinaryPath,TempPath,AdditionalSupportPaths,RoCfgsPath,WrCfgsPath:String;

@@ -140,10 +152,23 @@ function GetBinaryPath:String;
begin
result:=BinaryPath;
end;
function GetDistribPath:String;
begin
result:=DistribPath;
end;
procedure SetDistribPath(const APath:String);
begin
if not DistribPathOverride then
DistribPath:=APath;
end;
function GetRoCfgsPath:String;
begin
result:=RoCfgsPath;
end;
function GetWrCfgsPath:String;
begin
result:=WrCfgsPath;
end;
function GetTempPath:String;
begin
result:=TempPath;
@@ -333,7 +358,7 @@ procedure FromDirIterator(const APath,AMask,AFirstLoadFileName:String;AProc:TFro
if AIgnoreDoubles then
vs.done;
end;
function FindDistroPath(const CF:TDataFilesExistChecFunc):string;
function FindConfigsPath(const CF:TDataFilesExistChecFunc):string;
var
ts:string;
begin
@@ -351,9 +376,28 @@ function FindDistroPath(const CF:TDataFilesExistChecFunc):string;
RoCfgsPath:=Result;
end;
end;

function FindDistribPath(const CF:TDataFilesExistChecFunc):string;
var
ts:string;
begin
try
if @cf<>nil then begin
if cf(DistribPath) then
exit(DistribPath);
end;
Result:='';
finally
if result<>''then
DistribPathOverride:=True;
end;
end;

initialization
BinaryPath:=ExtractFilePath(paramstr(0));
RoCfgsPath:=ExpandFileName(BinaryPath+'../../cfg');
WrCfgsPath:=GetAppConfigDir(false);
TempPath:=GetTempDir;
BinaryPath:=ExcludeTrailingPathDelimiter(ExtractFilePath(paramstr(0)));
DistribPath:=ExpandFileName(ConcatPaths([BinaryPath,'..','..','data']));
DistribPathOverride:=false;
RoCfgsPath:=ExpandFileName(ConcatPaths([BinaryPath,'..','..','cfg']));
WrCfgsPath:=ExcludeTrailingPathDelimiter(GetAppConfigDir(false));
TempPath:=ExcludeTrailingPathDelimiter(GetTempDir);
end.
4 changes: 3 additions & 1 deletion cad_source/zcad/register/uzcregpaths.pas
Original file line number Diff line number Diff line change
@@ -28,8 +28,10 @@ initialization
units.CreateExtenalSystemVariable(SysVarUnit,SysVarN,GetSupportPaths,expandpath('$(DistribPath)/rtl/system.pas'),InterfaceTranslate,'PATH_Support_Path','String',@SupportPaths);
sysvar.PATH.Dictionaries:[email protected];
sysvar.PATH.RoCfg_Path:=@GetRoCfgsPath;
sysvar.PATH.WrCfg_Path:=@GetWrCfgsPath;
sysvar.PATH.Support_Paths:=@SupportPaths;
sysvar.PATH.Distrib_Path:[email protected];
sysvar.PATH.Distrib_Path:=@GetDistribPath;
sysvar.PATH.PreferedDistrib_Path:[email protected];
sysvar.PATH.AdditionalSupport_Paths:=@GetAdditionalSupportPaths;
sysvar.PATH.Temp_Path:=@GetTempPath;
finalization
8 changes: 5 additions & 3 deletions cad_source/zcad/uzcfilestructure.pas
Original file line number Diff line number Diff line change
@@ -22,9 +22,7 @@
interface
const
CFSrtlDir='rtl';
CFSconfigxmlFile='config.xml';
CFSsysvarpasFile='sysvar.pas';
CFSsavedvarpasFile='savedvar.pas';
CFSsystempasFile='system.pas';

CFScomponentsDir='components';
CFSdefaultlayoutxmlFile='defaultlayout.xml';
@@ -33,6 +31,10 @@ interface
CFSlogopngFile='logo.png';

CFSconfigsDir='configs';
CFSconfigxmlFile='config.xml';
CFSsysvarpasFile='sysvar.pas';
CFSsavedvarpasFile='savedvar.pas';

CFSnavigatorsDir='navigators';

CFSdictionariesDir='dictionaries';
2 changes: 1 addition & 1 deletion cad_source/zcad/uzcpathmacros.pas
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ class function TZCADPathsMacroMethods.MacroFuncBinaryPath(const {%H-}Param: stri
end;
class function TZCADPathsMacroMethods.MacroFuncDistribPath(const {%H-}Param: string; const Data: PtrInt;var {%H-}Abort: boolean): string;
begin
result:=sysparam.saved.DistribPath;
result:=GetDistribPath{sysparam.saved.PreferredDistribPath};
end;
class function TZCADPathsMacroMethods.MacroFuncDictPath(const {%H-}Param: string; const Data: PtrInt;
var {%H-}Abort: boolean): string;
10 changes: 8 additions & 2 deletions cad_source/zcad/uzcsysinfo.pas
Original file line number Diff line number Diff line change
@@ -141,11 +141,16 @@ procedure ProcessParamStr;

finally programlog.leave(IfEntered);end;
end;
function DataFilesExistChec(const ACheckedPath:string):boolean;
function ConfigsFilesExistChec(const ACheckedPath:string):boolean;
begin
result:=DirectoryExists(ConcatPaths([ACheckedPath,CFSconfigsDir]))
and FileExists(ConcatPaths([ACheckedPath,CFSconfigsDir,CFSsysvarpasFile]));
end;
function DistribFilesExistChec(const ACheckedPath:string):boolean;
begin
result:=DirectoryExists(ConcatPaths([ACheckedPath,CFSrtlDir]))
and FileExists(ConcatPaths([ACheckedPath,CFSrtlDir,CFSsystempasFile]));
end;

Procedure GetSysInfo;
begin
@@ -197,7 +202,8 @@ function DataFilesExistChec(const ACheckedPath:string):boolean;
end;
procedure FindData;
begin
FindDistroPath(DataFilesExistChec);
FindDistribPath(DistribFilesExistChec);
FindConfigsPath(ConfigsFilesExistChec);
end;

initialization
9 changes: 5 additions & 4 deletions cad_source/zcad/uzcsysparams.pas
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ tsavedparams=record
LangOverride:string;(*'Language override'*)
DictionariesPath:string;(*'Dictionaries path'*)
LastAutoSaveFile:string;(*'Last autosave file'*)
DistribPath:String;(*'Path to distributive'*)
PreferredDistribPath:String;(*'Path to distributive'*)
end;
{REGISTERRECORDTYPE tnotsavedparams}
tnotsavedparams=record
@@ -70,7 +70,7 @@ tsysparam=record
LangOverride:'';
DictionariesPath:'ru=$(ZCADDictionariesPath)/ru_RU.dic|en=$(ZCADDictionariesPath)/en_US.dic;$(ZCADDictionariesPath)/en_US_interface.dic|abbrv=$(ZCADDictionariesPath)/abbrv.dic';
LastAutoSaveFile:'noAutoSaveFile';
DistribPath:'sss');
PreferredDistribPath:'sss');
zcaduniqueinstanceid='zcad unique instance';
var
SysParam: tsysparam;
@@ -94,7 +94,7 @@ procedure SaveParamToConfig(Config: TConfigStorage; var Params:tsavedparams);
Config.SetDeleteValue('LangOverride',Params.LangOverride,DefaultSavedParams.LangOverride);
Config.SetDeleteValue('DictionariesPath',Params.DictionariesPath,DefaultSavedParams.DictionariesPath);
Config.SetDeleteValue('LastAutoSaveFile',Params.LastAutoSaveFile,DefaultSavedParams.LastAutoSaveFile);
Config.SetDeleteValue('DistribPath',Params.DistribPath,DefaultSavedParams.DistribPath);
Config.SetDeleteValue('PreferredDistribPath',Params.PreferredDistribPath,DefaultSavedParams.PreferredDistribPath);
Config.UndoAppendBasePath;
end;

@@ -145,7 +145,8 @@ procedure LoadParams(xmlfile:string;out Params:tsavedparams);
Params.LangOverride:=XMLConfig.GetAnsiValue('LangOverride',DefaultSavedParams.LangOverride);
Params.DictionariesPath:=XMLConfig.GetAnsiValue('DictionariesPath',DefaultSavedParams.DictionariesPath);
Params.LastAutoSaveFile:=XMLConfig.GetAnsiValue('LastAutoSaveFile',DefaultSavedParams.LastAutoSaveFile);
Params.DistribPath:=XMLConfig.GetAnsiValue('DistribPath',DefaultSavedParams.DistribPath);
Params.PreferredDistribPath:=XMLConfig.GetAnsiValue('PreferredDistribPath',DefaultSavedParams.PreferredDistribPath);
SetDistribPath(Params.PreferredDistribPath);
XMLConfig.CloseKey;
FreeAndNil(XMLConfig);
end;
30 changes: 16 additions & 14 deletions cad_source/zcad/uzcsysvars.pas
Original file line number Diff line number Diff line change
@@ -59,20 +59,22 @@ tdebug=record
end;
{REGISTERRECORDTYPE tpath}
tpath=record
Support_Paths:PString;(*'Support files'*)
AdditionalSupport_Paths:TFString;(*'Additional support files'*)(*oi_readonly*)
Preload_Paths:PString;(*'Preload files'*)
Fonts_Paths:PString;(*'Fonts'*)
Alternate_Font:PString;(*'Alternate font file'*)
Template_Path:PString;(*'Templates'*)
Template_File:PString;(*'Default template'*)
LayoutFile:PString;(*'Current layout'*)
Dictionaries:PString;(*'Dictionaries'*)
Distrib_Path:PString;(*'Path to program distributive'*)
RoCfg_Path:TFString;(*'Read only cfg path'*)(*oi_readonly*)
Temp_Path:TFString;(*'Temporary files'*)(*oi_readonly*)
Device_Library:PString;(*'Device base'*)
end;
Distrib_Path:TFString;(*'Path to program distributive'*)(*oi_readonly*)
PreferedDistrib_Path:PString;(*'Prefered path to distributive'*)
RoCfg_Path:TFString;(*'Path to program configs'*)(*oi_readonly*)
WrCfg_Path:TFString;(*'Path to user configs'*)(*oi_readonly*)
Temp_Path:TFString;(*'Temporary files'*)(*oi_readonly*)
Support_Paths:PString;(*'Support files'*)
AdditionalSupport_Paths:TFString;(*'Additional support files'*)(*oi_readonly*)
Preload_Paths:PString;(*'Preload files'*)
Fonts_Paths:PString;(*'Fonts'*)
Alternate_Font:PString;(*'Alternate font file'*)
Template_Path:PString;(*'Templates'*)
Template_File:PString;(*'Default template'*)
LayoutFile:PString;(*'Current layout'*)
Dictionaries:PString;(*'Dictionaries'*)
Device_Library:PString;(*'Device base'*)
end;
PTCanvasData=^TCanvasData;
{REGISTERRECORDTYPE TCanvasData}
TCanvasData=record
2 changes: 1 addition & 1 deletion cad_source/zcad/uzctranslations.pas
Original file line number Diff line number Diff line change
@@ -310,7 +310,7 @@ initialization
TranslateLogModuleId:=programlog.RegisterModule('TRANSLATOR');
TranslateSpellerLogModuleId:=ProgramLog.RegisterModule('TRANSLATOR/SPELLER');
DisableTranslateCount:=0;
PODirectory:=ConcatPaths([sysparam.saved.DistribPath,CFSlanguagesDir]);
PODirectory:=ConcatPaths([GetDistribPath,CFSlanguagesDir]);
GetLanguageIDs(Lang, FallbackLang); // определено в модуле gettext
if sysparam.saved.LangOverride<>'' then begin
Lang:=sysparam.saved.LangOverride;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<CONFIG>
<Stage0Params DictionariesPath="ru=$(DictPath)/ru_RU.dic;$(DictPath)/ops.dic|en=$(DictPath)/en_US.dic;$(DictPath)/en_US_interface.dic|abbrv=$(DictPath)/abbrv.dic" DistribPath="Y:\zcad\cad\data"/>
<Stage0Params DictionariesPath="ru=$(DictPath)/ru_RU.dic;$(DictPath)/ops.dic|en=$(DictPath)/en_US.dic;$(DictPath)/en_US_interface.dic|abbrv=$(DictPath)/abbrv.dic" PreferredDistribPath="C:\Program Files\zcad"/>
</CONFIG>

0 comments on commit 390d5bd

Please sign in to comment.