ADD: Check errors when loading doublecmd.ext and multiarc.ini

This commit is contained in:
Alexander Koblov 2012-11-05 09:33:30 +00:00
commit abc0ec80e0
3 changed files with 106 additions and 94 deletions

View file

@ -170,68 +170,71 @@ var
I, iIndex: Integer;
begin
extFile:= TStringListEx.Create;
extFile.LoadFromFile(sName);
extcmd:=nil;
for I:= 0 to extFile.Count - 1 do
begin
sLine:= extFile.Strings[I];
sLine:= Trim(sLine);
if (sLine='') or (sLine[1]='#') then Continue;
// writeln(sLine);
if sLine[1]='[' then
try
extFile.LoadFromFile(sName);
extcmd:=nil;
for I:= 0 to extFile.Count - 1 do
begin
extCmd:= TExtAction.Create;
FExtList.Add(extcmd);
iIndex:=pos(']', sLine);
if iIndex>0 then
sLine:=Copy(sLine,1,iIndex)
else
logWrite('] not found in line '+sLine);
{ add | for easy searching in two and more extensions
now I can search for example |pas| or |z|
}
extCmd.SectionName:=LowerCase(sLine);
// fill extensions list
s := LowerCase(sLine);
Delete(s, 1, 1); // Delete '['
Delete(s, Length(s), 1); // Delete ']'
s := s + '|';
while Pos('|', s) <> 0 do
begin
iIndex := Pos('|',s);
sExt := Copy(s,1,iIndex-1);
Delete(s, 1, iIndex);
extCmd.Extensions.Add(sExt);
end;
end // end if.. '['
else
begin // this must be a command
if not assigned(extCmd) then
sLine:= extFile.Strings[I];
sLine:= Trim(sLine);
if (sLine='') or (sLine[1]='#') then Continue;
// writeln(sLine);
if sLine[1]='[' then
begin
logWrite('Command '+sLine+' have not defined extension - ignored.');
Continue;
end;
extCmd:= TExtAction.Create;
FExtList.Add(extcmd);
// now set command to lowercase
s := sLine;
for iIndex:=1 to Length(s) do
iIndex:=pos(']', sLine);
if iIndex>0 then
sLine:=Copy(sLine,1,iIndex)
else
logWrite('] not found in line '+sLine);
{ add | for easy searching in two and more extensions
now I can search for example |pas| or |z|
}
extCmd.SectionName:=LowerCase(sLine);
// fill extensions list
s := LowerCase(sLine);
Delete(s, 1, 1); // Delete '['
Delete(s, Length(s), 1); // Delete ']'
s := s + '|';
while Pos('|', s) <> 0 do
begin
iIndex := Pos('|',s);
sExt := Copy(s,1,iIndex-1);
Delete(s, 1, iIndex);
extCmd.Extensions.Add(sExt);
end;
end // end if.. '['
else
begin // this must be a command
if not assigned(extCmd) then
begin
if s[iIndex]='=' then Break;
s[iIndex]:= LowerCase(s[iIndex]);
logWrite('Command '+sLine+' have not defined extension - ignored.');
Continue;
end;
// DCDebug(sLine);
if Pos('name', s) = 1 then // File type name
extCmd.Name := Copy(sLine, iIndex + 1, Length(sLine))
else if Pos('icon', s) = 1 then // File type icon
extCmd.Icon := Copy(sLine, iIndex + 1, Length(sLine))
else // action
extCmd.Actions.Add(sLine);
// now set command to lowercase
s := sLine;
for iIndex:=1 to Length(s) do
begin
if s[iIndex]='=' then Break;
s[iIndex]:= LowerCase(s[iIndex]);
end;
// DCDebug(sLine);
if Pos('name', s) = 1 then // File type name
extCmd.Name := Copy(sLine, iIndex + 1, Length(sLine))
else if Pos('icon', s) = 1 then // File type icon
extCmd.Icon := Copy(sLine, iIndex + 1, Length(sLine))
else // action
extCmd.Actions.Add(sLine);
end;
end;
finally
extFile.Free;
end;
extFile.Free;
end;
function TExts.GetNewSectionName(Index: Integer): String;

View file

@ -517,12 +517,24 @@ begin
Result := gConfig.Load;
end;
function LoadExtsConfig(var ErrorMessage: String): Boolean;
begin
gExts.LoadFromFile(gpCfgDir + 'doublecmd.ext');
Result := True;
end;
function LoadHotManConfig(var ErrorMessage: String): Boolean;
begin
HotMan.Load(gpCfgDir + gNameSCFile);
Result := True;
end;
function LoadMultiArcConfig(var ErrorMessage: String): Boolean;
begin
gMultiArcList.LoadFromFile(gpCfgDir + 'multiarc.ini');
Result := True;
end;
function GetValidDateTimeFormat(const aFormat, ADefaultFormat: string): string;
begin
try
@ -1282,8 +1294,9 @@ begin
CopySettingsFiles;
{ Internal associations }
if mbFileExists(gpCfgDir + 'doublecmd.ext') then
gExts.LoadFromFile(gpCfgDir + 'doublecmd.ext');
LoadConfigCheckErrors(@LoadExtsConfig, gpCfgDir + 'doublecmd.ext', ErrorMessage);
LoadStringsFromFile(glsDirHistory, gpCfgDir + 'dirhistory.txt', cMaxStringItems);
LoadStringsFromFile(glsMaskHistory, gpCfgDir + 'maskhistory.txt', cMaxStringItems);
@ -1302,7 +1315,7 @@ begin
{ MultiArc addons }
if mbFileExists(gpCfgDir + 'multiarc.ini') then
gMultiArcList.LoadFromFile(gpCfgDir + 'multiarc.ini');
LoadConfigCheckErrors(@LoadMultiArcConfig, gpCfgDir + 'multiarc.ini', ErrorMessage);
{ Localization }
DoLoadLng;

