Skip to content

Commit

Permalink
add a load recent menuitem
Browse files Browse the repository at this point in the history
  • Loading branch information
cheat-engine committed Aug 3, 2020
1 parent 171595e commit 46f8a85
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cheat Engine/AdvancedOptionsUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ procedure TAdvancedOptions.lvCodelistDragDrop(Sender, Source: TObject; X,
for i:=0 to selecteditems.Count-1 do
tlistitem(selectedItems[i]).Selected:=true;

mainform.editedsincelastsave:=true;
end;

end;
Expand Down
4 changes: 4 additions & 0 deletions Cheat Engine/MainUnit.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,10 @@ object MainForm: TMainForm
ImageIndex = 6
OnClick = actOpenExecute
end
object miLoadRecent: TMenuItem
Caption = 'Load Recent'
OnClick = miLoadRecentClick
end
object miSignTable: TMenuItem
Caption = 'Sign table'
ImageIndex = 27
Expand Down
71 changes: 68 additions & 3 deletions Cheat Engine/MainUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ TMainForm = class(TForm)
FromAddress: TEdit;
andlabel: TLabel;
lblcompareToSavedScan: TLabel;
miLoadRecent: TMenuItem;
miAlwaysHideChildren: TMenuItem;
miFoundListPreferences: TMenuItem;
N2: TMenuItem;
Expand Down Expand Up @@ -565,6 +566,7 @@ TMainForm = class(TForm)
procedure Label3Click(Sender: TObject);
procedure MenuItem12Click(Sender: TObject);
procedure MenuItem15Click(Sender: TObject);
procedure miLoadRecentClick(Sender: TObject);
procedure miFoundListPreferencesClick(Sender: TObject);
procedure miAutoAssembleErrorMessageClick(Sender: TObject);
procedure miHelpClick(Sender: TObject);
Expand Down Expand Up @@ -822,6 +824,9 @@ TMainForm = class(TForm)

showStaticAsStatic: boolean;

RecentFiles: Tstringlist;

procedure RecentFilesClick(Sender:TObject);
procedure CheckForSpeedhackKey(sender: TObject);

procedure doNewScan;
Expand Down Expand Up @@ -920,6 +925,8 @@ TMainForm = class(TForm)

function getUseThreadToFreeze: boolean;
procedure setUseThreadToFreeze(state: boolean);

procedure recentFilesUpdate(filepath: string);
public
{ Public declarations }
addresslist: TAddresslist;
Expand Down Expand Up @@ -1366,6 +1373,26 @@ constructor TFreezeThread.Create(AddressList: TAddresslist; interval: integer);

//--------------TMainThread------------

procedure TMainForm.recentFilesUpdate(filepath: string);
var i: integer;
begin
i:=recentfiles.IndexOf(filepath);
if i<>-1 then
begin
//move the old entry to the top
recentfiles.Delete(i);
recentfiles.Insert(0,filepath);
end
else
begin
//new entry
recentfiles.insert(0, filepath);
while recentfiles.count>10 do
recentfiles.Delete(recentfiles.count-1);
end;
cereg.writeStrings('Recent Files', recentfiles);
end;

function TMainForm.getUseThreadToFreeze: boolean;
begin
result:=freezeThread<>nil;
Expand Down Expand Up @@ -3512,6 +3539,11 @@ procedure TMainForm.MenuItem15Click(Sender: TObject);
end;
end;

procedure TMainForm.miLoadRecentClick(Sender: TObject);
begin

end;

procedure TMainForm.miFoundListPreferencesClick(Sender: TObject);
var
f: TfrmFoundlistPreferences;
Expand Down Expand Up @@ -3665,7 +3697,11 @@ procedure TMainForm.miManualExpandCollapseClick(Sender: TObject);
procedure TMainForm.miSaveClick(Sender: TObject);
begin
if fileexists(savedialog1.FileName) then
savetable(savedialog1.FileName, false)
begin
savetable(savedialog1.FileName, false);

recentFilesUpdate(savedialog1.filename);
end
else
actSave.Execute;
end;
Expand Down Expand Up @@ -5542,7 +5578,7 @@ procedure TMainForm.FormCreate(Sender: TObject);

errormode: dword;
minworkingsize, maxworkingsize: ptruint;
reg: tregistry;
//reg: tregistry;

PODirectory, Lang, FallbackLang: string;

Expand Down Expand Up @@ -5989,6 +6025,10 @@ procedure TMainForm.FormCreate(Sender: TObject);
foundlistColors.DynamicColor:=GetSysColor(COLOR_WINDOWTEXT);
showStaticAsStatic:=true;

RecentFiles:=tstringlist.Create;
cereg.readStrings('Recent Files', RecentFiles);



{$ifdef darwin}
cbDirty:=TCheckBox.create(self);
Expand Down Expand Up @@ -8690,6 +8730,8 @@ procedure TMainForm.actOpenExecute(Sender: TObject);

UserDefinedTableName:=Opendialog1.filename;
reinterpretaddresses;

recentFilesUpdate(Opendialog1.filename);
except
on e:exception do
MessageDlg('This table failed to load: '+e.message,mtError,[mbok],0);
Expand Down Expand Up @@ -8732,6 +8774,8 @@ procedure TMainForm.actSaveExecute(Sender: TObject);
SaveIntialTablesDir(extractfilepath(savedialog1.filename));

UserDefinedTableName:=savedialog1.filename;

recentFilesUpdate(savedialog1.filename);
end
else Savedialog1.FileName:=oldFileName;
end;
Expand Down Expand Up @@ -10395,10 +10439,31 @@ procedure TMainForm.ClearList;
addresslist.Clear;
end;

procedure TMainForm.File1Click(Sender: TObject);
procedure TMainForm.RecentFilesClick(Sender:TObject);
begin
if CheckIfSaved then
LoadTable(RecentFiles[tmenuitem(sender).Tag],false);
end;

procedure TMainForm.File1Click(Sender: TObject);
var
i: integer;
m: TMenuItem;
begin
miSaveScanresults.Enabled := memscan.nextscanCount > 0;
miLoadRecent.Visible:=RecentFiles.Count>0;

miLoadRecent.Clear;
for i:=0 to RecentFiles.count-1 do
begin
m:=tmenuitem.Create(miLoadRecent);
m.Caption:=RecentFiles[i];
m.OnClick:=RecentFilesClick;
m.tag:=i;

miLoadRecent.Add(m);
end;

end;

procedure TMainForm.actOpenProcesslistExecute(Sender: TObject);
Expand Down
27 changes: 27 additions & 0 deletions Cheat Engine/ceregistry.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ TCEReg=class
function readInteger(registryValueName:string; def: integer=0): integer;
procedure writeString(registryValueName: string; value: string);
function readString(registryValueName:string; def: string=''): string;
procedure writeStrings(registryValueName: string; sl: TStrings);
procedure readStrings(registryValueName: string; sl: TStrings);

end;

var cereg: TCEReg;
Expand Down Expand Up @@ -76,6 +79,30 @@ function TCEReg.getRegistry(force: boolean):boolean;
result:=openedregistry;
end;

procedure TCEReg.writeStrings(registryValueName: string; sl: TStrings);
begin
if getregistry(true) then
begin
try
reg.WriteStringList(registryValueName, sl);
except
end;
end;
end;

procedure TCEReg.readStrings(registryValueName: string; sl: TStrings);
begin
sl.Clear;

if getregistry(false) and (reg.ValueExists(registryValueName)) then
begin
try
reg.ReadStringList(registryValueName, sl);
except
end;
end;
end;

function TCEReg.readBool(registryValueName: string; def: boolean=false): boolean;
begin
result:=def;
Expand Down
2 changes: 1 addition & 1 deletion Cheat Engine/cheatengine.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="7"/>
<MinorVersionNr Value="1"/>
<BuildNr Value="6380"/>
<BuildNr Value="6395"/>
<Language Value=""/>
<CharSet Value=""/>
<StringTable CompanyName="Cheat Engine" FileDescription="Cheat Engine" ProductVersion="7.1"/>
Expand Down

0 comments on commit 46f8a85

Please sign in to comment.