This is the solution I came up with. We do not expect customer to ever edit any other plugins or the Mach4 config so it works for us
Button Clicked Script:
function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
function Save()
mc.mcProfileFlush(inst) --doesn't actually do anything ??
wx.wxMilliSleep(100)
mc.mcProfileSave(inst) -- doesn't actually do anything ??
wx.wxMilliSleep(100)
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
local machineINIPath = path .. "\\Profiles\\" .. profile .. "\\Machine.ini"
local outputINIPath = path .. "\\UnCorrupted\\Machine.ini"
if not file_exists(machineINIPath) then
mc.mcCntlSetLastError(inst, "Machine.ini file does not exist in Mach4 Profiles directory")
return
end
local outputINIFile = io.open(outputINIPath, "w")
local regValue = 0
local persistent = false
local isRegister = false
for line in io.lines(machineINIPath) do
if string.match(line, "gReg") and not isRegister then
isRegister = true
elseif isRegister then
if string.match(line, "Name=") then
local regName = string.match(line, "=(.*)")
local regHandle = mc.mcRegGetHandle(inst, "gRegs0/" .. regName)
regValue = mc.mcRegGetValue(regHandle)
elseif string.match(line, "Persistent=1") then
persistent = true
elseif persistent then
line = "Value=" .. tostring(regValue)
persistent = false
isRegister = false
regValue = 0
end
end
outputINIFile:write(line, "\n")
end
outputINIFile:close()
local rs = wx.wxMessageBox("Saving Complete ", "Confirm", wx.wxOK + wx.wxICON_EXCLAMATION)
end
Save()
.bat File linked to profile start (overwrites any existing machine.ini) .bat file is located in
C:\Mach4\UnCorrupted\
set workingDir=%cd%
set machDir=C:\Mach4
@echo F|xcopy /y "%workingDir%\Machine.ini" "%machDir%\Profiles\ProfileName\Machine.ini"
start %machDir%\Mach4GUI.exe /p ProfileName