Compare commits
No commits in common. "master" and "2.1.0" have entirely different histories.
12
.github/workflows/ci.yml
vendored
Executable file → Normal file
|
@ -50,7 +50,7 @@ jobs:
|
|||
run: echo "NCC_DIR=$(find build/ -type d -name 'ncc_*' | head -n 1)" >> $GITHUB_ENV
|
||||
|
||||
- name: Upload NCC build directory
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ncc-build
|
||||
path: ${{ env.NCC_DIR }}
|
||||
|
@ -59,7 +59,7 @@ jobs:
|
|||
run: zip -r redist.zip ${{ env.NCC_DIR }}
|
||||
|
||||
- name: Upload redist.zip
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: redist-zip
|
||||
path: redist.zip
|
||||
|
@ -72,7 +72,7 @@ jobs:
|
|||
run: echo "DEB_FILE=$(find build/ -type f -name '*.deb' | head -n 1)" >> $GITHUB_ENV
|
||||
|
||||
- name: Upload Debian package
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ncc-deb
|
||||
path: ${{ env.DEB_FILE }}
|
||||
|
@ -83,7 +83,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Download NCC build directory
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: ncc-build
|
||||
path: build
|
||||
|
@ -107,13 +107,13 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Download redist.zip
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: redist-zip
|
||||
path: .
|
||||
|
||||
- name: Download Debian package
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: ncc-deb
|
||||
path: .
|
||||
|
|
1
.gitignore
vendored
Executable file → Normal file
|
@ -31,4 +31,3 @@ tests/example_project/ncc
|
|||
tests/example_project/build
|
||||
/.phpunit.result.cache
|
||||
/.idea/php-test-framework.xml
|
||||
/.idea/gbrowser_project.xml
|
||||
|
|
0
.gitlab-ci.yml
Executable file → Normal file
0
.idea/.gitignore
generated
vendored
Executable file → Normal file
0
.idea/.name
generated
Executable file → Normal file
0
.idea/Nosial Code Compiler.iml
generated
Executable file → Normal file
7
.idea/codeStyles/Project.xml
generated
|
@ -1,7 +0,0 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
0
.idea/codeStyles/codeStyleConfig.xml
generated
Executable file → Normal file
0
.idea/copyright/Nosial.xml
generated
Executable file → Normal file
0
.idea/copyright/profiles_settings.xml
generated
Executable file → Normal file
0
.idea/encodings.xml
generated
Executable file → Normal file
0
.idea/inspectionProfiles/Project_Default.xml
generated
Executable file → Normal file
0
.idea/modules.xml
generated
Executable file → Normal file
0
.idea/php-inspections-ea-ultimate.xml
generated
Executable file → Normal file
0
.idea/php.xml
generated
Executable file → Normal file
0
.idea/runConfigurations/Build_Redist.xml
generated
Executable file → Normal file
0
.idea/runConfigurations/Rebuild_Autoloaders.xml
generated
Executable file → Normal file
0
.idea/scopes/Autoloaders.xml
generated
Executable file → Normal file
0
.idea/scopes/Installer_Source_files.xml
generated
Executable file → Normal file
0
.idea/scopes/NCC_Source_files.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_Filesystem.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_Process.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_Uid.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_Yaml.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_polyfill_ctype.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_polyfill_mbstring.xml
generated
Executable file → Normal file
0
.idea/scopes/Symfony_polyfill_uuid.xml
generated
Executable file → Normal file
0
.idea/scopes/Third_Party_Source_Files.xml
generated
Executable file → Normal file
0
.idea/scopes/defuse.xml
generated
Executable file → Normal file
0
.idea/scopes/defuse_php_encryption.xml
generated
Executable file → Normal file
0
.idea/scopes/jelix.xml
generated
Executable file → Normal file
0
.idea/scopes/jelix_version.xml
generated
Executable file → Normal file
0
.idea/scopes/nikic.xml
generated
Executable file → Normal file
0
.idea/scopes/nikic_PhpParser.xml
generated
Executable file → Normal file
0
.idea/scopes/theseer.xml
generated
Executable file → Normal file
0
.idea/scopes/theseer_Autoload.xml
generated
Executable file → Normal file
0
.idea/scopes/theseer_DirectoryScanner.xml
generated
Executable file → Normal file
0
.idea/vcs.xml
generated
Executable file → Normal file
0
.idea/webResources.xml
generated
Executable file → Normal file
97
CHANGELOG.md
Executable file → Normal file
|
@ -5,103 +5,6 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.1.8] - 2025-03-17
|
||||
|
||||
This update introduces a temporary fix
|
||||
|
||||
### Fixed
|
||||
- (Temporary) removed the ability to delete cache files because it's deleting important files that are needed.
|
||||
|
||||
|
||||
## [2.1.7] - 2025-03-17
|
||||
|
||||
This update introduces a quality of life improvement
|
||||
|
||||
### Changed
|
||||
- Refactor variable names for consistency and clarity in ShutdownHandler and PackageWriter classes
|
||||
- Improve error handling in ShutdownHandler by logging warnings for cleanup failures
|
||||
|
||||
### Fixed
|
||||
- Fixed issue in ArchiveExctractor where close() may be called on a already closed resource
|
||||
|
||||
|
||||
## [2.1.6] - 2024-10-29
|
||||
|
||||
This update introduces critical bug fixes
|
||||
|
||||
### Fixed
|
||||
- Validate package instance before checking execution policy
|
||||
|
||||
|
||||
|
||||
## [2.1.5] - 2024-10-14
|
||||
|
||||
This update introduces a critical bug fix
|
||||
|
||||
|
||||
|
||||
## [2.1.4] - 2024-10-13
|
||||
|
||||
This update introduces minor bug fixes & improvements
|
||||
|
||||
### Added
|
||||
- Added new constant `%DEFAULT_BUILD_CONFIGURATION%` which points to the project's default build configuration
|
||||
- Added new dynamic constant `%BUILD_OUTPUT_PATH%` which can be used as `%BUILD_OUTPUT_PATH%:release` to show the
|
||||
output path of a specific build configuration
|
||||
- Refactor CI templates to support dynamic build targets
|
||||
- Added template `phpexe` & `phpgz` for generating executable binaries and compressed executables for the project
|
||||
|
||||
### Changed
|
||||
- Refactor phpmake template to support dynamic build targets
|
||||
|
||||
### Fixed
|
||||
- ncc will now correctly handle package execution where the main unit is not defined in the package instead of
|
||||
throwing an exception.
|
||||
- Executable Compiler will now correctly create a directory if it does not exist when compiling a package using gcc
|
||||
|
||||
|
||||
|
||||
## [2.1.3] - 2024-09-27
|
||||
|
||||
This update introduces bug fixes
|
||||
|
||||
### Fixed
|
||||
- Null-pointer fix
|
||||
|
||||
|
||||
## [2.1.2] - 2024-09-27
|
||||
|
||||
This update introduces bug fixes
|
||||
|
||||
### Added
|
||||
- Add getter methods for installation lifecycle steps
|
||||
- Added pre-install & post-install execution unit handling
|
||||
|
||||
### Changed
|
||||
- Updated DocStrings in PackageManager
|
||||
|
||||
### Fixed
|
||||
- Fixed incorrect enum usage in RepositoryMenu
|
||||
|
||||
|
||||
## [2.1.1] - 2024-09-24
|
||||
|
||||
This update introduces a couple of new features and quality of life improvements
|
||||
|
||||
### Added
|
||||
- Added new PHP template `phpunit` for generating PhpUnit tests for the project
|
||||
- Added new PHP template `phpmake` for generating a Makefile for the project
|
||||
- Added new PHP template `phplib_full` That combines `phplib`, `phpmake` and `phpunit` templates
|
||||
- Added new PHP template `phpcli_full` That combines `phpcli`, `phplib`, `phpmake` and `phpunit` templates
|
||||
- Added new PHP template `phpci_github` that generates a Github CI workflow for the project
|
||||
|
||||
### Changed
|
||||
- The template `phpcli` no longer includes a Makefile, instead use `phpmake` to generate a Makefile for the project
|
||||
|
||||
### Fixed
|
||||
- Fixed incorrect enum usage with a logging method call.
|
||||
|
||||
|
||||
## [2.1.0] - 2024-09-20
|
||||
|
||||
This update introduces a refactored code-base, code quality improvements, and better exception handling.
|
||||
|
|
0
CODE_OF_CONDUCT.md
Executable file → Normal file
0
CONTRIBUTING.md
Executable file → Normal file
2
DOCUMENTATION.md
Executable file → Normal file
|
@ -62,7 +62,7 @@ basic usage, standards, and much more.
|
|||
* [Package Metadata (metadata)](#package-metadata-metadata)
|
||||
* [Assembly Information (assembly)](#assembly-information-assembly)
|
||||
* [Package Dependencies (dependencies)](#package-dependencies-dependencies)
|
||||
* [Execution Units (execution_units)](#execution-units-execution_units)
|
||||
* [Execution Units (execution_units)](#execution-units-executionunits)
|
||||
* [Building Projects (build)](#building-projects-build)
|
||||
* [Execute (exec)](#execute-exec)
|
||||
* [Project Configuration (package.json)](#project-configuration-packagejson)
|
||||
|
|
0
Dockerfile
Executable file → Normal file
0
Dockerfile.debian
Executable file → Normal file
0
LICENSE
Executable file → Normal file
0
Makefile
Executable file → Normal file
13
README.md
Executable file → Normal file
|
@ -6,19 +6,6 @@ Nosial Code Compiler is a package compiler, manager & installer for PHP. Allowin
|
|||
versions of php packages on your system that your PHP programs/projects can share and use. Additionally, ncc also allows
|
||||
you to create a redistributable package of your PHP program/project in the form of a `.ncc` binary package file.
|
||||
|
||||
## Community
|
||||
|
||||
This project and many others from Nosial are available on multiple publicly available and free git repositories at
|
||||
|
||||
- [n64](https://git.n64.cc/nosial/ncc)
|
||||
- [GitHub](https://github.com/nosial/ncc)
|
||||
- [Codeberg](https://codeberg.org/nosial/ncc)
|
||||
|
||||
Issues & Pull Requests are frequently checked and to be referenced accordingly in commits and changes, Nosial remains
|
||||
dedicated to keep these repositories up to date when possible.
|
||||
|
||||
For questions & discussions see the public Telegram community at [@NosialDiscussions](https://t.me/NosialDiscussions).
|
||||
We do encourage community support and discussions, please be respectful and follow the rules of the community.
|
||||
|
||||
## Features
|
||||
|
||||
|
|
0
assets/compiler_process.png
Executable file → Normal file
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
0
assets/data_structure.png
Executable file → Normal file
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
0
assets/execution_process.png
Executable file → Normal file
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
0
assets/header_structure.png
Executable file → Normal file
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
0
assets/icon/ncc.svg
Executable file → Normal file
Before Width: | Height: | Size: 683 B After Width: | Height: | Size: 683 B |
0
assets/icon/ncc@1024px.png
Executable file → Normal file
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
0
assets/icon/ncc@128px.png
Executable file → Normal file
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
0
assets/icon/ncc@16px.png
Executable file → Normal file
Before Width: | Height: | Size: 351 B After Width: | Height: | Size: 351 B |
0
assets/icon/ncc@256px.png
Executable file → Normal file
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
0
assets/icon/ncc@32px.png
Executable file → Normal file
Before Width: | Height: | Size: 504 B After Width: | Height: | Size: 504 B |
0
assets/icon/ncc@512px.png
Executable file → Normal file
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
0
assets/icon/ncc@64px.png
Executable file → Normal file
Before Width: | Height: | Size: 820 B After Width: | Height: | Size: 820 B |
0
assets/package_structure.png
Executable file → Normal file
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
0
bootstrap.php
Executable file → Normal file
0
old_docker/Dockerfile
Executable file → Normal file
0
old_docker/Dockerfile.debian
Executable file → Normal file
0
old_docker/note.txt
Executable file → Normal file
0
phpunit.xml
Executable file → Normal file
0
src/autoload/autoload.php
Executable file → Normal file
0
src/config/default_repositories.json
Executable file → Normal file
0
src/config/ncc.yaml
Executable file → Normal file
2
src/debian/control
Executable file → Normal file
|
@ -2,7 +2,7 @@ Package: ncc
|
|||
Source: ncc
|
||||
Section: devel
|
||||
Priority: optional
|
||||
Version: 2.0.4
|
||||
Version: 2.0.3
|
||||
Maintainer: netkas <netkas@nosial.net>
|
||||
Build-Depends: debhelper-compat (= 13)
|
||||
Standards-Version: 4.5.1
|
||||
|
|
0
src/debian/copyright
Executable file → Normal file
0
src/debian/postinst
Executable file → Normal file
0
src/debian/postrm
Executable file → Normal file
0
src/installer/generate_build_files.php
Executable file → Normal file
0
src/installer/hash_check.php
Executable file → Normal file
0
src/installer/installer
Executable file → Normal file
0
src/installer/ncc-package.xml
Executable file → Normal file
0
src/installer/ncc.desktop
Executable file → Normal file
0
src/ncc/CLI/Commands/BuildCommand.php
Executable file → Normal file
0
src/ncc/CLI/Commands/ExecCommand.php
Executable file → Normal file
0
src/ncc/CLI/Commands/PackageInspectorCommand.php
Executable file → Normal file
0
src/ncc/CLI/Commands/SetupCommand.php
Executable file → Normal file
0
src/ncc/CLI/HelpMenu.php
Executable file → Normal file
0
src/ncc/CLI/Main.php
Executable file → Normal file
0
src/ncc/CLI/Management/ConfigMenu.php
Executable file → Normal file
0
src/ncc/CLI/Management/CredentialMenu.php
Executable file → Normal file
0
src/ncc/CLI/Management/PackageManagerMenu.php
Executable file → Normal file
0
src/ncc/CLI/Management/ProjectMenu.php
Executable file → Normal file
2
src/ncc/CLI/Management/RepositoryMenu.php
Executable file → Normal file
|
@ -119,7 +119,7 @@
|
|||
$output = sprintf('%s (%s) [%s]',
|
||||
$source->getName(),
|
||||
Console::formatColor($source->getHost(), ConsoleColors::GREEN),
|
||||
Console::formatColor($source->getType()->value, ConsoleColors::YELLOW)
|
||||
Console::formatColor($source->getType(), ConsoleColors::YELLOW)
|
||||
);
|
||||
|
||||
if(!$source->isSsl())
|
||||
|
|
8
src/ncc/Classes/ArchiveExtractor.php
Executable file → Normal file
|
@ -29,7 +29,6 @@
|
|||
use ncc\Utilities\Console;
|
||||
use PharData;
|
||||
use RuntimeException;
|
||||
use ValueError;
|
||||
use ZipArchive;
|
||||
|
||||
class ArchiveExtractor
|
||||
|
@ -127,13 +126,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$zip_archive->close();
|
||||
}
|
||||
catch(ValueError $e)
|
||||
{
|
||||
Console::outWarning('An error occurred while closing the zip archive, ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
0
src/ncc/Classes/BashExtension/BashRunner.php
Executable file → Normal file
10
src/ncc/Classes/ExecutionUnitRunner.php
Executable file → Normal file
|
@ -31,7 +31,6 @@
|
|||
use ncc\Classes\PhpExtension\PhpRunner;
|
||||
use ncc\Enums\Runners;
|
||||
use ncc\Exceptions\ConfigurationException;
|
||||
use ncc\Exceptions\IntegrityException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\NotSupportedException;
|
||||
use ncc\Exceptions\OperationException;
|
||||
|
@ -77,19 +76,11 @@
|
|||
{
|
||||
$process->setTimeout($unit->getExecutionPolicy()->getExecute()->getTimeout());
|
||||
}
|
||||
else
|
||||
{
|
||||
$process->setTimeout(null);
|
||||
}
|
||||
|
||||
if($unit->getExecutionPolicy()->getExecute()->getIdleTimeout() !== null)
|
||||
{
|
||||
$process->setIdleTimeout($unit->getExecutionPolicy()->getExecute()->getIdleTimeout());
|
||||
}
|
||||
else
|
||||
{
|
||||
$process->setIdleTimeout(null);
|
||||
}
|
||||
|
||||
return $process;
|
||||
}
|
||||
|
@ -138,7 +129,6 @@
|
|||
* @return int
|
||||
* @throws ConfigurationException
|
||||
* @throws OperationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public static function executeFromPackage(PackageReader $package_reader, string $policy_name, array $args=[]): int
|
||||
{
|
||||
|
|
37
src/ncc/Classes/GiteaExtension/GiteaRepository.php
Executable file → Normal file
|
@ -39,7 +39,6 @@
|
|||
use ncc\Objects\Vault\Password\AccessToken;
|
||||
use ncc\Objects\Vault\Password\UsernamePassword;
|
||||
use ncc\Utilities\Console;
|
||||
use ncc\Utilities\Resolver;
|
||||
use ncc\Utilities\RuntimeCache;
|
||||
use RuntimeException;
|
||||
|
||||
|
@ -98,18 +97,12 @@
|
|||
'User-Agent: ncc'
|
||||
];
|
||||
|
||||
|
||||
if($authentication !== null)
|
||||
{
|
||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||
|
@ -193,13 +186,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $endpoint,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
@ -260,13 +246,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $endpoint,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
@ -358,13 +337,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $endpoint,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
@ -461,13 +433,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $endpoint,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
|
0
src/ncc/Classes/GithubExtension/GithubRepository.php
Executable file → Normal file
36
src/ncc/Classes/GitlabExtension/GitlabRepository.php
Executable file → Normal file
|
@ -39,7 +39,6 @@
|
|||
use ncc\Objects\Vault\Password\AccessToken;
|
||||
use ncc\Objects\Vault\Password\UsernamePassword;
|
||||
use ncc\Utilities\Console;
|
||||
use ncc\Utilities\Resolver;
|
||||
use ncc\Utilities\RuntimeCache;
|
||||
use RuntimeException;
|
||||
|
||||
|
@ -104,13 +103,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $endpoint,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
@ -195,13 +187,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_NOBODY => true,
|
||||
|
@ -265,13 +250,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||
|
@ -355,13 +333,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||
|
@ -447,13 +418,6 @@
|
|||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||
}
|
||||
|
||||
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||
|
||||
if($resolved_host !== null)
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||
|
|
0
src/ncc/Classes/LuaExtension/LuaRunner.php
Executable file → Normal file
65
src/ncc/Classes/NccExtension/ConstantCompiler.php
Executable file → Normal file
|
@ -22,10 +22,8 @@
|
|||
|
||||
namespace ncc\Classes\NccExtension;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use ncc\Enums\SpecialConstants\BuildConstants;
|
||||
use ncc\Enums\SpecialConstants\DateTimeConstants;
|
||||
use ncc\Enums\SpecialConstants\GeneralConstants;
|
||||
use ncc\Enums\SpecialConstants\InstallConstants;
|
||||
use ncc\Enums\SpecialConstants\AssemblyConstants;
|
||||
use ncc\Enums\SpecialConstants\RuntimeConstants;
|
||||
|
@ -49,67 +47,6 @@
|
|||
$input = self::compileBuildConstants($input);
|
||||
$input = self::compileDateTimeConstants($input, time());
|
||||
$input = self::compileRuntimeConstants($input);
|
||||
$input = self::compileGeneralConstants($input, $project_configuration);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles general constants from the given input string based on the provided project configuration.
|
||||
*
|
||||
* @param string|null $input The input string containing constants to be compiled.
|
||||
* @param ProjectConfiguration $project_configuration The project configuration used to resolve constants.
|
||||
* @return string|null The input string with constants replaced, or null if the input was null.
|
||||
*/
|
||||
public static function compileGeneralConstants(?string $input, ProjectConfiguration $project_configuration): ?string
|
||||
{
|
||||
if ($input === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Replace %DEFAULT_BUILD_CONFIGURATION%
|
||||
$input = str_replace(
|
||||
[
|
||||
GeneralConstants::DEFAULT_BUILD_CONFIGURATION->value
|
||||
],
|
||||
[
|
||||
$project_configuration->getBuild()->getDefaultConfiguration()
|
||||
],
|
||||
$input
|
||||
);
|
||||
|
||||
if (str_starts_with($input, GeneralConstants::BUILD_OUTPUT_PATH->value))
|
||||
{
|
||||
$build_name = null;
|
||||
if (preg_match('/' . preg_quote(GeneralConstants::BUILD_OUTPUT_PATH->value, '/') . ':(\S+)/', $input, $matches))
|
||||
{
|
||||
$build_name = $matches[1];
|
||||
}
|
||||
|
||||
if ($build_name === null)
|
||||
{
|
||||
Console::outWarning(sprintf("Cannot compile constant %s because it's not valid, usage: %%CONSTANT%%:<name>", $input));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$output_path = $project_configuration->getBuild()->getBuildConfiguration($build_name)->getOutput();
|
||||
$input = preg_replace(
|
||||
'/' . preg_quote(GeneralConstants::BUILD_OUTPUT_PATH->value, '/') . ':\S+/',
|
||||
$output_path,
|
||||
$input,
|
||||
1
|
||||
);
|
||||
}
|
||||
catch (InvalidArgumentException $e)
|
||||
{
|
||||
Console::outError(sprintf("Cannot compile constant %s because it does not point to an existing build configuration name", $input));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
@ -133,7 +70,7 @@
|
|||
AssemblyConstants::ASSEMBLY_NAME->value,
|
||||
AssemblyConstants::ASSEMBLY_PACKAGE->value,
|
||||
AssemblyConstants::ASSEMBLY_VERSION->value,
|
||||
AssemblyConstants::ASSEMBLY_UID->value,
|
||||
AssemblyConstants::ASSEMBLY_UID->value
|
||||
],
|
||||
[
|
||||
$assembly->getName(),
|
||||
|
|
16
src/ncc/Classes/NccExtension/NccCompiler.php
Executable file → Normal file
|
@ -59,17 +59,11 @@
|
|||
*/
|
||||
private $project_manager;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $merged_dependencies;
|
||||
|
||||
/**
|
||||
* @param ProjectManager $project_manager
|
||||
*/
|
||||
public function __construct(ProjectManager $project_manager)
|
||||
{
|
||||
$this->merged_dependencies = [];
|
||||
$this->project_manager = $project_manager;
|
||||
}
|
||||
|
||||
|
@ -95,7 +89,6 @@
|
|||
*/
|
||||
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT->value, array $options=[]): string
|
||||
{
|
||||
$this->merged_dependencies = [];
|
||||
$configuration = $this->project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
||||
$configuration->setOptions(array_merge($configuration->getOptions(), $options));
|
||||
$static_dependencies = isset($configuration->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES->value]);
|
||||
|
@ -171,7 +164,7 @@
|
|||
|
||||
foreach($execution_units as $unit)
|
||||
{
|
||||
$progress_bar->setMiscText(basename($unit->getExecutionPolicy()->getName()));
|
||||
$progress_bar->setMiscText($unit->getExecutionPolicy()->getName());
|
||||
//$progress++;
|
||||
//Console::inlineProgressBar($progress, $steps);
|
||||
$package_writer->addExecutionUnit($unit);
|
||||
|
@ -184,7 +177,7 @@
|
|||
{
|
||||
//$progress++;
|
||||
//Console::inlineProgressBar($progress, $steps);
|
||||
$progress_bar->setMiscText(basename($component));
|
||||
$progress_bar->setMiscText($component);
|
||||
Console::outVerbose(sprintf('Compiling \'%s\'', $component));
|
||||
|
||||
$this->processComponent($package_writer, $component);
|
||||
|
@ -196,7 +189,7 @@
|
|||
{
|
||||
//$progress++;
|
||||
//Console::inlineProgressBar($progress, $steps);
|
||||
$progress_bar->setMiscText(basename($resource));
|
||||
$progress_bar->setMiscText($resource);
|
||||
Console::outVerbose(sprintf('Processing \'%s\'', $resource));
|
||||
|
||||
$this->processResource($package_writer, $resource);
|
||||
|
@ -241,14 +234,13 @@
|
|||
/** @noinspection UnusedFunctionResultInspection */
|
||||
$package_writer->addDependencyConfiguration($dependency);
|
||||
|
||||
if(!$static || in_array($dependency->getName(), $this->merged_dependencies, true))
|
||||
if(!$static)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$entry = (new PackageManager())->getPackageLock()->getVersionEntry($dependency->getName(), $dependency->getVersion());
|
||||
$package_writer->merge((new PackageReader($entry->getShadowPackagePath($dependency->getName()))));
|
||||
$this->merged_dependencies[] = $dependency->getName();
|
||||
|
||||
foreach($entry->getDependencies() as $sub_dependency)
|
||||
{
|
||||
|
|
251
src/ncc/Classes/PackageReader.php
Executable file → Normal file
|
@ -29,8 +29,8 @@
|
|||
use ncc\Enums\Flags\PackageFlags;
|
||||
use ncc\Enums\PackageDirectory;
|
||||
use ncc\Exceptions\ConfigurationException;
|
||||
use ncc\Exceptions\IntegrityException;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\NotSupportedException;
|
||||
use ncc\Objects\Package\Component;
|
||||
use ncc\Objects\Package\ExecutionUnit;
|
||||
use ncc\Objects\Package\Metadata;
|
||||
|
@ -47,32 +47,32 @@
|
|||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $packageOffset;
|
||||
private $package_offset;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $packageLength;
|
||||
private $package_length;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $headerOffset;
|
||||
private $header_offset;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $headerLength;
|
||||
private $header_length;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $dataOffset;
|
||||
private $data_offset;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $dataLength;
|
||||
private $data_length;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@ -82,12 +82,7 @@
|
|||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $packageFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $packagePath;
|
||||
private $package_file;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@ -107,10 +102,8 @@
|
|||
throw new IOException(sprintf('File \'%s\' does not exist', $file_path));
|
||||
}
|
||||
|
||||
$this->packagePath = $file_path;
|
||||
$this->packageFile = fopen($file_path, 'rb');
|
||||
|
||||
if($this->packageFile === false)
|
||||
$this->package_file = fopen($file_path, 'rb');
|
||||
if($this->package_file === false)
|
||||
{
|
||||
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path));
|
||||
}
|
||||
|
@ -122,41 +115,41 @@
|
|||
// End of data: \xFF\xAA\x55\xF0
|
||||
|
||||
// First find the offset of the package by searching for the magic bytes "ncc_pkg"
|
||||
$this->packageOffset = 0;
|
||||
while(!feof($this->packageFile))
|
||||
$this->package_offset = 0;
|
||||
while(!feof($this->package_file))
|
||||
{
|
||||
$buffer = fread($this->packageFile, 1024);
|
||||
$buffer = fread($this->package_file, 1024);
|
||||
$buffer_length = strlen($buffer);
|
||||
$this->packageOffset += $buffer_length;
|
||||
$this->package_offset += $buffer_length;
|
||||
|
||||
if (($position = strpos($buffer, "ncc_pkg")) !== false)
|
||||
{
|
||||
$this->packageOffset -= $buffer_length - $position;
|
||||
$this->packageLength = 7; // ncc_pkg
|
||||
$this->headerOffset = $this->packageOffset + 7;
|
||||
$this->package_offset -= $buffer_length - $position;
|
||||
$this->package_length = 7; // ncc_pkg
|
||||
$this->header_offset = $this->package_offset + 7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for sanity reasons
|
||||
if($this->packageOffset === null || $this->packageLength === null)
|
||||
if($this->package_offset === null || $this->package_length === null)
|
||||
{
|
||||
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing magic bytes)', $file_path));
|
||||
}
|
||||
|
||||
// Seek the header until the end of headers byte sequence (1F 1F 1F 1F)
|
||||
fseek($this->packageFile, $this->headerOffset);
|
||||
while (!feof($this->packageFile))
|
||||
fseek($this->package_file, $this->header_offset);
|
||||
while (!feof($this->package_file))
|
||||
{
|
||||
$this->headers .= fread($this->packageFile, 1024);
|
||||
$this->headers .= fread($this->package_file, 1024);
|
||||
|
||||
// Search for the position of "1F 1F 1F 1F" within the buffer
|
||||
if (($position = strpos($this->headers, "\x1F\x1F\x1F\x1F")) !== false)
|
||||
{
|
||||
$this->headers = substr($this->headers, 0, $position);
|
||||
$this->headerLength = strlen($this->headers);
|
||||
$this->packageLength += $this->headerLength + 4;
|
||||
$this->dataOffset = $this->headerOffset + $this->headerLength + 4;
|
||||
$this->header_length = strlen($this->headers);
|
||||
$this->package_length += $this->header_length + 4;
|
||||
$this->data_offset = $this->header_offset + $this->header_length + 4;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -181,32 +174,21 @@
|
|||
}
|
||||
|
||||
// Seek the data until the end of the package (FF AA 55 F0)
|
||||
fseek($this->packageFile, $this->dataOffset);
|
||||
$buffer = '';
|
||||
while(!feof($this->packageFile))
|
||||
fseek($this->package_file, $this->data_offset);
|
||||
while(!feof($this->package_file))
|
||||
{
|
||||
$current_chunk = fread($this->packageFile, 1024);
|
||||
$this->dataLength += strlen($current_chunk);
|
||||
$buffer .= $current_chunk;
|
||||
$buffer = fread($this->package_file, 1024);
|
||||
$this->data_length += strlen($buffer);
|
||||
|
||||
// If we detect the end-of-data byte sequence
|
||||
if (($position = strpos($buffer, "\xFF\xAA\x55\xF0")) !== false)
|
||||
{
|
||||
$this->dataLength -= strlen($buffer) - $position;
|
||||
$this->packageLength += $this->dataLength + 4;
|
||||
$this->data_length -= strlen($buffer) - $position;
|
||||
$this->package_length += $this->data_length + 4;
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if the buffer is 1MB or larger
|
||||
if(strlen($buffer) > 1048576)
|
||||
{
|
||||
// Remove the first 512kb of the buffer
|
||||
$buffer = substr($buffer, 512000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($this->dataLength === null || $this->dataLength === 0)
|
||||
if($this->data_length === null)
|
||||
{
|
||||
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing end of package)', $file_path));
|
||||
}
|
||||
|
@ -275,18 +257,18 @@
|
|||
{
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
|
||||
{
|
||||
throw new RuntimeException(sprintf('File \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||
throw new RuntimeException(sprintf('File \'%s\' not found in package', $name));
|
||||
}
|
||||
|
||||
$location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
|
||||
fseek($this->packageFile, ($this->dataOffset + (int)$location[0]));
|
||||
fseek($this->package_file, ($this->data_offset + (int)$location[0]));
|
||||
|
||||
if(in_array(PackageFlags::COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
|
||||
{
|
||||
return gzuncompress(fread($this->packageFile, (int)$location[1]));
|
||||
return gzuncompress(fread($this->package_file, (int)$location[1]));
|
||||
}
|
||||
|
||||
return fread($this->packageFile, (int)$location[1]);
|
||||
return fread($this->package_file, (int)$location[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -299,7 +281,7 @@
|
|||
{
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
|
||||
{
|
||||
throw new RuntimeException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||
throw new RuntimeException(sprintf('Resource \'%s\' not found in package', $name));
|
||||
}
|
||||
|
||||
$location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
|
||||
|
@ -326,8 +308,8 @@
|
|||
*/
|
||||
public function getByPointer(int $pointer, int $length): string
|
||||
{
|
||||
fseek($this->packageFile, ($this->headerLength + $pointer));
|
||||
return fread($this->packageFile, $length);
|
||||
fseek($this->package_file, ($this->header_length + $pointer));
|
||||
return fread($this->package_file, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -335,7 +317,6 @@
|
|||
*
|
||||
* @return Assembly
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getAssembly(): Assembly
|
||||
{
|
||||
|
@ -348,18 +329,10 @@
|
|||
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Assembly object not found in package \'%s\'', $this->packagePath));
|
||||
throw new ConfigurationException('Package does not contain an assembly');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$assembly = Assembly::fromArray(ZiProto::decode($this->get($directory)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode assembly from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
|
||||
$this->cache[$directory] = $assembly;
|
||||
return $assembly;
|
||||
}
|
||||
|
@ -369,7 +342,7 @@
|
|||
*
|
||||
* @return Metadata
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
* @throws NotSupportedException
|
||||
*/
|
||||
public function getMetadata(): Metadata
|
||||
{
|
||||
|
@ -382,18 +355,10 @@
|
|||
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Metadata object not found in package \'%s\'', $this->packagePath));
|
||||
throw new ConfigurationException('Package does not contain metadata');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$metadata = Metadata::fromArray(ZiProto::decode($this->get($directory)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode metadata from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
|
||||
foreach($this->getFlags() as $flag)
|
||||
{
|
||||
$metadata->setOption($flag, true);
|
||||
|
@ -407,7 +372,6 @@
|
|||
* Optional. Returns the package's installer
|
||||
*
|
||||
* @return Installer|null
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getInstaller(): ?Installer
|
||||
{
|
||||
|
@ -423,15 +387,7 @@
|
|||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$installer = Installer::fromArray(ZiProto::decode($this->get($directory)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode installer from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
|
||||
$this->cache[$directory] = $installer;
|
||||
return $installer;
|
||||
}
|
||||
|
@ -463,25 +419,17 @@
|
|||
* @param string $name
|
||||
* @return Dependency
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getDependency(string $name): Dependency
|
||||
{
|
||||
$dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$dependency_name]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package', $name));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Dependency::fromArray(ZiProto::decode($this->get($dependency_name)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode dependency \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a dependency from the package by pointer
|
||||
|
@ -489,19 +437,12 @@
|
|||
* @param int $pointer
|
||||
* @param int $length
|
||||
* @return Dependency
|
||||
* @throws IntegrityException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public function getDependencyByPointer(int $pointer, int $length): Dependency
|
||||
{
|
||||
try
|
||||
{
|
||||
return Dependency::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode dependency from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of execution units from the package
|
||||
|
@ -530,36 +471,17 @@
|
|||
* @param string $name
|
||||
* @return ExecutionUnit
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getExecutionUnit(string $name): ExecutionUnit
|
||||
{
|
||||
$execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$execution_unit_name]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package', $name));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ExecutionUnit::fromArray(ZiProto::decode($this->get($execution_unit_name)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode execution unit \'%s\' from package file \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an execution unit with the specified name exists in the package.
|
||||
*
|
||||
* @param string $name The name of the execution unit to check.
|
||||
* @return bool True if the execution unit exists, false otherwise.
|
||||
*/
|
||||
public function executionUnitExists(string $name): bool
|
||||
{
|
||||
return isset($this->headers[PackageStructure::DIRECTORY->value][sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an execution unit from the package by pointer
|
||||
|
@ -567,19 +489,12 @@
|
|||
* @param int $pointer
|
||||
* @param int $length
|
||||
* @return ExecutionUnit
|
||||
* @throws IntegrityException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public function getExecutionUnitByPointer(int $pointer, int $length): ExecutionUnit
|
||||
{
|
||||
try
|
||||
{
|
||||
return ExecutionUnit::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode execution unit from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package's component pointers
|
||||
|
@ -629,25 +544,17 @@
|
|||
* @param string $name
|
||||
* @return Component
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getComponent(string $name): Component
|
||||
{
|
||||
$component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$component_name]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Component \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||
throw new ConfigurationException(sprintf('Component \'%s\' not found in package', $name));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Component::fromArray(ZiProto::decode($this->get($component_name)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode component \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a component from the package by pointer
|
||||
|
@ -655,19 +562,12 @@
|
|||
* @param int $pointer
|
||||
* @param int $length
|
||||
* @return Component
|
||||
* @throws IntegrityException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public function getComponentByPointer(int $pointer, int $length): Component
|
||||
{
|
||||
try
|
||||
{
|
||||
return Component::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode component from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a component from the package by a class pointer
|
||||
|
@ -675,25 +575,17 @@
|
|||
* @param string $class
|
||||
* @return Component
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getComponentByClass(string $class): Component
|
||||
{
|
||||
$class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$class_name]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package \'%s\'', $class, $this->packagePath));
|
||||
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package', $class));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Component::fromArray(ZiProto::decode($this->get($class_name)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode component from class pointer \'%s\' from package \'%s\' using ZiProto: %s', $class, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of resource pointers from the package
|
||||
|
@ -722,25 +614,17 @@
|
|||
* @param string $name
|
||||
* @return Resource
|
||||
* @throws ConfigurationException
|
||||
* @throws IntegrityException
|
||||
*/
|
||||
public function getResource(string $name): Resource
|
||||
{
|
||||
$resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$resource_name]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package', $name));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Resource::fromArray(ZiProto::decode($this->get($resource_name)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode resource \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a resource from the package by pointer
|
||||
|
@ -748,19 +632,12 @@
|
|||
* @param int $pointer
|
||||
* @param int $length
|
||||
* @return Resource
|
||||
* @throws IntegrityException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public function getResourceByPointer(int $pointer, int $length): Resource
|
||||
{
|
||||
try
|
||||
{
|
||||
return Resource::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new IntegrityException(sprintf('Failed to decode resource from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the package's directory for a file that matches the given filename
|
||||
|
@ -788,7 +665,7 @@
|
|||
*/
|
||||
public function getPackageOffset(): int
|
||||
{
|
||||
return $this->packageOffset;
|
||||
return $this->package_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -796,7 +673,7 @@
|
|||
*/
|
||||
public function getPackageLength(): int
|
||||
{
|
||||
return $this->packageLength;
|
||||
return $this->package_length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,7 +681,7 @@
|
|||
*/
|
||||
public function getHeaderOffset(): int
|
||||
{
|
||||
return $this->headerOffset;
|
||||
return $this->header_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -812,7 +689,7 @@
|
|||
*/
|
||||
public function getHeaderLength(): int
|
||||
{
|
||||
return $this->headerLength;
|
||||
return $this->header_length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -820,7 +697,7 @@
|
|||
*/
|
||||
public function getDataOffset(): int
|
||||
{
|
||||
return $this->dataOffset;
|
||||
return $this->data_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -828,7 +705,7 @@
|
|||
*/
|
||||
public function getDataLength(): int
|
||||
{
|
||||
return $this->dataLength;
|
||||
return $this->data_length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -842,12 +719,12 @@
|
|||
{
|
||||
$checksum = hash($hash, '', $binary);
|
||||
|
||||
fseek($this->packageFile, $this->packageOffset);
|
||||
$bytes_left = $this->packageLength;
|
||||
fseek($this->package_file, $this->package_offset);
|
||||
$bytes_left = $this->package_length;
|
||||
|
||||
while ($bytes_left > 0)
|
||||
{
|
||||
$buffer = fread($this->packageFile, min(1024, $bytes_left));
|
||||
$buffer = fread($this->package_file, min(1024, $bytes_left));
|
||||
$buffer_length = strlen($buffer);
|
||||
$bytes_left -= $buffer_length;
|
||||
$checksum = hash($hash, ($checksum . $buffer), $binary);
|
||||
|
@ -875,13 +752,13 @@
|
|||
throw new IOException(sprintf('Failed to open file \'%s\'', $path));
|
||||
}
|
||||
|
||||
fseek($this->packageFile, $this->packageOffset);
|
||||
$remaining_bytes = $this->packageLength;
|
||||
fseek($this->package_file, $this->package_offset);
|
||||
$remaining_bytes = $this->package_length;
|
||||
|
||||
while ($remaining_bytes > 0)
|
||||
{
|
||||
$bytes_to_read = min($remaining_bytes, 4096);
|
||||
$data = fread($this->packageFile, $bytes_to_read);
|
||||
$data = fread($this->package_file, $bytes_to_read);
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
|
@ -911,9 +788,9 @@
|
|||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if(is_resource($this->packageFile))
|
||||
if(is_resource($this->package_file))
|
||||
{
|
||||
fclose($this->packageFile);
|
||||
fclose($this->package_file);
|
||||
}
|
||||
}
|
||||
}
|
94
src/ncc/Classes/PackageWriter.php
Executable file → Normal file
|
@ -53,70 +53,70 @@
|
|||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $tempFile;
|
||||
private $temp_file;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $packageFile;
|
||||
private $package_file;
|
||||
|
||||
/**
|
||||
* @var string;
|
||||
*/
|
||||
private $temporaryPath;
|
||||
private $temporary_path;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $dataWritten;
|
||||
private $data_written;
|
||||
|
||||
/**
|
||||
* PackageWriter constructor.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public function __construct(string $filePath, bool $overwrite=true)
|
||||
public function __construct(string $file_path, bool $overwrite=true)
|
||||
{
|
||||
if(!$overwrite && is_file($filePath))
|
||||
if(!$overwrite && is_file($file_path))
|
||||
{
|
||||
throw new IOException(sprintf('File \'%s\' already exists', $filePath));
|
||||
throw new IOException(sprintf('File \'%s\' already exists', $file_path));
|
||||
}
|
||||
|
||||
if(is_file($filePath))
|
||||
if(is_file($file_path))
|
||||
{
|
||||
unlink($filePath);
|
||||
unlink($file_path);
|
||||
}
|
||||
|
||||
if(is_file($filePath . '.tmp'))
|
||||
if(is_file($file_path . '.tmp'))
|
||||
{
|
||||
unlink($filePath . '.tmp');
|
||||
unlink($file_path . '.tmp');
|
||||
}
|
||||
|
||||
// Create the parent directory if it doesn't exist
|
||||
if(!is_dir(dirname($filePath)))
|
||||
if(!is_dir(dirname($file_path)))
|
||||
{
|
||||
if (!mkdir($concurrentDirectory = dirname($filePath), 0777, true) && !is_dir($concurrentDirectory))
|
||||
if (!mkdir($concurrentDirectory = dirname($file_path), 0777, true) && !is_dir($concurrentDirectory))
|
||||
{
|
||||
throw new IOException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
||||
}
|
||||
}
|
||||
|
||||
touch($filePath);
|
||||
touch($filePath . '.tmp');
|
||||
touch($file_path);
|
||||
touch($file_path . '.tmp');
|
||||
|
||||
$this->dataWritten = false;
|
||||
$this->temporaryPath = $filePath . '.tmp';
|
||||
$this->tempFile = @fopen($this->temporaryPath, 'wb'); // Create a temporary data file
|
||||
$this->packageFile = @fopen($filePath, 'wb');
|
||||
$this->data_written = false;
|
||||
$this->temporary_path = $file_path . '.tmp';
|
||||
$this->temp_file = @fopen($this->temporary_path, 'wb'); // Create a temporary data file
|
||||
$this->package_file = @fopen($file_path, 'wb');
|
||||
$this->headers = [
|
||||
PackageStructure::FILE_VERSION->value => PackageStructureVersions::_2_0->value,
|
||||
PackageStructure::FLAGS->value => [],
|
||||
PackageStructure::DIRECTORY->value => []
|
||||
];
|
||||
|
||||
if($this->tempFile === false || $this->packageFile === false)
|
||||
if($this->temp_file === false || $this->package_file === false)
|
||||
{
|
||||
throw new IOException(sprintf('Failed to open file \'%s\'', $filePath));
|
||||
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@
|
|||
*/
|
||||
public function setFlags(array $flags): void
|
||||
{
|
||||
if($this->dataWritten)
|
||||
if($this->data_written)
|
||||
{
|
||||
throw new IOException('Cannot set flags after data has been written to the package');
|
||||
}
|
||||
|
@ -198,7 +198,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
if($this->dataWritten)
|
||||
if($this->data_written)
|
||||
{
|
||||
throw new IOException('Cannot add a flag after data has been written to the package');
|
||||
}
|
||||
|
@ -227,7 +227,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
if($this->dataWritten)
|
||||
if($this->data_written)
|
||||
{
|
||||
throw new IOException('Cannot remove a flag after data has been written to the package');
|
||||
}
|
||||
|
@ -269,10 +269,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
$pointer = sprintf("%d:%d", ftell($this->tempFile), strlen($data));
|
||||
$pointer = sprintf("%d:%d", ftell($this->temp_file), strlen($data));
|
||||
$this->headers[PackageStructure::DIRECTORY->value][$name] = $pointer;
|
||||
$this->dataWritten = true;
|
||||
fwrite($this->tempFile, $data);
|
||||
$this->data_written = true;
|
||||
fwrite($this->temp_file, $data);
|
||||
|
||||
return explode(':', $pointer);
|
||||
}
|
||||
|
@ -395,7 +395,7 @@
|
|||
public function merge(PackageReader $reader): void
|
||||
{
|
||||
$progress_bar = new ConsoleProgressBar(sprintf('Merging %s', $reader->getAssembly()->getPackage()), count($reader->getDirectory()));
|
||||
$processedResources = [];
|
||||
$processed_resources = [];
|
||||
|
||||
foreach($reader->getDirectory() as $name => $pointer)
|
||||
{
|
||||
|
@ -411,15 +411,15 @@
|
|||
break;
|
||||
|
||||
default:
|
||||
if(isset($processedResources[$pointer]))
|
||||
if(isset($processed_resources[$pointer]))
|
||||
{
|
||||
Console::outDebug(sprintf('Merging %s as a pointer', $name));
|
||||
$this->addPointer($name, (int)$processedResources[$pointer][0], (int)$processedResources[$pointer][1]);
|
||||
$this->addPointer($name, (int)$processed_resources[$pointer][0], (int)$processed_resources[$pointer][1]);
|
||||
break;
|
||||
}
|
||||
|
||||
Console::outDebug(sprintf('Merging %s', $name));
|
||||
$processedResources[$pointer] = $this->add($name, $reader->get($name));
|
||||
$processed_resources[$pointer] = $this->add($name, $reader->get($name));
|
||||
}
|
||||
|
||||
$progress_bar->increaseValue(1, true);
|
||||
|
@ -437,34 +437,34 @@
|
|||
*/
|
||||
public function close(): void
|
||||
{
|
||||
if(!is_resource($this->packageFile) || !is_resource($this->tempFile))
|
||||
if(!is_resource($this->package_file) || !is_resource($this->temp_file))
|
||||
{
|
||||
throw new IOException('Package is already closed');
|
||||
}
|
||||
|
||||
// Close the temporary data file
|
||||
fclose($this->tempFile);
|
||||
fclose($this->temp_file);
|
||||
|
||||
// Write the magic bytes "ncc_pkg" to the package and the header
|
||||
fwrite($this->packageFile, 'ncc_pkg');
|
||||
fwrite($this->packageFile, ZiProto::encode($this->headers));
|
||||
fwrite($this->packageFile, "\x1F\x1F\x1F\x1F");
|
||||
fwrite($this->package_file, 'ncc_pkg');
|
||||
fwrite($this->package_file, ZiProto::encode($this->headers));
|
||||
fwrite($this->package_file, "\x1F\x1F\x1F\x1F");
|
||||
|
||||
// Copy the temporary data file to the package
|
||||
$temp_file = fopen($this->temporaryPath, 'rb');
|
||||
stream_copy_to_stream($temp_file, $this->packageFile);
|
||||
$temp_file = fopen($this->temporary_path, 'rb');
|
||||
stream_copy_to_stream($temp_file, $this->package_file);
|
||||
|
||||
// End the package by writing the end-of-package delimiter (0xFFAA55F0)
|
||||
fwrite($this->packageFile, "\xFF\xAA\x55\xF0");
|
||||
fwrite($this->package_file, "\xFF\xAA\x55\xF0");
|
||||
|
||||
// Close the file handles
|
||||
fclose($this->packageFile);
|
||||
fclose($this->package_file);
|
||||
fclose($temp_file);
|
||||
|
||||
unlink($this->temporaryPath);
|
||||
unlink($this->temporary_path);
|
||||
|
||||
$this->packageFile = null;
|
||||
$this->tempFile = null;
|
||||
$this->package_file = null;
|
||||
$this->temp_file = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -482,14 +482,14 @@
|
|||
}
|
||||
finally
|
||||
{
|
||||
if(is_resource($this->packageFile))
|
||||
if(is_resource($this->package_file))
|
||||
{
|
||||
fclose($this->packageFile);
|
||||
fclose($this->package_file);
|
||||
}
|
||||
|
||||
if(is_resource($this->tempFile))
|
||||
if(is_resource($this->temp_file))
|
||||
{
|
||||
fclose($this->tempFile);
|
||||
fclose($this->temp_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|