View file

@ -233,8 +233,8 @@ var
FirstTime: Boolean = True;
MultiArcItem: TMultiArcItem;
begin
IniFile:= TIniFileEx.Create(FileName, fmOpenRead);
try
IniFile:= TIniFileEx.Create(FileName, fmOpenRead);
Sections:= TStringList.Create;
IniFile.ReadSections(Sections);
for I:= 0 to Sections.Count - 1 do
@ -294,49 +294,45 @@ var
Section: UTF8String;
MultiArcItem: TMultiArcItem;
begin
IniFile:= TIniFileEx.Create(FileName, fmOpenWrite);
try
IniFile:= TIniFileEx.Create(FileName, fmOpenWrite);
try
IniFile.Clear;
for I:= 0 to FList.Count - 1 do
IniFile.Clear;
for I:= 0 to FList.Count - 1 do
begin
Section:= FList.Strings[I];
MultiArcItem:= TMultiArcItem(FList.Objects[I]);
with MultiArcItem do
begin
Section:= FList.Strings[I];
MultiArcItem:= TMultiArcItem(FList.Objects[I]);
with MultiArcItem do
IniFile.WriteString(Section, 'Archiver', FArchiver);
IniFile.WriteString(Section, 'Description', FDescription);
IniFile.WriteString(Section, 'ID', FID);
IniFile.WriteString(Section, 'IDPos', FIDPos);
IniFile.WriteString(Section, 'IDSeekRange', FIDSeekRange);
IniFile.WriteString(Section, 'Extension', FExtension);
IniFile.WriteString(Section, 'Start', FStart);
IniFile.WriteString(Section, 'End', FEnd);
for J:= 0 to FFormat.Count - 1 do
begin
IniFile.WriteString(Section, 'Archiver', FArchiver);
IniFile.WriteString(Section, 'Description', FDescription);
IniFile.WriteString(Section, 'ID', FID);
IniFile.WriteString(Section, 'IDPos', FIDPos);
IniFile.WriteString(Section, 'IDSeekRange', FIDSeekRange);
IniFile.WriteString(Section, 'Extension', FExtension);
IniFile.WriteString(Section, 'Start', FStart);
IniFile.WriteString(Section, 'End', FEnd);
for J:= 0 to FFormat.Count - 1 do
begin
IniFile.WriteString(Section, 'Format' + IntToStr(J), FFormat[J]);
end;
IniFile.WriteString(Section, 'List', FList);
IniFile.WriteString(Section, 'Extract', FExtract);
IniFile.WriteString(Section, 'ExtractWithoutPath', FExtractWithoutPath);
IniFile.WriteString(Section, 'Test', FTest);
IniFile.WriteString(Section, 'Delete', FDelete);
IniFile.WriteString(Section, 'Add', FAdd);
IniFile.WriteString(Section, 'AddSelfExtract', FAddSelfExtract);
IniFile.WriteString(Section, 'PasswordQuery', FPasswordQuery);
// optional
IniFile.WriteInteger(Section, 'FormMode', FFormMode);
IniFile.WriteBool(Section, 'Enabled', FEnabled);
IniFile.WriteBool(Section, 'Output', FOutput);
IniFile.WriteBool(Section, 'Debug', FDebug);
IniFile.WriteString(Section, 'Format' + IntToStr(J), FFormat[J]);
end;
IniFile.WriteString(Section, 'List', FList);
IniFile.WriteString(Section, 'Extract', FExtract);
IniFile.WriteString(Section, 'ExtractWithoutPath', FExtractWithoutPath);
IniFile.WriteString(Section, 'Test', FTest);
IniFile.WriteString(Section, 'Delete', FDelete);
IniFile.WriteString(Section, 'Add', FAdd);
IniFile.WriteString(Section, 'AddSelfExtract', FAddSelfExtract);
IniFile.WriteString(Section, 'PasswordQuery', FPasswordQuery);
// optional
IniFile.WriteInteger(Section, 'FormMode', FFormMode);
IniFile.WriteBool(Section, 'Enabled', FEnabled);
IniFile.WriteBool(Section, 'Output', FOutput);
IniFile.WriteBool(Section, 'Debug', FDebug);
end;
IniFile.WriteBool('MultiArc', 'FirstTime', False);
finally
IniFile.Free;
end;
except
IniFile.WriteBool('MultiArc', 'FirstTime', False);
finally
IniFile.Free;
end;
end;