-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFEProjectBuildSystem.cpp
More file actions
489 lines (409 loc) · 20 KB
/
FEProjectBuildSystem.cpp
File metadata and controls
489 lines (409 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#include "FEProjectBuildSystem.h"
using namespace FocalEngine;
FEProjectBuildSystem::FEProjectBuildSystem()
{
}
FEProjectBuildSystem::~FEProjectBuildSystem()
{
}
std::string FEProjectBuildSystem::GetVSProjectName(FEProject* ProjectToBuild)
{
if (ProjectToBuild == nullptr)
{
LOG.Add("FEProjectBuildSystem::GetVSProjectName: ProjectToBuild is nullptr!", "FE_LOG_LOADING", FE_LOG_ERROR);
return "";
}
std::string AppropriateProjectName = ProjectToBuild->GetName();
for (size_t i = 0; i < AppropriateProjectName.size(); i++)
{
if (AppropriateProjectName[i] == ' ')
AppropriateProjectName[i] = '_';
}
if (AppropriateProjectName.empty())
AppropriateProjectName = "UntitledProject";
return AppropriateProjectName;
}
bool FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles(const std::string& OutputPath)
{
if (!FILE_SYSTEM.DoesDirectoryExist(OutputPath))
{
LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: OutputPath does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Create all needed folders.
std::vector<std::string> FoldersToCreate = { "VisualNodeSystem/"};
for (size_t i = 0; i < FoldersToCreate.size(); i++)
{
if (!FILE_SYSTEM.CreateDirectory(OutputPath + FoldersToCreate[i]))
{
LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error creating " + FoldersToCreate[i] + " directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
// Place required files in the destination directory.
std::string EditorPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/";
std::string VisualNodeSystemPath = EditorPath + "SubSystems/NodeSystem/VisualNodeSystem/";
std::vector<std::pair<std::string, std::string>> FilesToCopy;
FilesToCopy.push_back({ VisualNodeSystemPath + "CMakeLists.txt", OutputPath + "VisualNodeSystem/CMakeLists.txt" });
// Add all source files to the list.
std::vector<std::string> FilesInMainFolder = FILE_SYSTEM.GetFileList(VisualNodeSystemPath);
for (size_t i = 0; i < FilesInMainFolder.size(); i++)
{
if (FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 2) == ".h" ||
FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 4) == ".hpp" ||
FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 4) == ".inl" ||
FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 4) == ".cpp" ||
FilesInMainFolder[i].substr(FilesInMainFolder[i].size() - 2) == ".c")
{
FilesToCopy.push_back({ VisualNodeSystemPath + FilesInMainFolder[i], OutputPath + "VisualNodeSystem/" + FilesInMainFolder[i] });
}
}
for (size_t i = 0; i < FilesToCopy.size(); i++)
{
if (!FILE_SYSTEM.CopyFile(FilesToCopy[i].first, FilesToCopy[i].second))
{
LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error copying file " + FilesToCopy[i].first + " to " + FilesToCopy[i].second, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
if (!FILE_SYSTEM.CopyDirectory(VisualNodeSystemPath + "SubSystems/",
OutputPath + "VisualNodeSystem/SubSystems/"))
{
LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!FILE_SYSTEM.CopyDirectory(VisualNodeSystemPath + "ThirdParty/",
OutputPath + "VisualNodeSystem/ThirdParty/"))
{
LOG.Add("FEProjectBuildSystem::CopyVisualNodeSystemSubProjectFiles: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
return true;
}
bool FEProjectBuildSystem::BuildExecutable(FEProject* ProjectToBuild)
{
if (ProjectToBuild == nullptr)
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: ProjectToBuild is nullptr!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
std::string VSProjectDirectory = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/";
if (FILE_SYSTEM.DoesDirectoryExist(VSProjectDirectory))
{
if (!FILE_SYSTEM.DeleteDirectory(VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error deleting BuildProjects_Temporary directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
if (!FILE_SYSTEM.CreateDirectory(VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating BuildProjects_Temporary directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
VSProjectDirectory += ProjectToBuild->GetID() + "/";
if (!FILE_SYSTEM.CreateDirectory(VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating project directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!FILE_SYSTEM.DoesDirectoryExist(VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: VSProjectDirectory does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
FEAssetPackage* Resources = ProjectToBuild->SaveResourcesToAssetPackage();
Resources->SaveToFile(VSProjectDirectory + "/Resources.fepackage");
// Create all needed folders.
std::vector<std::string> FoldersToCreate = { "SubSystems/",
"SubSystems/FocalEngine",
"ScriptModules/",
"SubSystems/FocalEngine/ResourceManager",
"SubSystems/FocalEngine/SubSystems",
"SubSystems/FocalEngine/ThirdParty",
"SubSystems/FocalEngine/ThirdParty/openxr",
"SubSystems/FocalEngine/SubSystems/FEBasicApplication",
"SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty",
"SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW",
"SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/glew2" };
for (size_t i = 0; i < FoldersToCreate.size(); i++)
{
if (!FILE_SYSTEM.CreateDirectory(VSProjectDirectory + FoldersToCreate[i]))
{
LOG.Add("FEProjectBuildSystem::InitializeProject: Error creating " + FoldersToCreate[i] + " directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
// Place required files in the destination directory.
std::string EditorPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/";
std::vector<std::pair<std::string, std::string>> FilesToCopy;
FilesToCopy.push_back({ EditorPath + "/Resources/BuildScripts/Main_Template.cpp", VSProjectDirectory + "Main.cpp" });
FilesToCopy.push_back({ EditorPath + "/Resources/BuildScripts/Main_Template.h", VSProjectDirectory + "Main.h" });
FilesToCopy.push_back({ EditorPath + "/Resources/BuildScripts/CMakeLists_Template.txt", VSProjectDirectory + "CMakeLists.txt" });
std::string EnginePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/" + std::string(ENGINE_FOLDER) + "/";
FilesToCopy.push_back({ EnginePath + "CMakeLists.txt", VSProjectDirectory + "SubSystems/FocalEngine/CMakeLists.txt" });
FilesToCopy.push_back({ EnginePath + "UpdateTimestamp.cmake", VSProjectDirectory + "SubSystems/FocalEngine/UpdateTimestamp.cmake" });
FilesToCopy.push_back({ EnginePath + "ResourceManager/Config.h.in", VSProjectDirectory + "SubSystems/FocalEngine/ResourceManager/Config.h.in" });
FilesToCopy.push_back({ EnginePath + "ResourceManager/Timestamp.h.in", VSProjectDirectory + "SubSystems/FocalEngine/ResourceManager/Timestamp.h.in" });
FilesToCopy.push_back({ EnginePath + "SubSystems/FEBasicApplication/CMakeLists.txt", VSProjectDirectory + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/CMakeLists.txt" });
for (size_t i = 0; i < FilesToCopy.size(); i++)
{
if (!FILE_SYSTEM.CopyFile(FilesToCopy[i].first, FilesToCopy[i].second))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error copying file " + FilesToCopy[i].first + " to " + FilesToCopy[i].second, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
if (!FILE_SYSTEM.CopyDirectory(EnginePath + "/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib",
VSProjectDirectory + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/GLFW/lib"))
{
LOG.Add("FEProjectBuildSystem::InitializeProject: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!FILE_SYSTEM.CopyDirectory(EnginePath + "/SubSystems/FEBasicApplication/ThirdParty/glew2/lib",
VSProjectDirectory + "SubSystems/FocalEngine/SubSystems/FEBasicApplication/ThirdParty/glew2/lib"))
{
LOG.Add("FEProjectBuildSystem::InitializeProject: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!FILE_SYSTEM.CopyDirectory(EnginePath + "/ThirdParty/openxr/Lib",
VSProjectDirectory + "SubSystems/FocalEngine/ThirdParty/openxr/Lib"))
{
LOG.Add("FEProjectBuildSystem::InitializeProject: Error copying directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!CopyVisualNodeSystemSubProjectFiles(VSProjectDirectory + "/SubSystems/"))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error copying VisualNodeSystem sub project files", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
FEAssetPackage* EngineResources = RESOURCE_MANAGER.CreatePrivateEngineAssetPackage();
if (EngineResources == nullptr)
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating private engine asset package", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
EngineResources->SaveToFile(VSProjectDirectory + "/EngineResources.fepackage");
if (!InitializeCMakeFileAndScriptFiles(ProjectToBuild, VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::InitializeProject: Error initializing CMakeLists.txt", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Copy the engine files to the temporary directory
if (!RESOURCE_MANAGER.CopyEngineFiles(true, true, false, VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error copying engine files", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Build the executable
if (!ConfigureAndBuildCMake(VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error configuring and building VS Project", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!CreateFinalExecutableDirectory(ProjectToBuild))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error creating final executable directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Delete the temporary directory
if (!FILE_SYSTEM.DeleteDirectory(VSProjectDirectory))
{
LOG.Add("FEProjectBuildSystem::BuildExecutable: Error deleting temporary directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
return true;
}
bool FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles(FEProject* ProjectToBuild, const std::string& VSProjectDirectory)
{
if (ProjectToBuild == nullptr)
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: ProjectToBuild is nullptr!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (VSProjectDirectory.empty())
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: path is empty", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING);
return false;
}
std::vector<std::string> NativeScriptModuleIDList = RESOURCE_MANAGER.GetNativeScriptModuleIDList();
std::string CMakeFilePath = VSProjectDirectory + "CMakeLists.txt";
std::vector<FEFileSystem::TextReplacementRule> Instructions;
FEFileSystem::TextReplacementRule CurrentInstruction;
CurrentInstruction.ContextPattern = "set(PROJECT_NAME PLACE_HOLDER)";
CurrentInstruction.TargetText = "PLACE_HOLDER";
CurrentInstruction.ReplacementText = GetVSProjectName(ProjectToBuild);
Instructions.push_back(CurrentInstruction);
std::string SourceFileListString = "";
std::string ExecutableListString = "";
std::string FolderListInVSProjectString = "";
for (size_t i = 0; i < NativeScriptModuleIDList.size(); i++)
{
FENativeScriptModule* CurrentModule = RESOURCE_MANAGER.GetNativeScriptModule(NativeScriptModuleIDList[i]);
if (CurrentModule == nullptr)
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error getting native script module with ID: " + NativeScriptModuleIDList[i], "FE_BUILD_EXECUTABLE", FE_LOG_WARNING);
continue;
}
if (CurrentModule->GetProject() == nullptr)
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error getting project of native script module with ID: " + NativeScriptModuleIDList[i], "FE_BUILD_EXECUTABLE", FE_LOG_WARNING);
continue;
}
if (!CurrentModule->GetProject()->HasRecoverableVSProjectData())
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Project of native script module with ID: " + NativeScriptModuleIDList[i] + " does not have recoverable VS project data", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING);
continue;
}
std::vector<std::string> SourceFileList = CurrentModule->GetProject()->GetSourceFileList();
if (SourceFileList.empty())
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: SourceFileList is empty for native script module with ID: " + NativeScriptModuleIDList[i], "FE_BUILD_EXECUTABLE", FE_LOG_WARNING);
continue;
}
std::string CurrentString = "file(GLOB Script_Module_" + CurrentModule->GetObjectID() + "_SRC\n";
for (size_t i = 0; i < SourceFileList.size(); i++)
{
CurrentString += std::string("\t\"") + "ScriptModules/" + CurrentModule->GetObjectID() + "/" + SourceFileList[i] + "\"\n";
}
CurrentString += ")\n";
CurrentString += "\n";
SourceFileListString += CurrentString;
// Replace the placeholder in add_executable list.
CurrentString = std::string("\t\t") + "${Script_Module_" + CurrentModule->GetObjectID() + "_SRC}\n";
ExecutableListString += CurrentString;
// Add the folder to the list of folders in VS project.
FolderListInVSProjectString += "source_group(\"Source Files/ScriptModules/" + CurrentModule->GetObjectID() + "/\" FILES ${Script_Module_" + CurrentModule->GetObjectID() + "_SRC})\n";
// Now we will create the directories and copy the files to the destination directory.
std::string ScriptModuleDirectory = VSProjectDirectory + "ScriptModules/" + CurrentModule->GetObjectID() + "/";
if (!FILE_SYSTEM.CreateDirectory(ScriptModuleDirectory))
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error creating directory " + ScriptModuleDirectory, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!CurrentModule->GetProject()->ExtractSourceFilesTo(ScriptModuleDirectory))
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error extracting source files to " + ScriptModuleDirectory, "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
CurrentInstruction.ContextPattern = "#(PLACE_HOLDER) Here should be list of all script modules sources.";
CurrentInstruction.TargetText = "#(PLACE_HOLDER) Here should be list of all script modules sources.";
CurrentInstruction.ReplacementText = SourceFileListString;
Instructions.push_back(CurrentInstruction);
CurrentInstruction.ContextPattern = " #(PLACE_HOLDER) Here should be list of all script modules.";
CurrentInstruction.TargetText = " #(PLACE_HOLDER) Here should be list of all script modules.";
CurrentInstruction.ReplacementText = ExecutableListString;
Instructions.push_back(CurrentInstruction);
CurrentInstruction.ContextPattern = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project.";
CurrentInstruction.TargetText = "#(PLACE_HOLDER) Here should be list of all script modules and where to place them in VS project.";
CurrentInstruction.ReplacementText = FolderListInVSProjectString;
Instructions.push_back(CurrentInstruction);
if (!FILE_SYSTEM.PerformTextReplacements(CMakeFilePath, Instructions))
{
LOG.Add("FEProjectBuildSystem::InitializeCMakeFileAndScriptFiles: Error initializing CMakeLists.txt", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
Instructions.clear();
return true;
}
bool FEProjectBuildSystem::ConfigureAndBuildCMake(const std::string& VSProjectDirectory)
{
if (VSProjectDirectory.empty())
{
LOG.Add("FEProjectBuildSystem::ConfigureAndBuildCMake: VSProjectDirectory is empty", "FE_BUILD_EXECUTABLE", FE_LOG_WARNING);
return false;
}
std::string Generator = "Visual Studio 17 2022";
// CMake configure command.
std::string ConfigureCommand = "cmake -S \"" + VSProjectDirectory + "\" -B \"" + VSProjectDirectory + "\" -G \"" + Generator + "\"";
// Execute CMake configure command.
int ConfigureResult = std::system(ConfigureCommand.c_str());
if (ConfigureResult != 0)
{
LOG.Add("FEProjectBuildSystem::ConfigureAndBuildCMake: Error running CMake configure command", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Construct the CMake build command
std::string BuildCommand = "cmake --build \"" + VSProjectDirectory + "\" --config Release";
// Execute CMake build command
int BuildResult = std::system(BuildCommand.c_str());
if (BuildResult != 0)
{
LOG.Add("FEProjectBuildSystem::ConfigureAndBuildCMake: Error running CMake build command", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
return true;
}
std::string NormalizePathToWindows(const std::string& Path)
{
std::filesystem::path FSPath(Path);
std::string Normalized = FSPath.make_preferred().string();
// Replace remaining forward slashes with backslashes
std::replace(Normalized.begin(), Normalized.end(), '/', '\\');
// Remove trailing backslash if present
if (!Normalized.empty() && Normalized.back() == '\\')
Normalized.pop_back();
return Normalized;
}
bool FEProjectBuildSystem::CreateFinalExecutableDirectory(FEProject* ProjectToBuild)
{
std::string ProjectFolder = ProjectToBuild->GetProjectFolder();
if (!FILE_SYSTEM.DoesDirectoryExist(ProjectFolder))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: ProjectFolder does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
std::string ExecutablePath = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/" + ProjectToBuild->GetID() + "/Release/" + GetVSProjectName(ProjectToBuild) + ".exe";
if (!FILE_SYSTEM.DoesFileExist(ExecutablePath))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Executable does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
std::string EngineResourcesPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/" + ProjectToBuild->GetID() + "/EngineResources.fepackage";
if (!FILE_SYSTEM.DoesFileExist(EngineResourcesPath))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: EngineResources.fepackage does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
std::string ProjectResourcesPath = FILE_SYSTEM.GetCurrentWorkingPath() + "/BuildProjects_Temporary/" + ProjectToBuild->GetID() + "/Resources.fepackage";
if (!FILE_SYSTEM.DoesFileExist(ProjectResourcesPath))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: ProjectResources.fepackage does not exist!", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
std::string FinalDirectory = ProjectFolder + "Build/";
if (FILE_SYSTEM.DoesDirectoryExist(FinalDirectory))
{
if (!FILE_SYSTEM.DeleteDirectory(FinalDirectory))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error deleting Build directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
}
if (!FILE_SYSTEM.CreateDirectory(FinalDirectory))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error creating Build directory", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Copy all files to the final directory.
if (!FILE_SYSTEM.CopyFile(ExecutablePath, FinalDirectory + GetVSProjectName(ProjectToBuild) + ".exe"))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error copying executable", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!FILE_SYSTEM.CopyFile(EngineResourcesPath, FinalDirectory + "EngineResources.fepackage"))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error copying EngineResources.fepackage", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
if (!FILE_SYSTEM.CopyFile(ProjectResourcesPath, FinalDirectory + "Resources.fepackage"))
{
LOG.Add("FEProjectBuildSystem::CreateFinalExecutableDirectory: Error copying ProjectResources.fepackage", "FE_BUILD_EXECUTABLE", FE_LOG_ERROR);
return false;
}
// Open the directory in file explorer.
std::string OpenCommand = "explorer \"" + NormalizePathToWindows(FinalDirectory) + "\"";
std::system(OpenCommand.c_str());
return true;
}