local recentFiles = {} -- settings recentFiles.FileName = 'recentFiles.txt' recentFiles.NumberOfEntries = 25 recentFiles.IgnoreCETRAINER = false -- vars recentFiles.FileList = {} recentFiles.FileList_Sorted = {} local function insertRecentFileMenuItem(parent,position,caption) if parent==nil then return nil end local newItem = createMenuItem(parent) newItem.Caption = caption parent.insert(position,newItem) return newItem end function recentFiles.Show() if recentFiles.MenuMainItem==nil then local FileMenuItem = getMainForm().Menu.Items[0] local position = FileMenuItem.Count - 1 insertRecentFileMenuItem(FileMenuItem,position,'-') insertRecentFileMenuItem(FileMenuItem,position,'Clear Recent File List').OnClick = function (sender) if messageDialog("Are you sure?", mtConfirmation, mbYes, mbNo)~=mrYes then return end recentFiles.FileList = {} recentFiles.Save() end recentFiles.MenuMainItem = insertRecentFileMenuItem(FileMenuItem,position,'Recent Files') end while recentFiles.MenuMainItem.Count > 0 do recentFiles.MenuMainItem[0].destroy() end local from = math.min(#recentFiles.FileList_Sorted,recentFiles.NumberOfEntries) recentFiles.MenuMainItem.Enabled = from > 0 for i=from,1,-1 do insertRecentFileMenuItem(recentFiles.MenuMainItem,0,recentFiles.FileList_Sorted[i].k).OnClick = function (sender) local file = io.open( utf8ToAnsi(recentFiles.FileList_Sorted[i].k) ,'r') if file==nil then messageDialog("File "..recentFiles.FileList_Sorted[i].k.." doesn't exist. Entry will be removed from the list.", mtInformation,mbOK) recentFiles.FileList[recentFiles.FileList_Sorted[i].k] = nil recentFiles.Save() return else file:close() end local dir = recentFiles.FileList_Sorted[i].k:match([[.*%\]]) local filename = recentFiles.FileList_Sorted[i].k:sub(#dir+1) getMainForm().OpenDialog1.Filename = filename getMainForm().OpenDialog1.InitialDir = dir getMainForm().LoadButton.doClick() end end end function recentFiles.Save() local file = io.open(getCheatEngineDir()..recentFiles.FileName,"w") if file then recentFiles.FileList_Sorted = {} for k,v in pairs(recentFiles.FileList) do recentFiles.FileList_Sorted[#recentFiles.FileList_Sorted+1] = {['k']=k,['v']=v} end table.sort(recentFiles.FileList_Sorted, function (a,b) return a.v < b.v end) if #recentFiles.FileList_Sorted==0 then file:write('') end for i=1,#recentFiles.FileList_Sorted do file:write(recentFiles.FileList_Sorted[i].k.."\n") end file:close() end recentFiles.Show() end function recentFiles.Load() local file = io.open(getCheatEngineDir()..recentFiles.FileName, "r") if file then local pos = 1 for line in file:lines() do recentFiles.FileList[line] = pos pos = pos + 1 end file:close() end recentFiles.FileList_Sorted = {} for k,v in pairs(recentFiles.FileList) do recentFiles.FileList_Sorted[v] = {['k']=k,['v']=v} end recentFiles.Show() end -- ONPOSTLOADTABLE local function onPostLoadTable(filename,result) if (result == mrCancel) or (filename == '') then return end if recentFiles.IgnoreCETRAINER and filename:sub(-3):upper()~='.CT' then return end for k,v in pairs(recentFiles.FileList) do if k~=filename then recentFiles.FileList[k] = v + 1 end -- update positions end recentFiles.FileList[filename] = 1 -- bring to front recentFiles.Save() end local actOpenExecute = getMainForm().Load1.OnClick local function openWithButtonOrMenu(sender) local dialogResultOffset = cheatEngineIs64Bit() and 0xB8 or 0x64 if getCEVersion()>=7.0 then dialogResultOffset = cheatEngineIs64Bit() and 0xD8 or 0x70 end actOpenExecute(sender) local dialogResult = readIntegerLocal(userDataToInteger(getMainForm().OpenDialog1)+dialogResultOffset) --mrOK, mrCancel local filename = getMainForm().OpenDialog1.Filename onPostLoadTable(filename,dialogResult) end getMainForm().LoadButton.OnClick = openWithButtonOrMenu -- button getMainForm().Load1.OnClick = openWithButtonOrMenu -- menu getMainForm().LoadButton.Action = nil getMainForm().Load1.Action = nil -- init and load recentFiles recentFiles.Load()