mirror of
https://github.com/moparisthebest/Simba
synced 2025-01-10 21:28:00 -05:00
Simba: Create new settings on unclean settings.
If we cannot move, rewrite or delete settings.xml, try to cope without settings.xml but warn user.
This commit is contained in:
parent
2b9d7ac498
commit
00ea13c250
@ -35,11 +35,14 @@ type
|
|||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormDestroy(Sender: TObject);
|
procedure FormDestroy(Sender: TObject);
|
||||||
procedure SettingsTreeViewDblClick(Sender: TObject);
|
procedure SettingsTreeViewDblClick(Sender: TObject);
|
||||||
|
function LastStance: Boolean;
|
||||||
{ private declarations }
|
{ private declarations }
|
||||||
public
|
public
|
||||||
procedure SaveCurrent;
|
procedure SaveCurrent;
|
||||||
procedure Reload;
|
procedure Reload;
|
||||||
{ public declarations }
|
{ public declarations }
|
||||||
|
public
|
||||||
|
Oops: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -52,10 +55,33 @@ uses LCLtype;
|
|||||||
|
|
||||||
{ TSettingsForm }
|
{ TSettingsForm }
|
||||||
|
|
||||||
|
function TSettingsForm.LastStance: Boolean;
|
||||||
|
begin
|
||||||
|
result := true;
|
||||||
|
mDebugLn('Could not load settings.xml!');
|
||||||
|
if renamefileUTF8('settings.xml', 'settings.bak') then
|
||||||
|
begin
|
||||||
|
mDebugLn('Moved settings.xml to settings.bak');
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
mDebugLn('Could not move settings.xml to settings.bak');
|
||||||
|
if not deletefile('settings.xml') then
|
||||||
|
begin
|
||||||
|
mDebugLn('Couldnt delete the file either.');
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
SettingsTreeView.Items.Clear;
|
||||||
|
Settings.SaveToXML(SimbaSettingsFile);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSettingsForm.FormCreate(Sender: TObject);
|
procedure TSettingsForm.FormCreate(Sender: TObject);
|
||||||
var
|
var
|
||||||
FirstNode : TTreeNode;
|
FirstNode : TTreeNode;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Oops := False;
|
||||||
Settings := TMMLSettings.Create(SettingsTreeView.Items);
|
Settings := TMMLSettings.Create(SettingsTreeView.Items);
|
||||||
if not FileExists(SimbaSettingsFile) then
|
if not FileExists(SimbaSettingsFile) then
|
||||||
begin
|
begin
|
||||||
@ -63,7 +89,17 @@ begin
|
|||||||
Settings.SaveToXML(SimbaSettingsFile);
|
Settings.SaveToXML(SimbaSettingsFile);
|
||||||
end;
|
end;
|
||||||
SettingsTreeView.Items.Clear;
|
SettingsTreeView.Items.Clear;
|
||||||
Settings.LoadFromXML(SimbaSettingsFile);
|
|
||||||
|
if not Settings.LoadFromXML(SimbaSettingsFile) then
|
||||||
|
begin
|
||||||
|
if not LastStance then
|
||||||
|
begin
|
||||||
|
mDebugLn('Could not create, move or delete settings.xml.');
|
||||||
|
mDebugLn('***************** Giving up... ********************');
|
||||||
|
Oops := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
FirstNode := SettingsTreeView.Items.GetFirstNode;
|
FirstNode := SettingsTreeView.Items.GetFirstNode;
|
||||||
if FirstNode <> nil then
|
if FirstNode <> nil then
|
||||||
if FirstNode.Text = 'Settings' then
|
if FirstNode.Text = 'Settings' then
|
||||||
|
@ -2245,7 +2245,9 @@ begin
|
|||||||
FillThread.FreeOnTerminate:= True;
|
FillThread.FreeOnTerminate:= True;
|
||||||
FillThread.NormalProc:= @CCFillCore;
|
FillThread.NormalProc:= @CCFillCore;
|
||||||
UpdateTimer.OnTimer:= @UpdateTimerCheck;
|
UpdateTimer.OnTimer:= @UpdateTimerCheck;
|
||||||
|
|
||||||
Application.CreateForm(TSimbaUpdateForm, SimbaUpdateForm);
|
Application.CreateForm(TSimbaUpdateForm, SimbaUpdateForm);
|
||||||
|
|
||||||
if FileExistsUTF8(SimbaSettingsFile) then
|
if FileExistsUTF8(SimbaSettingsFile) then
|
||||||
begin
|
begin
|
||||||
Application.CreateForm(TSettingsForm,SettingsForm);
|
Application.CreateForm(TSettingsForm,SettingsForm);
|
||||||
@ -2253,6 +2255,7 @@ begin
|
|||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
Application.CreateForm(TSettingsForm,SettingsForm);
|
Application.CreateForm(TSettingsForm,SettingsForm);
|
||||||
|
|
||||||
Self.CreateDefaultEnvironment;
|
Self.CreateDefaultEnvironment;
|
||||||
FillThread.StartWait:= 250;
|
FillThread.StartWait:= 250;
|
||||||
end;
|
end;
|
||||||
@ -2292,6 +2295,9 @@ begin
|
|||||||
LoadExtensions;
|
LoadExtensions;
|
||||||
UpdateTitle;
|
UpdateTitle;
|
||||||
self.EndFormUpdate;
|
self.EndFormUpdate;
|
||||||
|
|
||||||
|
if SettingsForm.Oops then
|
||||||
|
formWriteln('WARNING: No permissions to write to settings.xml!');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSimbaForm.FormDestroy(Sender: TObject);
|
procedure TSimbaForm.FormDestroy(Sender: TObject);
|
||||||
|
@ -90,8 +90,8 @@ type
|
|||||||
function RenameKey(oldKey,newKey : string) : boolean;
|
function RenameKey(oldKey,newKey : string) : boolean;
|
||||||
function GetKeyValueDefLoad(KeyName, defVal, fileName: String): String;
|
function GetKeyValueDefLoad(KeyName, defVal, fileName: String): String;
|
||||||
|
|
||||||
procedure LoadFromXML(fileName: String);
|
function LoadFromXML(fileName: String): Boolean;
|
||||||
procedure SaveToXML(fileName: String);
|
function SaveToXML(fileName: String): Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -591,7 +591,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
{ load from xml }
|
{ load from xml }
|
||||||
procedure TMMLSettings.LoadFromXML(fileName: String);
|
function TMMLSettings.LoadFromXML(fileName: String): Boolean;
|
||||||
var
|
var
|
||||||
Doc: TXMLDocument;
|
Doc: TXMLDocument;
|
||||||
begin
|
begin
|
||||||
@ -602,9 +602,16 @@ begin
|
|||||||
// create file.
|
// create file.
|
||||||
SaveToXML(fileName);
|
SaveToXML(fileName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
try
|
||||||
ReadXMLFile(Doc, utf8tosys(fileName));
|
ReadXMLFile(Doc, utf8tosys(fileName));
|
||||||
InternalLoadFromXML(Doc);
|
InternalLoadFromXML(Doc);
|
||||||
Doc.Free;
|
Doc.Free;
|
||||||
|
Result := True;
|
||||||
|
except
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMMLSettings.WriteXMLData(n: TTreeNode;
|
procedure TMMLSettings.WriteXMLData(n: TTreeNode;
|
||||||
@ -644,7 +651,7 @@ end;
|
|||||||
|
|
||||||
{ save to xml }
|
{ save to xml }
|
||||||
|
|
||||||
procedure TMMLSettings.SaveToXML(fileName: String);
|
function TMMLSettings.SaveToXML(fileName: String): Boolean;
|
||||||
var
|
var
|
||||||
XMLDoc: TXMLDocument;
|
XMLDoc: TXMLDocument;
|
||||||
Simba,DOMNode: TDOMNode;
|
Simba,DOMNode: TDOMNode;
|
||||||
@ -669,8 +676,10 @@ begin
|
|||||||
|
|
||||||
try
|
try
|
||||||
WriteXMLFile(XMLDoc, utf8tosys(fileName));
|
WriteXMLFile(XMLDoc, utf8tosys(fileName));
|
||||||
|
Result := True;
|
||||||
except
|
except
|
||||||
mDebugLn('Failed to write ' + fileName);
|
mDebugLn('Failed to write ' + fileName);
|
||||||
|
Result := False;
|
||||||
end;
|
end;
|
||||||
XMLDoc.Free;
|
XMLDoc.Free;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user