Skip to content

Commit

Permalink
Changed: Use well documented function for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdvideo1234 committed Aug 3, 2022
1 parent d978adb commit a67bb3c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 89 deletions.
2 changes: 1 addition & 1 deletion data/gearassembly/tools/hooks/pre-commit.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set hookInpFile=tmp.lua

:: The name of the modify file
set hookOutFile=trackassembly_init.lua
set hookOutFile=gearassembly_init.lua

:: Current path of this batch file
set hookBasPath=%~dp0
Expand Down
145 changes: 59 additions & 86 deletions data/gearassembly/tools/hooks/pre-commit.lua
Original file line number Diff line number Diff line change
@@ -1,101 +1,76 @@
-- Test in CMD:
-- ..\..\bin\lua.exe go.lua "E:\Documents\Lua-Projs\SVN\TrackAssemblyTool_GIT_master\lua\autorun\trackassembly_init.lua" "Rev." "UNX"
-- Call in CMD: Script { LUA_PATH, LOG_FILE }
-- Work: E:\Documents\Lua-Projs\SVN\TrackAssemblyTool_GIT_master\hooks\pre-commit.bat E:\Documents\Lua-Projs\Lua\Bin\ E:\Desktop\tmp.txt
-- Work: pre-commit.bat E:\Documents\Lua-Projs\Lua\Bin D:\WindowsTemp\tmp.txt
-- Home:

local sLog = tostring(arg[4]) -- "test.lua"
if((sLog == "nil") or (string.len(sLog) == 0)) then
io.write("No output log file")
else
sLog = sLog:gsub("\\","/")
fLog = io.open(sLog,"a+")
if(fLog) then io.output(fLog) end
end
local fSta = "------------------ %s ------------------\n"
local fVer = "asmlib.SetOpVar%s*%(%s*\"TOOL_VERSION\"%s*,%s*\"%d+%.%d+\"%s*%)"
local fNum = "%s*%d+%s*%.%s*%d+%s*"
local tEnd = {["DOS"]="\r\n", ["UNX"]="\n"}

io.write("------------------ ARG ------------------\n")
io.write("arg[1]<"..tostring(arg[1])..">\n")
io.write("arg[2]<"..tostring(arg[2])..">\n")
io.write("arg[3]<"..tostring(arg[3])..">\n")
io.write("arg[4]<"..tostring(arg[4])..">\n")
local sBase = tostring(arg[1])
sBase = sBase:gsub("\\","/")
if((sBase == "nil") or (string.len(sBase) == 0)) then
io.write("No file\n")
return false
end
io.write("------------------ FILE ------------------\n")
local sOut = tostring(arg[2]) -- "test.lua"
if((sOut == "nil") or (string.len(sOut) == 0)) then
io.write("No output file")
return false
end
local sOut = sBase..sOut
local sInp = sBase.."tmp.lua"
io.write("<"..sOut..">\n<"..sInp..">\n")
io.write("------------------ END ------------------\n")
function trim(s) return s:match("^%s*(.-)%s*$") end

local sLog = tostring(arg[4]):gsub("\\","/")

local fLog, sE = io.open(sLog,"a+")
if(fLog) then io.output(fLog) else io.output("Error: "..sE) end

io.write(fSta:format("START"))

local sBas = tostring(arg[1]):gsub("\\","/")
sBas = ((sBas:sub(-1,-1) == "/") and sBas or sBas.."/")
local sOut = tostring(arg[2])
local sEnd = tostring(arg[3])
if((sEnd == "nil") or (string.len(sEnd) == 0)) then
io.write("No end-line\n")
return false
end
if(not (sEnd == "DOS" or sEnd == "UNX")) then
io.write("Wrong end line mode: -"..sEnd.."-\n")
return false
end
if(sEnd == "DOS") then sEnd = "\r\n" end
if(sEnd == "UNX") then sEnd = "\n" end
io.write("------------------ OPEN FILE ------------------\n")
local fOut = io.open(sOut,"wb")

io.write("arg[1]<"..sBas..">: Process file folder\n")
io.write("arg[2]<"..sOut..">: Process file name\n")
io.write("arg[3]<"..sEnd..">: Dos or unix\n")
io.write("arg[4]<"..sLog..">: Log file path\n")

if(tEnd[sEnd]) then sEnd = tEnd[sEnd]
else io.write("Line end mismatch ["..sEnd.."]\n"); return false end

