Skip to content

Commit

Permalink
Small log changes and WIP log decoder script
Browse files Browse the repository at this point in the history
- Unified version text in log
- Added map/savegame info to the log
- Added WIP Python script to decode log file
  • Loading branch information
schwiti6190 committed Nov 2, 2024
1 parent 0169409 commit 2a52bc3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
60 changes: 60 additions & 0 deletions .github/scripts/extract-log-infos/extract-log-infos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import re, pprint

TIME_PATTERN = r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}\s*"
CP_TIME_PATTERN = TIME_PATTERN + r":\d{2}\s*"
CP_LOG_PATTERN = CP_TIME_PATTERN + r"\[\w+\s*lp\d*\]\s*"
VERSION_PATTERN = r"[\d\w]+\.[\d\w]+\.[\d\w]+\.[\d\w]+"
CP_VERSION_PATTERN = rf"Current mod name: [\w\d_]+, Current version: {VERSION_PATTERN},"

LOAD_MOD_PATTERN = r"(?<=Load mod:\s)[\w\d_]+"
MOD_VERSION_PATTERN = r"(?<=Version:\s)[\d.]+(?=\)\s*%s)"
MAP_NAME_PATTERN = r"(?<=Map loaded:\s).+(?=,)"
SAVEGAME_NAME_PATTERN = r"(?<=\sSavegame name:\s).+"
SAVEGAME_INDEX_PATTERN = r"(?<=\()\d+(?=\))"

def decodeLog(path):
with open(path, "r") as f:
data = f.read()
found = re.search(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2} ", data)
sysInfos = "".join(data.splitlines(keepends=True)[3:found.start()])
sysInfosLines = sysInfos.splitlines(keepends=True)
fsVersionData = ""
for i in range(0, len(sysInfosLines)):
if sysInfosLines[i].startswith("Farming Simulator"):
j = i + 1
while True:
if not re.match(r"\s+", sysInfosLines[j]):
break
j += 1
fsVersionData = "".join(sysInfosLines[i:j])
fsVersion = re.findall(VERSION_PATTERN, fsVersionData)[0]

for gameData in re.split("Loaded 'vehicle' specializations", data)[1:]:
try:
# Courseplay infos ...
found = re.findall(CP_LOG_PATTERN + CP_VERSION_PATTERN, gameData)[0]
print(found)
cpVersion = re.findall(VERSION_PATTERN, found)[0]
print(f"Game: {fsVersion}, CP: {cpVersion}, Map: ..")

key = re.search(fr"{CP_LOG_PATTERN}.*{MAP_NAME_PATTERN}.*", gameData).group()
mapName = re.search(MAP_NAME_PATTERN, key).group()
savegameName = re.search(SAVEGAME_NAME_PATTERN, key).group()
savegameIndex = re.search(SAVEGAME_INDEX_PATTERN, savegameName).group()
print(savegameName, savegameIndex)

found_mods = re.findall(LOAD_MOD_PATTERN, gameData)
mods = []
for mod in found_mods:
mods.append({
"name" : mod,
"version" : re.findall(MOD_VERSION_PATTERN % mod, data)[0]})

print(f"Found Mods: \n{pprint.pformat(mods)}")
except:
pass

if __name__ == "__main__":
# TODO add parse input args ...
# decodeLog()
pass
22 changes: 12 additions & 10 deletions Courseplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,16 @@ end
function Courseplay:showUserInformation(xmlFile, key)
local showInfoDialog = true
self.currentVersion = g_modManager:getModByName(self.MOD_NAME).version
local lastLoadedVersion = "----"
if xmlFile then
local lastLoadedVersion = xmlFile:getValue(key.."#lastVersion")
if lastLoadedVersion then
if self.currentVersion == lastLoadedVersion then
showInfoDialog = false
end
CpUtil.info("Current mod name: %s, Current version: %s, last version: %s", self.MOD_NAME, self.currentVersion, lastLoadedVersion)
else
CpUtil.info("Current mod name: %s, Current version: %s, last version: ----", self.MOD_NAME, self.currentVersion)
end
lastLoadedVersion = xmlFile:getValue(key.."#lastVersion")
showInfoDialog = self.currentVersion ~= lastLoadedVersion
else
CpUtil.info("Current mod name: %s, first version: %s (no courseplay config file found)", self.MOD_NAME, self.currentVersion)
lastLoadedVersion = "no config file!"
end
CpUtil.info("Current mod name: %s, Current version: %s, Last version: %s",
self.MOD_NAME, self.currentVersion, lastLoadedVersion)

if showInfoDialog then
g_gui:showInfoDialog({
text = string.format(g_i18n:getText("CP_infoText"), self.currentVersion)
Expand All @@ -96,6 +93,11 @@ function Courseplay:loadMap(filename)
self.globalSettings = CpGlobalSettings()
self:registerXmlSchema()
self:loadUserSettings()
--- Savegame infos here
CpUtil.info("Map loaded: %s, Savegame name: %s(%d)",
g_currentMission.missionInfo.mapId,
g_currentMission.missionInfo.savegameName,
g_currentMission.missionInfo.savegameIndex)
self:load()
self:setupGui()
if g_currentMission.missionInfo.savegameDirectory ~= nil then
Expand Down

0 comments on commit 2a52bc3

Please sign in to comment.