Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Main.ddp
Binary file not shown.
Binary file modified Main.dfm
Binary file not shown.
134 changes: 104 additions & 30 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,9 @@ TMainForm = class(TForm)
Sessions: Integer;
History: string;
CDROM: Boolean;
ReadParamFile: Boolean;
ReadParamFile: Boolean;//CMDLINE_OP
resultCMD: Integer;//CMDLINE_OP
ReadParamCMD: string;
RecentFiles: TStringList;
WinLeft, WinTop, WinWidth, WinHeight: Integer; // 2.55
TileSelX1, TileSelY1, // 2.0
Expand Down Expand Up @@ -8950,8 +8952,9 @@ procedure TMainForm.Generate1Click(Sender: TObject);

// options
StartWithEmptyTile: Boolean;
ExportDuplicateTiles: Boolean; // ignore unique tile check


RunCMDLine: string; // run command line

const
MAX_COUNTER = 100;
Expand Down Expand Up @@ -12037,7 +12040,8 @@ procedure TMainForm.Generate1Click(Sender: TObject);


StartWithEmptyTile := FALSE;

ExportDuplicateTiles := FALSE; // ignore unique tile check

SetNumVar ('TRUE', 1);
SetNumVar ('FALSE', 0);

Expand Down Expand Up @@ -13164,30 +13168,73 @@ procedure TMainForm.Generate1Click(Sender: TObject);
var
i: Integer;
s: string;
begin
begin

for i := 0 to lines.Count - 1 do
begin
s := UpCaseStr (Trim(lines.Strings[i]));
if (s <> '') then
begin
if (s[1] = '!') then
begin
Delete (s, 1, 1);


if (s <> '') then
begin
if (s[1] = '!') then
begin
Delete (s, 1, 1);

if (s = 'RUNCMDLINE') then // run command line
begin
RunCMDLine := UpCaseStr (Trim(lines.Strings[i+1])); // read next line
Delete (RunCMDLine, 1, 1); // remove first char
end;

if (s = 'STARTWITHEMPTYTILE') then
begin
StartWithEmptyTile := TRUE;
end;

if (s = 'EXPORTDUPLICATETILES') then
begin
ExportDuplicateTiles := TRUE; // ignore unique tile check
end;



end;
end;

end;
end;


// from https://stackoverflow.com/questions/32211723/why-delphi-app-cant-run-a-bat-file-and-make-it-work?noredirect=1&lq=1
procedure StartProcess(ExeName: string; CmdLineArgs: string = ''; ShowWindow: boolean = True; WaitForFinish: boolean = False);
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
//Simple wrapper for the CreateProcess command
//returns the process id of the started process.
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);

if (s = 'STARTWITHEMPTYTILE') then
StartWithEmptyTile := TRUE;
if not(ShowWindow) then begin
StartInfo.dwFlags := STARTF_USESHOWWINDOW;
StartInfo.wShowWindow := SW_HIDE;
end;

CreateProcess(nil,PChar(ExeName + ' ' + CmdLineArgs),nil,nil,False,
CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS,nil,nil,StartInfo,
ProcInfo);

end;
end;
end;
//Result := ProcInfo.dwProcessId;

if WaitForFinish then begin
WaitForSingleObject(ProcInfo.hProcess,Infinite);
end;


//close process & thread handles
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;

{ TMainForm.Generate1Click }

Expand Down Expand Up @@ -13392,7 +13439,7 @@ procedure TMainForm.Generate1Click(Sender: TObject);
for j := 0 to N - 1 do
if not found then
begin
diff := FALSE;
diff := ExportDuplicateTiles; // ignore unique tile check
for y := 0 to tbr.H - 1 do
if not diff then
for x := 0 to tbr.W - 1 do
Expand Down Expand Up @@ -13677,25 +13724,36 @@ procedure TMainForm.Generate1Click(Sender: TObject);
// generate the code

ErrMsg := RunCode;



for itab := 0 to Tab.Tabs.Count - 1 do
with TileTab[itab].tbr do
begin
W := LastW;
H := LastH;
end;


if ErrMsg <> '' then
ShowMessage (ErrMsg)
else
begin
with ProgressBar do
Position := Max;
ShowMessage ('Code generated successfully');
end;

// CMDLINE_OP
if ReadParamCMD <> 'F10' then
begin


// run cmd line if not empty and no errors
if (RunCMDLine <> '') AND (ErrMsg = '') then
begin
// StartProcess(ExeName: string; CmdLineArgs: string = ''; ShowWindow: boolean = True; WaitForFinish: boolean = False);
StartProcess('cmd.exe', '/C ' + RunCMDLine, TRUE, TRUE); // execute, show window and wait?
end;

if ErrMsg <> '' then
ShowMessage (ErrMsg)
else
begin
with ProgressBar do
Position := Max;
ShowMessage ('Code generated successfully');
end;
end;
// CMDLINE_OP

// clean up and release memory

Expand Down Expand Up @@ -14742,6 +14800,22 @@ procedure TMainForm.FormShow(Sender: TObject);
begin
Modified := FALSE;
Open1Click (nil);
//CMDLINE_OP
ReadParamFile := ParamCount > 1;
if ReadParamFile then
begin


ReadParamCMD := ParamStr(2);

if ReadParamCMD = 'F10' then
begin
Generate1Click(Self);
Modified := FALSE;
Exit1Click(Self);
end;
end;
//CMDLINE_OP
end;
ReadParamFile := FALSE;
end;
Expand Down
Loading