local sInp = sBas.."tmp.lua"
local fInp = io.open(sInp,"rb")
if(not fOut) then
io.write("File "..sOut.." not found\n")
return false
end
if(not fInp) then
io.write("File "..sInp.." not found\n")
return false
end
io.write("------------------ STORE ------------------\n")
local sI = fInp:read()
if(not sI) then
io.write("File "..sInp.." reached EOF\n")
return false
end
local sO, sCat = "", ""
local sLog = "asmlib.SetLogControl("
local sVer = "asmlib.SetOpVar(\"TOOL_VERSION\",\"5."
local nB, nE, nS, nL, sL = 1, 1, 1, 1, ""
if(fInp) then io.write("Inp: ["..sInp.."]\n")
else io.write("File ["..sInp.."] not found\n"); return false end

local sOut = sBas..sOut
local fOut = io.open(sOut,"wb")
if(fOut) then io.write("Out: ["..sOut.."]\n")
else io.write("File ["..sOut.."] not found\n"); return false end

-- Read first line
local sI = fInp:read("*line"); if(not sI) then -- Line by line
io.write("File "..sInp.." reached EOF\n"); return false end

io.write(fSta:format("PROCESS"))

local nL = 1-- Process file
while(sI) do
sL = "["..tostring(nL).."]"
nB, nE = sI:find(sLog,1,true)
local nB, nE = sI:find(fVer)
if(nB and nE) then
sCat = "0,\"\")"
io.write("Disable logs"..sL.."[1]:Found at <"..tostring(nB).."> to <"..tostring(nE).."> end <"..sCat..">\n")
nB = sI:find(",",1,true)
if(nB and tonumber(sI:sub(nE+1,nB-1))) then
io.write("Disable logs"..sL.."[2]:Number at <"..tostring(nB).."> string <"..tostring(sI:sub(nE+1,nB-1)).."> to <"..tonumber(sI:sub(nE+1,nB-1)).."> Updated !\n")
sI = sLog..sCat
end
end
nB, nE = sI:find(sVer,1,true)
if(nB and nE) then
sCat = "\")"
io.write("Increment the version"..sL.."[1]: Found at <"..tostring(nB).."> to <"..tostring(nE).."> end <"..sCat..">\n")
nB = sI:find(sCat,1,true)
if(nB) then
nS = tonumber(sI:sub(nE+1,nB-1))
io.write("Increment the version"..sL.."[2]: String <"..tostring(sI:sub(nE+1,nB-1)).."> to <"..tostring(nS)..">\n")
if(nS) then
io.write("Increment the version"..sL.."[3]: Increment <"..tostring(nS+1).."> Updated !\n")
sI = sVer..tostring(nS+1)..sCat
io.write("Version found at line ["..nL.."]\n")
local vB, vE = sI:find(fNum)
if(vB and vE) then
print(sI:sub(vB, vE))
local nD = sI:sub(vB, vE):find(".", 1, true)
if(nD) then
local sW = trim(sI:sub(vB, vB + nD - 2))
local sF = trim(sI:sub(vB + nD, vE))
io.write("Version > ["..sW.."]["..sF.."]\n")
sF = tostring(tonumber(sF) + 1)
sI = sI:sub(1,vB-1)..sW.."."..sF..sI:sub(vE+1,-1)
io.write("Extract > ["..sF.."]\n")
end
end
end; nL = nL + 1
end
nL = nL + 1
fOut:write(sI,sEnd)
sI = fInp:read()
sI = fInp:read("*line")
end
io.write("------------------ FINISH ------------------\n")
io.write(fSta:format("FINISH"))
fOut:flush()
fOut:close()
fInp:close()
Expand All @@ -104,5 +79,3 @@ if(fLog) then
fLog:flush()
fLog:close()
end


2 changes: 1 addition & 1 deletion lua/autorun/gearassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local asmlib = gearasmlib

------ CONFIGURE ASMLIB ------
asmlib.InitBase("gear","assembly")
asmlib.SetOpVar("TOOL_VERSION","5.225")
asmlib.SetOpVar("TOOL_VERSION","5.226")
asmlib.SetIndexes("V",1,2,3)
asmlib.SetIndexes("A",1,2,3)
asmlib.SetIndexes("S",4,5,6,7)
Expand Down
2 changes: 1 addition & 1 deletion lua/gearassembly/gearasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ function PrintNotifyPly(pPly,sText,sNotifType)
if(not IsPlayer(pPly)) then
return StatusLog(false,"PrintNotifyPly: Player <"..tostring(pPly)"> invalid") end
if(SERVER) then -- Send notification to client that something happened
pPly:SendLua("GAMEMODE:AddNotify(\""..sText.."\", NOTIFY_"..sNotifType..", 6)")
pPly:SendLua("notification.AddLegacy(\""..sText.."\", NOTIFY_"..sNotifType..", 6)")
pPly:SendLua("surface.PlaySound(\"ambient/water/drip"..mathRandom(1, 4)..".wav\")")
end; return StatusLog(true,"PrintNotifyPly: Success")
end
Expand Down

0 comments on commit a67bb3c

Please sign in to comment.