mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-22 23:38:50 -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 FormDestroy(Sender: TObject);
|
||||
procedure SettingsTreeViewDblClick(Sender: TObject);
|
||||
function LastStance: Boolean;
|
||||
{ private declarations }
|
||||
public
|
||||
procedure SaveCurrent;
|
||||
procedure Reload;
|
||||
{ public declarations }
|
||||
public
|
||||
Oops: Boolean;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -52,10 +55,33 @@ uses LCLtype;
|
||||
|
||||
{ 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);
|
||||
var
|
||||
FirstNode : TTreeNode;
|
||||
|
||||
begin
|
||||
Oops := False;
|
||||
Settings := TMMLSettings.Create(SettingsTreeView.Items);
|
||||
if not FileExists(SimbaSettingsFile) then
|
||||
begin
|
||||
@ -63,7 +89,17 @@ begin
|
||||
Settings.SaveToXML(SimbaSettingsFile);
|
||||
end;
|
||||
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;
|
||||
if FirstNode <> nil then
|
||||
if FirstNode.Text = 'Settings' then
|
||||
|
@ -2245,7 +2245,9 @@ begin
|
||||
FillThread.FreeOnTerminate:= True;
|
||||
FillThread.NormalProc:= @CCFillCore;
|
||||
UpdateTimer.OnTimer:= @UpdateTimerCheck;
|
||||
|
||||
Application.CreateForm(TSimbaUpdateForm, SimbaUpdateForm);
|
||||
|
||||
if FileExistsUTF8(SimbaSettingsFile) then
|
||||
begin
|
||||
Application.CreateForm(TSettingsForm,SettingsForm);
|
||||
@ -2253,6 +2255,7 @@ begin
|
||||
end else
|
||||
begin
|
||||
Application.CreateForm(TSettingsForm,SettingsForm);
|
||||
|
||||
Self.CreateDefaultEnvironment;
|
||||
FillThread.StartWait:= 250;
|
||||
end;
|
||||
@ -2292,6 +2295,9 @@ begin
|
||||
LoadExtensions;
|
||||
UpdateTitle;
|
||||
self.EndFormUpdate;
|
||||
|
||||
if SettingsForm.Oops then
|
||||
formWriteln('WARNING: No permissions to write to settings.xml!');
|
||||
end;
|
||||
|
||||
procedure TSimbaForm.FormDestroy(Sender: TObject);
|
||||
|
@ -90,8 +90,8 @@ type
|
||||
function RenameKey(oldKey,newKey : string) : boolean;
|
||||
function GetKeyValueDefLoad(KeyName, defVal, fileName: String): String;
|
||||
|
||||
procedure LoadFromXML(fileName: String);
|
||||
procedure SaveToXML(fileName: String);
|
||||
function LoadFromXML(fileName: String): Boolean;
|
||||
function SaveToXML(fileName: String): Boolean;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -591,7 +591,7 @@ end;
|
||||
|
||||
|
||||
{ load from xml }
|
||||
procedure TMMLSettings.LoadFromXML(fileName: String);
|
||||
function TMMLSettings.LoadFromXML(fileName: String): Boolean;
|
||||
var
|
||||
Doc: TXMLDocument;
|
||||
begin
|
||||
@ -602,9 +602,16 @@ begin
|
||||
// create file.
|
||||
SaveToXML(fileName);
|
||||
end;
|
||||
|
||||
try
|
||||
ReadXMLFile(Doc, utf8tosys(fileName));
|
||||
InternalLoadFromXML(Doc);
|
||||
Doc.Free;
|
||||
Result := True;
|
||||
except
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TMMLSettings.WriteXMLData(n: TTreeNode;
|
||||
@ -644,7 +651,7 @@ end;
|
||||
|
||||
{ save to xml }
|
||||
|
||||
procedure TMMLSettings.SaveToXML(fileName: String);
|
||||
function TMMLSettings.SaveToXML(fileName: String): Boolean;
|
||||
var
|
||||
XMLDoc: TXMLDocument;
|
||||
Simba,DOMNode: TDOMNode;
|
||||
@ -669,8 +676,10 @@ begin
|
||||
|
||||
try
|
||||
WriteXMLFile(XMLDoc, utf8tosys(fileName));
|
||||
Result := True;
|
||||
except
|
||||
mDebugLn('Failed to write ' + fileName);
|
||||
Result := False;
|
||||
end;
|
||||
XMLDoc.Free;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user