GH*master Expert Cheater
Reputation: 8
Joined: 10 Jan 2008 Posts: 159
|
Posted: Tue May 29, 2012 12:26 pm Post subject: How open and save file without merge data? |
|
|
| Quote: | loadTable(filename, merge OPTIONAL): Loads a .ct or .cetrainer. If merge is provided and set to true it will not clear the old table
saveTable(filename, protect OPTIONAL): Saves the current table. If protect is provided and set to true and the filename has the .CETRAINER extension, it will protect it from reading normally |
if I open the file with
loadTable(newName, false)
and save
saveTable(oldName, false)
Some "Structures" data from "newName"-file merge with "oldName"-file
| Code: | local version = '0.6'
local defaultScriptFolder = "//TempScripts"
--local path = getCheatEngineDir().."autorun\\TempScripts\\"
local pathAutorun = getCheatEngineDir()..'\\autorun\\'
local path = 'C:\\Users\\'..os.getenv("USERNAME")..'\\Documents\\My Cheat Tables\\'
listBoxScripts = nil
tempCopyFileNames = nil
function UpdateTempCopyFileNames()
if tempCopyFileNames ~= nil then
strings_clear(tempCopyFileNames)
else
tempCopyFileNames = createStringlist()
end
local _strings = listbox_getItems(listBoxScripts)
local maxCount = strings_getCount(_strings) - 1
for i=0, maxCount do
local fileName = strings_getString(_strings, i)
strings_add(tempCopyFileNames, fileName)
end
end
local editScriptFilter = nil
local firstFilter = true
local lastString = ''
function OnUpKeyEditScriptFilter(sender)
local focused = wincontrol_focused(editScriptFilter)
if(focused) then
if firstFilter then
firstFilter = false
control_setCaption(editScriptFilter, '')
return
end
local filterCaption = control_getCaption(editScriptFilter)
if (lastString ~= filterCaption) then
lastString = filterCaption
if filterCaption == '' then
local _strings = listbox_getItems(listBoxScripts)
local currentCountFiles = strings_getCount(_strings)
local currentCounttempFiles = strings_getCount(tempCopyFileNames)
if (currentCountFiles ~= currentCounttempFiles) then
local maxCount = strings_getCount(tempCopyFileNames) - 1
strings_clear(_strings)
for i=0, maxCount do
local fileName = strings_getString(tempCopyFileNames, i)
strings_add(_strings, fileName)
end
end
return
end
local _strings = listbox_getItems(listBoxScripts)
local currentCountFiles = strings_getCount(_strings)
local currentCounttempFiles = strings_getCount(tempCopyFileNames)
local newStringList = createStringlist()
strings_clear(_strings)
local maxCount = strings_getCount(tempCopyFileNames) - 1
local pattern = filterCaption:upper()
for i=0, maxCount do
local fileName = strings_getString(tempCopyFileNames, i)
local tfileName = fileName:upper()
if (string.find(fileName:upper(), pattern) ~= nil) then
strings_add(_strings, fileName)
end
end
object_destroy(newStringList)
end
end
end
function GetListFilesCT()
local sctringsScriptNames = listbox_getItems(listBoxScripts)
strings_clear(sctringsScriptNames)
local tableFileList = io.popen([[dir "]]..path..[[" /b ]]):lines()
local pattern1 = "(%.ct)$"
local pattern2 = "(%.CT)$"
for dir in tableFileList do
if (string.find(dir, pattern1) ~= nil or string.find(dir, pattern2) ~= nil ) then
strings_add(sctringsScriptNames, dir)
end
end
UpdateTempCopyFileNames()
end
function GetListFilesCETRAINER()
local sctringsScriptNames = listbox_getItems(listBoxScripts)
strings_clear(sctringsScriptNames)
local tableFileList = io.popen([[dir "]]..path..[[" /b ]]):lines()
local pattern1 = "(%.cetrainer)$"
local pattern2 = "(%.CETRAINER)$"
for dir in tableFileList do
if (string.find(dir, pattern1) ~= nil or string.find(dir, pattern2) ~= nil ) then
strings_add(sctringsScriptNames, dir)
end
end
UpdateTempCopyFileNames()
end
function FillListFilesTwoType(sctringsScriptNames)
local sctringsScriptNames = listbox_getItems(listBoxScripts)
strings_clear(sctringsScriptNames)
local tableFileList = io.popen([[dir "]]..path..[[" /b ]]):lines()
local pattern1 = "(%.ct)$"
local pattern2 = "(%.CT)$"
local pattern3 = "(%.cetrainer)$"
local pattern4 = "(%.CETRAINER)$"
for dir in tableFileList do
if string.find(dir, pattern1) ~= nil or string.find(dir, pattern2) ~= nil or string.find(dir, pattern3) ~= nil or string.find(dir, pattern4) ~= nil then
strings_add(sctringsScriptNames, dir)
end
end
UpdateTempCopyFileNames()
end
function GetListFiles()
local sctringsScriptNames = listbox_getItems(listBoxScripts)
strings_clear(sctringsScriptNames)
local tableFileList = io.popen([[dir "]]..path..[[" /b ]]):lines()
local pattern1 = "(%.ct)$"
local pattern2 = "(%.CT)$"
local pattern3 = "(%.cetrainer)$"
local pattern4 = "(%.CETRAINER)$"
for dir in tableFileList do
if not(string.find(dir, pattern1) ~= nil or string.find(dir, pattern2) ~= nil or string.find(dir, pattern3) ~= nil or string.find(dir, pattern4) ~= nil) then
strings_add(sctringsScriptNames, dir)
end
end
UpdateTempCopyFileNames()
end
local controlMainForm = getMainForm()
Panel1 = wincontrol_getControl(controlMainForm,1)
spliterPanelTableGameList = createSplitter(Panel1)
setProperty(spliterPanelTableGameList, 'Align', 'alLeft')
local panelTableGameList = createPanel(Panel1)
setProperty(panelTableGameList, 'Align', 'alLeft')
editScriptFilter = createEdit(panelTableGameList)
setProperty(editScriptFilter, 'Align', 'alTop')
control_setCaption(editScriptFilter, 'Script Name')
listBoxScripts = createListBox(panelTableGameList)
setProperty(listBoxScripts, 'Align', 'alClient')
lastItemIndex = -1
function TimerOnChangeSelectListBox(sender)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
if lastItemIndex ~= itemIndexSelected then
local strings = listbox_getItems(listBoxScripts)
if lastItemIndex ~= -1 then
local oldName = path..strings_getString(strings, lastItemIndex)
saveTable(oldName, false)
end
lastItemIndex = itemIndexSelected
if lastItemIndex ~= -1 then
local newName = path..strings_getString(strings, itemIndexSelected)
--print('loadTable '..newName)
loadTable(newName, false)
end
end
end
eventListBoxTimer = createTimer(listBoxScripts)
timer_setInterval(eventListBoxTimer, 300)
timer_onTimer(eventListBoxTimer, TimerOnChangeSelectListBox)
timer_setEnabled(eventListBoxTimer, true)
popupMenulistBoxScripts = createPopupMenu(listBoxScripts)
control_setPopupMenu(listBoxScripts, popupMenulistBoxScripts)
itemsPopupMenulistBoxScripts = menu_getItems(popupMenulistBoxScripts)
function AddMenuItemInPopupMenulistBoxScripts(caption)
menuItem = createMenuItem(popupMenulistBoxScripts)
menuItem_setCaption(menuItem, caption)
menuItem_add(itemsPopupMenulistBoxScripts, menuItem)
return menuItem
end
itemCT = nil
itemCETRAINER = nil
itemCTChecked = true
itemCETRAINERChecked = true
FillListFilesTwoType()
function UpdateExtensions()
if itemCTChecked and itemCETRAINERChecked then FillListFilesTwoType()
else if not itemCTChecked and not itemCETRAINERChecked then GetListFiles()
else if itemCTChecked and not itemCETRAINERChecked then GetListFilesCT()
else if not itemCTChecked and itemCETRAINERChecked then GetListFilesCETRAINER() end
end
end
end
end
function OnlyCT()
if itemCTChecked then
itemCTChecked = false
setProperty(itemCT, 'Checked', 'false')
else
itemCTChecked = true
setProperty(itemCT, 'Checked', 'true')
end
UpdateExtensions()
end
function OnlyCETRAINER()
if itemCETRAINERChecked then
itemCETRAINERChecked = false
setProperty(itemCETRAINER, 'Checked', 'false')
else
itemCETRAINERChecked = true
setProperty(itemCETRAINER, 'Checked', 'true')
end
UpdateExtensions()
end
function CreateNewFileCE(extension)
-- local tempText = [[
--<?xml version="1.0" encoding="utf-8"?>
--<CheatTable CheatEngineTableVersion="13">
--</CheatTable>]]
-- local fullName = path..'new'..extension
-- local file = io.open(path.."New."..extension, "w")
-- file:write(tempText)
-- file:close()
local strings = listbox_getItems(listBoxScripts)
local command = 'copy "'..pathAutorun..'New.'..extension..'"'..' "'..path..'New.'..extension..'"'
local countRecord = strings_getCount(strings)
io.popen(command)
UpdateExtensions()
strings = listbox_getItems(listBoxScripts)
if countRecord == strings_getCount(strings) then
print("Not CreateNewFileCE. 'New.cetrainer' or 'New.ct' File perhaps already")
end
end
function NewCTFile()
CreateNewFileCE('ct')
end
function NewCETRAINERFile()
CreateNewFileCE('cetrainer')
end
function SaveFileName(sender)
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local oldName = path..strings_getString(strings, itemIndexSelected)
local newName = path..control_getCaption(sender)
if oldName~=newName and os.rename(oldName, newName) then
UpdateExtensions()
else
print('not RenameFile')
end
end
-- todo: сообщение таймера на проверку keyUp влияет на фокус Edit
eventEditBoxtimer = nil
storyEditBox = nil
function OnUpKeyRenameFileEdit(sender)
local rezultButton = 0
if isKeyPressed(VK_ESCAPE) then
wincontrol_setFocus(listBoxScripts)
else
if isKeyPressed(VK_RETURN) then
SaveFileName(storyEditBox)
wincontrol_setFocus(listBoxScripts)
end
end
end
function CreateTimerEventKeyUp(editBox)
storyEditBox = editBox
eventEditBoxtimer = createTimer(editBox)
timer_setInterval(eventEditBoxtimer, 100)
timer_onTimer(eventEditBoxtimer, OnUpKeyRenameFileEdit)
timer_setEnabled(eventEditBoxtimer, true)
end
function OnLastFocusFileEdit(sender)
--SaveFileName(sender) мы не будем сохранять файл, если пользователь не подтвердил сохранение через Enter
timer_setEnabled(eventEditBoxtimer, false)
object_destroy(storyEditBox)
eventEditBoxtimer = nil
storyEditBox = nil
end
-- Event OnPopup
function OnShowPopupPlaginMenu(sender)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
if itemIndexSelected ~= -1 then
setProperty(itemRename, 'Enabled', 'true')
setProperty(itemConvertToCT, 'Enabled', 'true')
setProperty(itemConvertToCETRAINER, 'Enabled', 'true')
setProperty(itemDuplicate, 'Enabled', 'true')
setProperty(itemDeleteteFile, 'Enabled', 'true')
setProperty(itemDblClickOpenNotePad, 'Enabled', 'true')
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local nameWithExtension = strings_getString(strings, itemIndexSelected)
local pattern1 = "(%.ct)$"
local pattern2 = "(%.CT)$"
if string.find(nameWithExtension, pattern1) ~= nil or string.find(nameWithExtension, pattern2) ~= nil then
setProperty(itemConvertToCT, 'Enabled', 'false')
else
local pattern3 = "(%.cetrainer)$"
local pattern4 = "(%.CETRAINER)$"
if string.find(nameWithExtension, pattern3) ~= nil or string.find(nameWithExtension, pattern4) ~= nil then
setProperty(itemConvertToCETRAINER, 'Enabled', 'false')
else
setProperty(itemConvertToCETRAINER, 'Enabled', 'false')
setProperty(itemConvertToCT, 'Enabled', 'false')
end
end
else
setProperty(itemRename, 'Enabled', 'false')
setProperty(itemConvertToCT, 'Enabled', 'false')
setProperty(itemConvertToCETRAINER, 'Enabled', 'false')
setProperty(itemDuplicate, 'Enabled', 'false')
setProperty(itemDeleteteFile, 'Enabled', 'false')
setProperty(itemDblClickOpenNotePad, 'Enabled', 'false')
end
end
function RenameFile()
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
if itemIndexSelected ~= -1 then
local strings = listbox_getItems(listBoxScripts)
local oldName = strings_getString(strings, itemIndexSelected)
local heightLine = getProperty(listBoxScripts, 'ItemHeight')
--local heightLine = 13
local editName = createEdit(listBoxScripts)
control_setCaption(editName, oldName)
control_setPosition(editName, 0, itemIndexSelected*heightLine)
setProperty(editName, 'BorderStyle', 'bsNone')
setProperty(editName, 'AutoSize', 'false')
setProperty(editName, 'Color', 'clGradientActiveCaption')
control_setColor(editName, 0xA3F2FF) -- orange color
local w = 0
local h = 0
w, h = control_getSize(listBoxScripts)
control_setSize(editName, w, heightLine)
wincontrol_setFocus(editName)
wincontrol_onExit(editName, OnLastFocusFileEdit)
CreateTimerEventKeyUp(editName)
--[[
OriginalFunctionOnUpKeyRenameFileEdit = getMethodProperty(editName, 'OnKeyPress')
if OriginalFunctionOnUpKeyRenameFileEdit == nil then
print('nil')
else
print('not nil '.. OriginalFunctionOnUpKeyRenameFileEdit)
end]]--
--setMethodProperty(editName, 'OnKeyDown', OnUpKeyRenameFileEdit) --Press
-- : Sets the width and height of the control
--control_getSize(control) : Sets the size of the control
end
end
function ConvertToCT()
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local nameWithExtension = strings_getString(strings, itemIndexSelected)
--local pattern1 = "(%.ct)$"
--local pattern2 = "(%.CT)$"
local pattern1 = "(%.cetrainer)$"
local pattern2 = "(%.CETRAINER)$"
if string.find(nameWithExtension, pattern1) ~= nil or string.find(nameWithExtension, pattern2) ~= nil then
local newName = ''
if string.find(nameWithExtension, pattern1) ~= nil then
newName = path..string.gsub(nameWithExtension, '.cetrainer', ".ct")
else
newName = path..string.gsub(nameWithExtension, '.CETRAINER', ".CT")
end
local oldName = path..nameWithExtension
os.rename(oldName, newName)
UpdateExtensions()
else
print('not ConvertToCT from *.cetrainer or *.CETRAINER')
end
end
function ConvertToCETRAINER()
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local nameWithExtension = strings_getString(strings, itemIndexSelected)
local pattern1 = "(%.ct)$"
local pattern2 = "(%.CT)$"
--local pattern1 = "(%.cetrainer)$"
--local pattern2 = "(%.CETRAINER)$"
if string.find(nameWithExtension, pattern1) ~= nil or string.find(nameWithExtension, pattern2) ~= nil then
local newName = ''
if string.find(nameWithExtension, pattern1) ~= nil then
newName = path..string.gsub(nameWithExtension, '.ct', ".cetrainer")
print(newName)
else
newName = path..string.gsub(nameWithExtension, '.CT', ".CETRAINER")
print(newName)
end
local oldName = path..nameWithExtension
os.rename(oldName, newName)
UpdateExtensions()
else
print('not ConvertToCT from *.cetrainer or *.CETRAINER')
end
end
function DeleteRecord()
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local oldName = path..strings_getString(strings, itemIndexSelected)
local rez = messageDialog('Delete '..oldName..' ?' , mtConfirmation, mbYes,mbNo)
if rez == mrYes then
os.remove(oldName)
UpdateExtensions()
end
end
function DuplicateFile()
--print('DuplicateFile')
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local fileName = strings_getString(strings, itemIndexSelected)
local comand = 'copy "'..path..fileName..'"'..' "'..path..'Copy '..fileName..'"'
local countRecord = strings_getCount(strings)
io.popen(comand)
UpdateExtensions()
strings = listbox_getItems(listBoxScripts)
if countRecord == strings_getCount(strings) then
print("Not DuplicateFile")
end
end
function OnItemUpdateList()
UpdateExtensions()
end
function OnItemGotoDir()
io.popen('explorer '..path)
end
itemNewCT = AddMenuItemInPopupMenulistBoxScripts('New *.CT')
menuItem_onClick(itemNewCT, NewCTFile)
itemNewCETRAINER = AddMenuItemInPopupMenulistBoxScripts('New *.CETRAINER')
menuItem_onClick(itemNewCETRAINER, NewCETRAINERFile)
AddMenuItemInPopupMenulistBoxScripts('-')
itemDuplicate = AddMenuItemInPopupMenulistBoxScripts('Duplicate')
menuItem_onClick(itemDuplicate, DuplicateFile)
itemDeleteteFile= AddMenuItemInPopupMenulistBoxScripts('Delete script')
menuItem_onClick(itemDeleteteFile, DeleteRecord)
AddMenuItemInPopupMenulistBoxScripts('-')
itemConvertToCT = AddMenuItemInPopupMenulistBoxScripts('ConvertTo *.CT')
menuItem_onClick(itemConvertToCT, ConvertToCT)
itemConvertToCETRAINER = AddMenuItemInPopupMenulistBoxScripts('ConvertTo *.CETRAINER')
menuItem_onClick(itemConvertToCETRAINER, ConvertToCETRAINER)
itemRename = AddMenuItemInPopupMenulistBoxScripts('Rename')
menuItem_onClick(itemRename, RenameFile)
-- Выключать или включать Rename, если записи выделены или не выделены popupMenulistBoxScripts OnPopup OnShowPopupPlaginMenu
setMethodProperty(popupMenulistBoxScripts, 'OnPopup', OnShowPopupPlaginMenu)
-- Двойной клик по листБоксу связать с функцией RenameFile
setMethodProperty(listBoxScripts, 'OnDblClick', RenameFile)
AddMenuItemInPopupMenulistBoxScripts('-')
itemCETRAINER = AddMenuItemInPopupMenulistBoxScripts('Show *.CETRAINER')
menuItem_onClick(itemCETRAINER, OnlyCETRAINER)
setProperty(itemCETRAINER, 'Checked', 'true')
itemCT = AddMenuItemInPopupMenulistBoxScripts('Show *.CT')
menuItem_onClick(itemCT, OnlyCT)
setProperty(itemCT, 'Checked', 'true')
itemUpdateList = AddMenuItemInPopupMenulistBoxScripts('Update List')
menuItem_onClick(itemUpdateList, OnItemUpdateList)
itemGotoDir = AddMenuItemInPopupMenulistBoxScripts('Open scripts directory')
menuItem_onClick(itemGotoDir, OnItemGotoDir)
function OpenNotePad()
local strings = listbox_getItems(listBoxScripts)
local itemIndexSelected = listbox_getItemIndex(listBoxScripts)
local oldName = path..strings_getString(strings, itemIndexSelected)
--io.popen('notepad++ -lxml '..oldName) --io.popen('notepad++ -lxml '..oldName)
shellExecute('notepad++', ' -lxml "'..oldName..'"') --'-lxml '..
end
itemDblClickOpenNotePad = AddMenuItemInPopupMenulistBoxScripts('Open with NotePad++')
menuItem_onClick(itemDblClickOpenNotePad, OpenNotePad)
AddMenuItemInPopupMenulistBoxScripts('-')
local menuItemLang = AddMenuItemInPopupMenulistBoxScripts('Change current language: En')
setProperty(menuItemLang, 'Enabled', 'false')
function OpenSite()
io.popen("explorer http:\\\\Gamehacklab.ru")
end
local menuItemAbout = AddMenuItemInPopupMenulistBoxScripts('About: lua plugin v'..version..', http:\\\\GameHackLab.ru, 2012(c)')
menuItem_onClick(menuItemAbout, OpenSite)
--setProperty(menuItemAbout, 'Enabled', 'false')
--print(strings_getText(getPropertyList(separator)))
--print(getProperty(separator, 'Name'))
local eventEditScriptFilterTimer = createTimer(editScriptFilter)
timer_setInterval(eventEditScriptFilterTimer, 100)
timer_onTimer(eventEditScriptFilterTimer, OnUpKeyEditScriptFilter)
timer_setEnabled(eventEditScriptFilterTimer, true) |
|
|