| 1 |
{ |
| 2 |
Copyright 2018-2022 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Project-related castle-editor utilities. } |
| 17 |
unit ProjectUtils; |
| 18 |
|
| 19 |
{$mode objfpc}{$H+} |
| 20 |
|
| 21 |
interface |
| 22 |
|
| 23 |
uses |
| 24 |
Classes, SysUtils; |
| 25 |
|
| 26 |
{ Fill directory for new project with the build-tool generated stuff. } |
| 27 |
procedure GenerateProgramWithBuildTool(const ProjectDirUrl: String); |
| 28 |
|
| 29 |
type |
| 30 |
TBuildMode = (bmDebug, bmRelease); |
| 31 |
|
| 32 |
{ For some operations (like creating a project from template), the editor uses |
| 33 |
ApplicationData files (castle-data:/xxx URLs). |
| 34 |
So make sure that ApplicationData is correct, by setting ApplicationDataOverride. |
| 35 |
We can use CastleEnginePath (that uses $CASTLE_ENGINE_PATH environment variable) |
| 36 |
for this. } |
| 37 |
procedure UseEditorApplicationData; |
| 38 |
|
| 39 |
implementation |
| 40 |
|
| 41 |
uses Forms, |
| 42 |
CastleUriUtils, CastleStringUtils, CastleFindFiles, CastleUtils, |
| 43 |
CastleFilesUtils, |
| 44 |
EditorUtils, ToolCommonUtils, FormProject; |
| 45 |
|
| 46 |
|
| 47 |
procedure GenerateProgramWithBuildTool(const ProjectDirUrl: String); |
| 48 |
var |
| 49 |
BuildToolExe, BuildToolOutput: String; |
| 50 |
BuildToolStatus: integer; |
| 51 |
NewEnvironment: TStringList; |
| 52 |
begin |
| 53 |
BuildToolExe := FindExeCastleTool('castle-engine'); |
| 54 |
if BuildToolExe = '' then |
| 55 |
begin |
| 56 |
WarningBox('Cannot find build tool (castle-engine) on $PATH environment variable. You will need to manually run "castle-engine generate-program" within project''s directory.'); |
| 57 |
Exit; |
| 58 |
end; |
| 59 |
|
| 60 |
{ Pass CASTLE_ENGINE_PATH to build tool, to use the same CGE as detected by editor. |
| 61 |
This means that e.g. editor that autodetects CGE (based on GetCastleEnginePathFromExeName, |
| 62 |
because editor exe is in <cge>/tools/castle-editor/castle-editor) |
| 63 |
invokes build tool in local bin (like ~/bin) |
| 64 |
and the build tool uses the same <cge> as detected by editor. } |
| 65 |
NewEnvironment := nil; |
| 66 |
if CastleEnginePath <> '' then |
| 67 |
begin |
| 68 |
NewEnvironment := EnvironmentStrings; |
| 69 |
NewEnvironment.Values['CASTLE_ENGINE_PATH'] := CastleEnginePath; |
| 70 |
end; |
| 71 |
|
| 72 |
MyRunCommandIndir(UriToFilenameSafe(ProjectDirUrl), BuildToolExe, |
| 73 |
['generate-program'], BuildToolOutput, BuildToolStatus, nil, nil, |
| 74 |
// prevent from blinking console on Windows |
| 75 |
[rcNoConsole], |
| 76 |
NewEnvironment); |
| 77 |
if BuildToolStatus <> 0 then |
| 78 |
begin |
| 79 |
WarningBox(Format('Generating program with the build tool failed with status code %d and output: "%s"', |
| 80 |
[BuildToolStatus, BuildToolOutput])); |
| 81 |
Exit; |
| 82 |
end; |
| 83 |
end; |
| 84 |
|
| 85 |
procedure UseEditorApplicationData; |
| 86 |
var |
| 87 |
DataPath: string; |
| 88 |
begin |
| 89 |
{ start by resetting ApplicationDataOverride to empty, to reset |
| 90 |
previous customizations of ApplicationDataOverride done by some editor code. } |
| 91 |
ApplicationDataOverride := ''; |
| 92 |
|
| 93 |
if CastleEnginePath <> '' then |
| 94 |
begin |
| 95 |
DataPath := CastleEnginePath + |
| 96 |
'tools' + PathDelim + 'castle-editor' + PathDelim + 'data' + PathDelim; |
| 97 |
if DirectoryExists(DataPath) then |
| 98 |
ApplicationDataOverride := FilenameToUriSafe(DataPath); |
| 99 |
end; |
| 100 |
end; |
| 101 |
|
| 102 |
end. |