Skip to content

Commit

Permalink
🚑 Fix location of settings xml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisu118 committed Jun 29, 2019
1 parent a9a5f52 commit 71f8a6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 28 additions & 2 deletions RealClock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ function RealClock:loadMap(name)
local xmlFile = g_modsDirectory .. "/" .. RealClock.configFileName
if not fileExists(xmlFile) then
local modSettingsDir = getUserProfileAppPath() .. "modsSettings"
local newXmlFile = modSettingsDir .. RealClock.configFileName
local newXmlFile = modSettingsDir .. "/" .. RealClock.configFileName
if not fileExists(newXmlFile) then
createFolder(modSettingsDir)
self:writeDefaultConfig(newXmlFile)

-- Special handling for wrongly named file
local wrongNamedFile = modSettingsDir .. RealClock.configFileName
if (fileExists(wrongNamedFile)) then
self:setValuesFromXML(wrongNamedFile)
self:writeCurrentConfig(newXmlFile)
self.debugger:warn("Config file created at correct place, you can safely delete the old file: " .. wrongNamedFile)
else
self:writeDefaultConfig(newXmlFile)
end
end
self:setValuesFromXML(newXmlFile)
else
Expand Down Expand Up @@ -140,6 +149,23 @@ function RealClock:writeDefaultConfig(fileName)
delete(xml)
end

function RealClock:writeCurrentConfig(fileName)
self.debugger:info(
function()
return "Write current Config to " .. fileName
end
)
local xml = createXMLFile("RealClock", fileName, "RealClock")
setXMLBool(xml, "RealClock.position#isDynamic", self.position.dynamic)
setXMLFloat(xml, "RealClock.position#x", self.position.x)
setXMLFloat(xml, "RealClock.position#y", self.position.y)
setXMLString(xml, "RealClock.rendering#color", self.rendering.color)
setXMLFloat(xml, "RealClock.rendering#fontSize", self.rendering.fontSize)
setXMLString(xml, "RealClock.format#string", self.timeFormat)
saveXMLFile(xml)
delete(xml)
end

function RealClock:setValuesFromXML(fileName)
self.debugger:info(
function()
Expand Down
6 changes: 5 additions & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="43">
<author>VertexDezign and Slivicon</author>
<version>1.1.1.0</version>
<version>1.1.2.0</version>
<title>
<en>RealClock Mod</en>
<de>Echte Uhrzeit Mod</de>
Expand All @@ -23,6 +23,8 @@ This script creates a configuration xml at first startup in your modfolder. Ther
* fontSize: the size of the font to display, a value in the range [0..1], default 0.015. UI Scale is used for calculating the font size to display
* Format of datetime string (placeholders see formats_en.txt)
Changelog 1.1.2.0:
- Fix settings file save place
Changelog 1.1.1.0:
- Create modSettings folder if not existent
Changelog 1.1.0.0:
Expand All @@ -47,6 +49,8 @@ Das Script erstellt beim ersten Start eine xml Datei im Mod Ordner. Dort könnt
* fontSize: Die grösse der Schrift, ein wert im Bereich [0..1], Standart ist 0.015. UI Skalierung wird mit einbezogen bei der Darstellung!
* Format des Strings (Formatierungsmöglichkeiten siehe formats_de.txt)
Changelog 1.1.2.0:
- Korrigiere settings xml speicher ort.
Changelog 1.1.1.0:
- modSettings Ordner wird erstellt, falls er noch nicht existiert
Changelog 1.1.0.0:
Expand Down

0 comments on commit 71f8a6b

Please sign in to comment.