Skip to content

Commit 294bd8d

Browse files
committed
REVIEWED: Project generation template detection, added security check with log message
ADDED: Generate project configuration file to be used by raylib project builder
1 parent be70f3e commit 294bd8d

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/rpc.c

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,18 @@ static void SetupProject(rpcProjectConfig *config)
15701570
// Get template directory
15711571
// TODO: Use embedded template into executable?
15721572
char templatePath[256] = { 0 };
1573-
strcpy(templatePath, TextFormat("%s/template", GetWorkingDirectory()));//GetApplicationDirectory()));
1574-
//strcpy(templatePath, "./template"); // NOTE: Template directory should be in same directory as application, usually working directory
1573+
// NOTE: [template] directory must be in same directory as [rpc] tool
1574+
strcpy(templatePath, TextFormat("%s/template", GetApplicationDirectory()));
1575+
1576+
// Security check to validate required template
1577+
if (!DirectoryExists(templatePath) ||
1578+
!DirectoryExists(TextFormat("%s/src", templatePath)) ||
1579+
!DirectoryExists(TextFormat("%s/projects", templatePath)) ||
1580+
!FileExists(TextFormat("%s/project_name.rpc", templatePath)))
1581+
{
1582+
LOG("WARNING: Project generation template required files can not be found\n");
1583+
return;
1584+
}
15751585

15761586
//mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags); // Read file from memory zip data
15771587
// TODO: Replace LoadFileText(), from template path, by reading text file from zip data, decompressing it...
@@ -1580,9 +1590,9 @@ static void SetupProject(rpcProjectConfig *config)
15801590
char internalNameLower[256] = { 0 };
15811591
TextCopy(internalNameLower, TextToLower(config->Project.internalName));//TextRemoveSpaces(TextToLower(config->Project.name)));
15821592

1583-
if (config->Project.repoName[0] == '\0') strcpy(config->Project.repoName, internalNameLower);
1593+
if (config->Project.repoName[0] == '\0') strcpy(config->Project.repoName, config->Project.internalName);
15841594

1585-
LOG("INFO: Output path: %s\n", TextFormat("%s/%s", config->Project.generationOutPath, config->Project.repoName));
1595+
LOG("INFO: Output path: %s/%s\n", config->Project.generationOutPath, config->Project.repoName);
15861596

15871597
// Copy project source file(s) provided
15881598
//--------------------------------------------------------------------------
@@ -1626,7 +1636,43 @@ static void SetupProject(rpcProjectConfig *config)
16261636
LOG("INFO: Copied src/%s successfully\n", GetFileName(config->Project.sourceFilePaths[i]));
16271637
}
16281638
}
1629-
//--------------------------------------------------------------------------
1639+
//-------------------------------------------------------------------------------------
1640+
1641+
// Project configuration file (.rpc)
1642+
// NOTE: This file can be used by [rpb] to build the project
1643+
//-------------------------------------------------------------------------------------
1644+
// Update project configuration .rpc to defined values by [rpc] tool:
1645+
/*
1646+
PROJECT_INTERNAL_NAME "$(project_name)" # Project intenal name, used for executable and project files
1647+
PROJECT_REPO_NAME "$(repo-name)" # Project repository name, used for VCS (GitHub, GitLab)
1648+
PROJECT_COMMERCIAL_NAME "$(CommercialName)" # Project commercial name, used for docs and web
1649+
PROJECT_SHORT_NAME "$(ShortName)" # Project short name
1650+
PROJECT_VERSION "$(ProjectVersion)" # Project version
1651+
PROJECT_DESCRIPTION "$(ProjectDescription)" # Project description
1652+
PROJECT_PUBLISHER_NAME "$(PublisherName)" # Project publisher name
1653+
PROJECT_DEVELOPER_NAME "$(ProjectDeveloper)" # Project developer name
1654+
PROJECT_DEVELOPER_URL "$(DeveloperUrl)" # Project developer webpage url
1655+
PROJECT_DEVELOPER_EMAIL "$(DeveloperEmail)" # Project developer email
1656+
PROJECT_ICON_FILE "$(repo-name)/src/$(project_name).ico" # Project icon file
1657+
PROJECT_SOURCE_PATH "$(repo-name)/src" # Project source directory, including all required code files (C/C++)
1658+
PROJECT_ASSETS_PATH "$(repo-name)/src/resources" # Project assets directory, including all required assets
1659+
PROJECT_ASSETS_OUTPUT_PATH "$(repo-name)/release/resources" # Project assets destination path
1660+
*/
1661+
fileText = LoadFileText(TextFormat("%s/project_name.rpc", templatePath));
1662+
fileTextUpdated[0] = TextReplace(fileText, "$(project_name)", config->Project.internalName); // GetProjectConfigText(projectraw, "PROJECT_INTERNAL_NAME")
1663+
fileTextUpdated[1] = TextReplace(fileTextUpdated[0], "$(repo-name)", config->Project.repoName);
1664+
fileTextUpdated[2] = TextReplace(fileTextUpdated[1], "$(CommercialName)", config->Project.commercialName);
1665+
fileTextUpdated[3] = TextReplace(fileTextUpdated[2], "$(ShortName)", config->Project.shortName);
1666+
fileTextUpdated[4] = TextReplace(fileTextUpdated[3], "$(ProjectVersion)", config->Project.version);
1667+
fileTextUpdated[5] = TextReplace(fileTextUpdated[4], "$(ProjectDescription)", config->Project.description);
1668+
fileTextUpdated[6] = TextReplace(fileTextUpdated[5], "$(PublisherName)", config->Project.publisherName);
1669+
fileTextUpdated[7] = TextReplace(fileTextUpdated[6], "$(ProjectDeveloper)", config->Project.developerName);
1670+
fileTextUpdated[8] = TextReplace(fileTextUpdated[7], "$(DeveloperUrl)", config->Project.developerUrl);
1671+
fileTextUpdated[9] = TextReplace(fileTextUpdated[8], "$(DeveloperEmail)", config->Project.developerUrl);
1672+
SaveFileText(TextFormat("%s/%s.rpc", config->Project.generationOutPath, config->Project.internalName), fileTextUpdated[9]);
1673+
for (int i = 0; i < 10; i++) { MemFree(fileTextUpdated[i]); fileTextUpdated[i] = NULL; }
1674+
UnloadFileText(fileText);
1675+
//-------------------------------------------------------------------------------------
16301676

16311677
// Project build system: Scripts
16321678
//-------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)