Compare commits

..

18 commits

Author SHA1 Message Date
6909790de6
Update GitHub Actions to use download-artifact@v4 for enhanced performance
Some checks are pending
CI Pipeline / build (push) Waiting to run
CI Pipeline / test-install (push) Blocked by required conditions
CI Pipeline / upload-release (push) Blocked by required conditions
2025-03-17 15:06:09 -04:00
db631bd778
Update GitHub Actions to use upload-artifact@v4 for improved functionality
Some checks are pending
CI Pipeline / build (push) Waiting to run
CI Pipeline / test-install (push) Blocked by required conditions
CI Pipeline / upload-release (push) Blocked by required conditions
2025-03-17 15:03:11 -04:00
1b8b3f8ad7
Temporarily disable cache file deletion to prevent loss of important files
Some checks are pending
CI Pipeline / build (push) Waiting to run
CI Pipeline / test-install (push) Blocked by required conditions
CI Pipeline / upload-release (push) Blocked by required conditions
2025-03-17 14:29:19 -04:00
ccb1ef6971
Improve error handling in ArchiveExtractor by catching ValueError during zip archive closure
Some checks are pending
CI Pipeline / build (push) Waiting to run
CI Pipeline / test-install (push) Blocked by required conditions
CI Pipeline / upload-release (push) Blocked by required conditions
2025-03-17 03:17:47 -04:00
ead20f7924
Improve error handling in ShutdownHandler by logging warnings for cleanup failures 2025-03-11 13:56:37 -04:00
487eb70b0b
Refactor variable names for consistency and clarity in ShutdownHandler and PackageWriter classes 2025-03-11 13:56:05 -04:00
1e45b47f0f
Bumped version to 2.1.7 2025-03-10 15:30:56 -04:00
d861998f4f
Merge branch 'master' into dev 2025-03-10 15:25:59 -04:00
netkas
d57666b40d
Updated README.md 2025-03-10 15:18:34 -04:00
netkas
05882205f0
Updated Permissions 2025-03-10 15:13:50 -04:00
netkas
2bd78a1d79
Added Community Section 2025-03-10 15:13:17 -04:00
netkas
81894af835
Updated TOC 2025-03-10 15:05:15 -04:00
netkas
b975508d07 Indentation Correction 2025-01-08 15:46:13 -05:00
netkas
1ef96c3c4c Updated CHANGELOG.md 2024-10-29 12:28:41 -04:00
netkas
2dad5133bd Updated .gitignore 2024-10-25 19:59:33 -04:00
netkas
544d4ebdf6 Validate package instance before checking execution policy 2024-10-25 19:59:22 -04:00
netkas
41947069be Bumped version to 2.1.6 2024-10-25 19:56:25 -04:00
netkas
11aaa39eaa Update build script and bump version to 2.1.5 2024-10-14 15:29:32 -04:00
707 changed files with 336 additions and 281 deletions

12
.github/workflows/ci.yml vendored Normal file → Executable file
View file

@ -50,7 +50,7 @@ jobs:
run: echo "NCC_DIR=$(find build/ -type d -name 'ncc_*' | head -n 1)" >> $GITHUB_ENV run: echo "NCC_DIR=$(find build/ -type d -name 'ncc_*' | head -n 1)" >> $GITHUB_ENV
- name: Upload NCC build directory - name: Upload NCC build directory
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: ncc-build name: ncc-build
path: ${{ env.NCC_DIR }} path: ${{ env.NCC_DIR }}
@ -59,7 +59,7 @@ jobs:
run: zip -r redist.zip ${{ env.NCC_DIR }} run: zip -r redist.zip ${{ env.NCC_DIR }}
- name: Upload redist.zip - name: Upload redist.zip
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: redist-zip name: redist-zip
path: 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 run: echo "DEB_FILE=$(find build/ -type f -name '*.deb' | head -n 1)" >> $GITHUB_ENV
- name: Upload Debian package - name: Upload Debian package
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: ncc-deb name: ncc-deb
path: ${{ env.DEB_FILE }} path: ${{ env.DEB_FILE }}
@ -83,7 +83,7 @@ jobs:
steps: steps:
- name: Download NCC build directory - name: Download NCC build directory
uses: actions/download-artifact@v3 uses: actions/download-artifact@v4
with: with:
name: ncc-build name: ncc-build
path: build path: build
@ -107,13 +107,13 @@ jobs:
steps: steps:
- name: Download redist.zip - name: Download redist.zip
uses: actions/download-artifact@v3 uses: actions/download-artifact@v4
with: with:
name: redist-zip name: redist-zip
path: . path: .
- name: Download Debian package - name: Download Debian package
uses: actions/download-artifact@v3 uses: actions/download-artifact@v4
with: with:
name: ncc-deb name: ncc-deb
path: . path: .

1
.gitignore vendored Normal file → Executable file
View file

@ -31,3 +31,4 @@ tests/example_project/ncc
tests/example_project/build tests/example_project/build
/.phpunit.result.cache /.phpunit.result.cache
/.idea/php-test-framework.xml /.idea/php-test-framework.xml
/.idea/gbrowser_project.xml

0
.gitlab-ci.yml Normal file → Executable file
View file

0
.idea/.gitignore generated vendored Normal file → Executable file
View file

0
.idea/.name generated Normal file → Executable file
View file

0
.idea/Nosial Code Compiler.iml generated Normal file → Executable file
View file

0
.idea/codeStyles/Project.xml generated Normal file → Executable file
View file

0
.idea/codeStyles/codeStyleConfig.xml generated Normal file → Executable file
View file

0
.idea/copyright/Nosial.xml generated Normal file → Executable file
View file

0
.idea/copyright/profiles_settings.xml generated Normal file → Executable file
View file

0
.idea/encodings.xml generated Normal file → Executable file
View file

0
.idea/inspectionProfiles/Project_Default.xml generated Normal file → Executable file
View file

0
.idea/modules.xml generated Normal file → Executable file
View file

0
.idea/php-inspections-ea-ultimate.xml generated Normal file → Executable file
View file

0
.idea/php.xml generated Normal file → Executable file
View file

0
.idea/runConfigurations/Build_Redist.xml generated Normal file → Executable file
View file

0
.idea/runConfigurations/Rebuild_Autoloaders.xml generated Normal file → Executable file
View file

0
.idea/scopes/Autoloaders.xml generated Normal file → Executable file
View file

0
.idea/scopes/Installer_Source_files.xml generated Normal file → Executable file
View file

0
.idea/scopes/NCC_Source_files.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_Filesystem.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_Process.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_Uid.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_Yaml.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_polyfill_ctype.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_polyfill_mbstring.xml generated Normal file → Executable file
View file

0
.idea/scopes/Symfony_polyfill_uuid.xml generated Normal file → Executable file
View file

0
.idea/scopes/Third_Party_Source_Files.xml generated Normal file → Executable file
View file

0
.idea/scopes/defuse.xml generated Normal file → Executable file
View file

0
.idea/scopes/defuse_php_encryption.xml generated Normal file → Executable file
View file

0
.idea/scopes/jelix.xml generated Normal file → Executable file
View file

0
.idea/scopes/jelix_version.xml generated Normal file → Executable file
View file

0
.idea/scopes/nikic.xml generated Normal file → Executable file
View file

0
.idea/scopes/nikic_PhpParser.xml generated Normal file → Executable file
View file

0
.idea/scopes/theseer.xml generated Normal file → Executable file
View file

0
.idea/scopes/theseer_Autoload.xml generated Normal file → Executable file
View file

0
.idea/scopes/theseer_DirectoryScanner.xml generated Normal file → Executable file
View file

0
.idea/vcs.xml generated Normal file → Executable file
View file

0
.idea/webResources.xml generated Normal file → Executable file
View file

35
CHANGELOG.md Normal file → Executable file
View file

@ -5,6 +5,41 @@ 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/), 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). 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 ## [2.1.4] - 2024-10-13
This update introduces minor bug fixes & improvements This update introduces minor bug fixes & improvements

0
CODE_OF_CONDUCT.md Normal file → Executable file
View file

0
CONTRIBUTING.md Normal file → Executable file
View file

2
DOCUMENTATION.md Normal file → Executable file
View file

@ -62,7 +62,7 @@ basic usage, standards, and much more.
* [Package Metadata (metadata)](#package-metadata-metadata) * [Package Metadata (metadata)](#package-metadata-metadata)
* [Assembly Information (assembly)](#assembly-information-assembly) * [Assembly Information (assembly)](#assembly-information-assembly)
* [Package Dependencies (dependencies)](#package-dependencies-dependencies) * [Package Dependencies (dependencies)](#package-dependencies-dependencies)
* [Execution Units (execution_units)](#execution-units-executionunits) * [Execution Units (execution_units)](#execution-units-execution_units)
* [Building Projects (build)](#building-projects-build) * [Building Projects (build)](#building-projects-build)
* [Execute (exec)](#execute-exec) * [Execute (exec)](#execute-exec)
* [Project Configuration (package.json)](#project-configuration-packagejson) * [Project Configuration (package.json)](#project-configuration-packagejson)

0
Dockerfile Normal file → Executable file
View file

0
Dockerfile.debian Normal file → Executable file
View file

0
LICENSE Normal file → Executable file
View file

0
Makefile Normal file → Executable file
View file

13
README.md Normal file → Executable file
View file

@ -6,6 +6,19 @@ 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 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. 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 ## Features

0
assets/compiler_process.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

0
assets/data_structure.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

0
assets/execution_process.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

0
assets/header_structure.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

0
assets/icon/ncc.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 683 B

After

Width:  |  Height:  |  Size: 683 B

0
assets/icon/ncc@1024px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

0
assets/icon/ncc@128px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

0
assets/icon/ncc@16px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 351 B

0
assets/icon/ncc@256px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

0
assets/icon/ncc@32px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 504 B

After

Width:  |  Height:  |  Size: 504 B

0
assets/icon/ncc@512px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

0
assets/icon/ncc@64px.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 820 B

After

Width:  |  Height:  |  Size: 820 B

0
assets/package_structure.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

0
bootstrap.php Normal file → Executable file
View file

0
old_docker/Dockerfile Normal file → Executable file
View file

0
old_docker/Dockerfile.debian Normal file → Executable file
View file

0
old_docker/note.txt Normal file → Executable file
View file

0
phpunit.xml Normal file → Executable file
View file

0
src/autoload/autoload.php Normal file → Executable file
View file

0
src/config/default_repositories.json Normal file → Executable file
View file

0
src/config/ncc.yaml Normal file → Executable file
View file

0
src/debian/control Normal file → Executable file
View file

0
src/debian/copyright Normal file → Executable file
View file

0
src/debian/postinst Normal file → Executable file
View file

0
src/debian/postrm Normal file → Executable file
View file

0
src/installer/generate_build_files.php Normal file → Executable file
View file

0
src/installer/hash_check.php Normal file → Executable file
View file

0
src/installer/installer Normal file → Executable file
View file

0
src/installer/ncc-package.xml Normal file → Executable file
View file

0
src/installer/ncc.desktop Normal file → Executable file
View file

0
src/ncc/CLI/Commands/BuildCommand.php Normal file → Executable file
View file

0
src/ncc/CLI/Commands/ExecCommand.php Normal file → Executable file
View file

0
src/ncc/CLI/Commands/PackageInspectorCommand.php Normal file → Executable file
View file

0
src/ncc/CLI/Commands/SetupCommand.php Normal file → Executable file
View file

0
src/ncc/CLI/HelpMenu.php Normal file → Executable file
View file

0
src/ncc/CLI/Main.php Normal file → Executable file
View file

0
src/ncc/CLI/Management/ConfigMenu.php Normal file → Executable file
View file

0
src/ncc/CLI/Management/CredentialMenu.php Normal file → Executable file
View file

0
src/ncc/CLI/Management/PackageManagerMenu.php Normal file → Executable file
View file

0
src/ncc/CLI/Management/ProjectMenu.php Normal file → Executable file
View file

0
src/ncc/CLI/Management/RepositoryMenu.php Normal file → Executable file
View file

8
src/ncc/Classes/ArchiveExtractor.php Normal file → Executable file
View file

@ -29,6 +29,7 @@
use ncc\Utilities\Console; use ncc\Utilities\Console;
use PharData; use PharData;
use RuntimeException; use RuntimeException;
use ValueError;
use ZipArchive; use ZipArchive;
class ArchiveExtractor class ArchiveExtractor
@ -126,6 +127,13 @@
} }
} }
try
{
$zip_archive->close(); $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 Normal file → Executable file
View file

0
src/ncc/Classes/ExecutionUnitRunner.php Normal file → Executable file
View file

0
src/ncc/Classes/GiteaExtension/GiteaRepository.php Normal file → Executable file
View file

0
src/ncc/Classes/GithubExtension/GithubRepository.php Normal file → Executable file
View file

0
src/ncc/Classes/GitlabExtension/GitlabRepository.php Normal file → Executable file
View file

0
src/ncc/Classes/LuaExtension/LuaRunner.php Normal file → Executable file
View file

0
src/ncc/Classes/NccExtension/ConstantCompiler.php Normal file → Executable file
View file

0
src/ncc/Classes/NccExtension/NccCompiler.php Normal file → Executable file
View file

144
src/ncc/Classes/PackageReader.php Normal file → Executable file
View file

@ -47,32 +47,32 @@
/** /**
* @var int * @var int
*/ */
private $package_offset; private $packageOffset;
/** /**
* @var int * @var int
*/ */
private $package_length; private $packageLength;
/** /**
* @var int * @var int
*/ */
private $header_offset; private $headerOffset;
/** /**
* @var int * @var int
*/ */
private $header_length; private $headerLength;
/** /**
* @var int * @var int
*/ */
private $data_offset; private $dataOffset;
/** /**
* @var int * @var int
*/ */
private $data_length; private $dataLength;
/** /**
* @var array * @var array
@ -82,12 +82,12 @@
/** /**
* @var resource * @var resource
*/ */
private $package_file; private $packageFile;
/** /**
* @var string * @var string
*/ */
private $package_path; private $packagePath;
/** /**
* @var array * @var array
@ -107,10 +107,10 @@
throw new IOException(sprintf('File \'%s\' does not exist', $file_path)); throw new IOException(sprintf('File \'%s\' does not exist', $file_path));
} }
$this->package_path = $file_path; $this->packagePath = $file_path;
$this->package_file = fopen($file_path, 'rb'); $this->packageFile = fopen($file_path, 'rb');
if($this->package_file === false) if($this->packageFile === false)
{ {
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path)); throw new IOException(sprintf('Failed to open file \'%s\'', $file_path));
} }
@ -122,41 +122,41 @@
// End of data: \xFF\xAA\x55\xF0 // End of data: \xFF\xAA\x55\xF0
// First find the offset of the package by searching for the magic bytes "ncc_pkg" // First find the offset of the package by searching for the magic bytes "ncc_pkg"
$this->package_offset = 0; $this->packageOffset = 0;
while(!feof($this->package_file)) while(!feof($this->packageFile))
{ {
$buffer = fread($this->package_file, 1024); $buffer = fread($this->packageFile, 1024);
$buffer_length = strlen($buffer); $buffer_length = strlen($buffer);
$this->package_offset += $buffer_length; $this->packageOffset += $buffer_length;
if (($position = strpos($buffer, "ncc_pkg")) !== false) if (($position = strpos($buffer, "ncc_pkg")) !== false)
{ {
$this->package_offset -= $buffer_length - $position; $this->packageOffset -= $buffer_length - $position;
$this->package_length = 7; // ncc_pkg $this->packageLength = 7; // ncc_pkg
$this->header_offset = $this->package_offset + 7; $this->headerOffset = $this->packageOffset + 7;
break; break;
} }
} }
// Check for sanity reasons // Check for sanity reasons
if($this->package_offset === null || $this->package_length === null) if($this->packageOffset === null || $this->packageLength === null)
{ {
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing magic bytes)', $file_path)); 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) // Seek the header until the end of headers byte sequence (1F 1F 1F 1F)
fseek($this->package_file, $this->header_offset); fseek($this->packageFile, $this->headerOffset);
while (!feof($this->package_file)) while (!feof($this->packageFile))
{ {
$this->headers .= fread($this->package_file, 1024); $this->headers .= fread($this->packageFile, 1024);
// Search for the position of "1F 1F 1F 1F" within the buffer // Search for the position of "1F 1F 1F 1F" within the buffer
if (($position = strpos($this->headers, "\x1F\x1F\x1F\x1F")) !== false) if (($position = strpos($this->headers, "\x1F\x1F\x1F\x1F")) !== false)
{ {
$this->headers = substr($this->headers, 0, $position); $this->headers = substr($this->headers, 0, $position);
$this->header_length = strlen($this->headers); $this->headerLength = strlen($this->headers);
$this->package_length += $this->header_length + 4; $this->packageLength += $this->headerLength + 4;
$this->data_offset = $this->header_offset + $this->header_length + 4; $this->dataOffset = $this->headerOffset + $this->headerLength + 4;
break; break;
} }
@ -181,19 +181,19 @@
} }
// Seek the data until the end of the package (FF AA 55 F0) // Seek the data until the end of the package (FF AA 55 F0)
fseek($this->package_file, $this->data_offset); fseek($this->packageFile, $this->dataOffset);
$buffer = ''; $buffer = '';
while(!feof($this->package_file)) while(!feof($this->packageFile))
{ {
$current_chunk = fread($this->package_file, 1024); $current_chunk = fread($this->packageFile, 1024);
$this->data_length += strlen($current_chunk); $this->dataLength += strlen($current_chunk);
$buffer .= $current_chunk; $buffer .= $current_chunk;
// If we detect the end-of-data byte sequence // If we detect the end-of-data byte sequence
if (($position = strpos($buffer, "\xFF\xAA\x55\xF0")) !== false) if (($position = strpos($buffer, "\xFF\xAA\x55\xF0")) !== false)
{ {
$this->data_length -= strlen($buffer) - $position; $this->dataLength -= strlen($buffer) - $position;
$this->package_length += $this->data_length + 4; $this->packageLength += $this->dataLength + 4;
break; break;
} }
@ -206,7 +206,7 @@
} }
if($this->data_length === null || $this->data_length === 0) if($this->dataLength === null || $this->dataLength === 0)
{ {
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing end of package)', $file_path)); throw new IOException(sprintf('File \'%s\' is not a valid package file (missing end of package)', $file_path));
} }
@ -275,18 +275,18 @@
{ {
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
{ {
throw new RuntimeException(sprintf('File \'%s\' not found in package \'%s\'', $name, $this->package_path)); throw new RuntimeException(sprintf('File \'%s\' not found in package \'%s\'', $name, $this->packagePath));
} }
$location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]); $location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
fseek($this->package_file, ($this->data_offset + (int)$location[0])); fseek($this->packageFile, ($this->dataOffset + (int)$location[0]));
if(in_array(PackageFlags::COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true)) if(in_array(PackageFlags::COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
{ {
return gzuncompress(fread($this->package_file, (int)$location[1])); return gzuncompress(fread($this->packageFile, (int)$location[1]));
} }
return fread($this->package_file, (int)$location[1]); return fread($this->packageFile, (int)$location[1]);
} }
/** /**
@ -299,7 +299,7 @@
{ {
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
{ {
throw new RuntimeException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->package_path)); throw new RuntimeException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->packagePath));
} }
$location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]); $location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
@ -326,8 +326,8 @@
*/ */
public function getByPointer(int $pointer, int $length): string public function getByPointer(int $pointer, int $length): string
{ {
fseek($this->package_file, ($this->header_length + $pointer)); fseek($this->packageFile, ($this->headerLength + $pointer));
return fread($this->package_file, $length); return fread($this->packageFile, $length);
} }
/** /**
@ -348,7 +348,7 @@
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
{ {
throw new ConfigurationException(sprintf('Assembly object not found in package \'%s\'', $this->package_path)); throw new ConfigurationException(sprintf('Assembly object not found in package \'%s\'', $this->packagePath));
} }
try try
@ -357,7 +357,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode assembly from package \'%s\' using ZiProto: %s', $this->package_path, $e->getMessage()), $e); throw new IntegrityException(sprintf('Failed to decode assembly from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
} }
$this->cache[$directory] = $assembly; $this->cache[$directory] = $assembly;
@ -382,7 +382,7 @@
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
{ {
throw new ConfigurationException(sprintf('Metadata object not found in package \'%s\'', $this->package_path)); throw new ConfigurationException(sprintf('Metadata object not found in package \'%s\'', $this->packagePath));
} }
try try
@ -391,7 +391,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode metadata from package \'%s\' using ZiProto: %s', $this->package_path, $e->getMessage()), $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) foreach($this->getFlags() as $flag)
@ -429,7 +429,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode installer from package \'%s\' using ZiProto: %s', $this->package_path, $e->getMessage()), $e); throw new IntegrityException(sprintf('Failed to decode installer from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
} }
$this->cache[$directory] = $installer; $this->cache[$directory] = $installer;
@ -470,7 +470,7 @@
$dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $name); $dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $name);
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$dependency_name])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$dependency_name]))
{ {
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package \'%s\'', $name, $this->package_path)); throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package \'%s\'', $name, $this->packagePath));
} }
try try
@ -479,7 +479,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode dependency \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->package_path, $e->getMessage()), $e); throw new IntegrityException(sprintf('Failed to decode dependency \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
} }
} }
@ -499,7 +499,7 @@
} }
catch(Exception $e) 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->package_path, $e->getMessage()), $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);
} }
} }
@ -537,7 +537,7 @@
$execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name); $execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name);
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$execution_unit_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->package_path)); throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package \'%s\'', $name, $this->packagePath));
} }
try try
@ -546,7 +546,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode execution unit \'%s\' from package file \'%s\' using ZiProto: %s', $name, $this->package_path, $e->getMessage()), $e); throw new IntegrityException(sprintf('Failed to decode execution unit \'%s\' from package file \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
} }
} }
@ -577,7 +577,7 @@
} }
catch(Exception $e) 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->package_path, $e->getMessage()), $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);
} }
} }
@ -636,7 +636,7 @@
$component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $name); $component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $name);
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$component_name])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$component_name]))
{ {
throw new ConfigurationException(sprintf('Component \'%s\' not found in package \'%s\'', $name, $this->package_path)); throw new ConfigurationException(sprintf('Component \'%s\' not found in package \'%s\'', $name, $this->packagePath));
} }
try try
@ -645,7 +645,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode component \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->package_path, $e->getMessage()), $e); throw new IntegrityException(sprintf('Failed to decode component \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
} }
} }
@ -665,7 +665,7 @@
} }
catch(Exception $e) 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->package_path, $e->getMessage()), $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);
} }
} }
@ -682,7 +682,7 @@
$class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class); $class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class);
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$class_name])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$class_name]))
{ {
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package \'%s\'', $class, $this->package_path)); throw new ConfigurationException(sprintf('Class map \'%s\' not found in package \'%s\'', $class, $this->packagePath));
} }
try try
@ -691,7 +691,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode component from class pointer \'%s\' from package \'%s\' using ZiProto: %s', $class, $this->package_path, $e->getMessage()), $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);
} }
} }
@ -729,7 +729,7 @@
$resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $name); $resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $name);
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$resource_name])) if(!isset($this->headers[PackageStructure::DIRECTORY->value][$resource_name]))
{ {
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->package_path)); throw new ConfigurationException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->packagePath));
} }
try try
@ -738,7 +738,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
throw new IntegrityException(sprintf('Failed to decode resource \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->package_path, $e->getMessage()), $e); throw new IntegrityException(sprintf('Failed to decode resource \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
} }
} }
@ -758,7 +758,7 @@
} }
catch(Exception $e) 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->package_path, $e->getMessage()), $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);
} }
} }
@ -788,7 +788,7 @@
*/ */
public function getPackageOffset(): int public function getPackageOffset(): int
{ {
return $this->package_offset; return $this->packageOffset;
} }
/** /**
@ -796,7 +796,7 @@
*/ */
public function getPackageLength(): int public function getPackageLength(): int
{ {
return $this->package_length; return $this->packageLength;
} }
/** /**
@ -804,7 +804,7 @@
*/ */
public function getHeaderOffset(): int public function getHeaderOffset(): int
{ {
return $this->header_offset; return $this->headerOffset;
} }
/** /**
@ -812,7 +812,7 @@
*/ */
public function getHeaderLength(): int public function getHeaderLength(): int
{ {
return $this->header_length; return $this->headerLength;
} }
/** /**
@ -820,7 +820,7 @@
*/ */
public function getDataOffset(): int public function getDataOffset(): int
{ {
return $this->data_offset; return $this->dataOffset;
} }
/** /**
@ -828,7 +828,7 @@
*/ */
public function getDataLength(): int public function getDataLength(): int
{ {
return $this->data_length; return $this->dataLength;
} }
/** /**
@ -842,12 +842,12 @@
{ {
$checksum = hash($hash, '', $binary); $checksum = hash($hash, '', $binary);
fseek($this->package_file, $this->package_offset); fseek($this->packageFile, $this->packageOffset);
$bytes_left = $this->package_length; $bytes_left = $this->packageLength;
while ($bytes_left > 0) while ($bytes_left > 0)
{ {
$buffer = fread($this->package_file, min(1024, $bytes_left)); $buffer = fread($this->packageFile, min(1024, $bytes_left));
$buffer_length = strlen($buffer); $buffer_length = strlen($buffer);
$bytes_left -= $buffer_length; $bytes_left -= $buffer_length;
$checksum = hash($hash, ($checksum . $buffer), $binary); $checksum = hash($hash, ($checksum . $buffer), $binary);
@ -875,13 +875,13 @@
throw new IOException(sprintf('Failed to open file \'%s\'', $path)); throw new IOException(sprintf('Failed to open file \'%s\'', $path));
} }
fseek($this->package_file, $this->package_offset); fseek($this->packageFile, $this->packageOffset);
$remaining_bytes = $this->package_length; $remaining_bytes = $this->packageLength;
while($remaining_bytes > 0) while($remaining_bytes > 0)
{ {
$bytes_to_read = min($remaining_bytes, 4096); $bytes_to_read = min($remaining_bytes, 4096);
$data = fread($this->package_file, $bytes_to_read); $data = fread($this->packageFile, $bytes_to_read);
if ($data === false) if ($data === false)
{ {
@ -911,9 +911,9 @@
*/ */
public function __destruct() public function __destruct()
{ {
if(is_resource($this->package_file)) if(is_resource($this->packageFile))
{ {
fclose($this->package_file); fclose($this->packageFile);
} }
} }
} }

94
src/ncc/Classes/PackageWriter.php Normal file → Executable file
View file

@ -53,70 +53,70 @@
/** /**
* @var resource * @var resource
*/ */
private $temp_file; private $tempFile;
/** /**
* @var resource * @var resource
*/ */
private $package_file; private $packageFile;
/** /**
* @var string; * @var string;
*/ */
private $temporary_path; private $temporaryPath;
/** /**
* @var bool * @var bool
*/ */
private $data_written; private $dataWritten;
/** /**
* PackageWriter constructor. * PackageWriter constructor.
* *
* @throws IOException * @throws IOException
*/ */
public function __construct(string $file_path, bool $overwrite=true) public function __construct(string $filePath, bool $overwrite=true)
{ {
if(!$overwrite && is_file($file_path)) if(!$overwrite && is_file($filePath))
{ {
throw new IOException(sprintf('File \'%s\' already exists', $file_path)); throw new IOException(sprintf('File \'%s\' already exists', $filePath));
} }
if(is_file($file_path)) if(is_file($filePath))
{ {
unlink($file_path); unlink($filePath);
} }
if(is_file($file_path . '.tmp')) if(is_file($filePath . '.tmp'))
{ {
unlink($file_path . '.tmp'); unlink($filePath . '.tmp');
} }
// Create the parent directory if it doesn't exist // Create the parent directory if it doesn't exist
if(!is_dir(dirname($file_path))) if(!is_dir(dirname($filePath)))
{ {
if (!mkdir($concurrentDirectory = dirname($file_path), 0777, true) && !is_dir($concurrentDirectory)) if (!mkdir($concurrentDirectory = dirname($filePath), 0777, true) && !is_dir($concurrentDirectory))
{ {
throw new IOException(sprintf('Directory "%s" was not created', $concurrentDirectory)); throw new IOException(sprintf('Directory "%s" was not created', $concurrentDirectory));
} }
} }
touch($file_path); touch($filePath);
touch($file_path . '.tmp'); touch($filePath . '.tmp');
$this->data_written = false; $this->dataWritten = false;
$this->temporary_path = $file_path . '.tmp'; $this->temporaryPath = $filePath . '.tmp';
$this->temp_file = @fopen($this->temporary_path, 'wb'); // Create a temporary data file $this->tempFile = @fopen($this->temporaryPath, 'wb'); // Create a temporary data file
$this->package_file = @fopen($file_path, 'wb'); $this->packageFile = @fopen($filePath, 'wb');
$this->headers = [ $this->headers = [
PackageStructure::FILE_VERSION->value => PackageStructureVersions::_2_0->value, PackageStructure::FILE_VERSION->value => PackageStructureVersions::_2_0->value,
PackageStructure::FLAGS->value => [], PackageStructure::FLAGS->value => [],
PackageStructure::DIRECTORY->value => [] PackageStructure::DIRECTORY->value => []
]; ];
if($this->temp_file === false || $this->package_file === false) if($this->tempFile === false || $this->packageFile === false)
{ {
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path)); throw new IOException(sprintf('Failed to open file \'%s\'', $filePath));
} }
} }
@ -160,7 +160,7 @@
*/ */
public function setFlags(array $flags): void public function setFlags(array $flags): void
{ {
if($this->data_written) if($this->dataWritten)
{ {
throw new IOException('Cannot set flags after data has been written to the package'); throw new IOException('Cannot set flags after data has been written to the package');
} }
@ -198,7 +198,7 @@
} }
} }
if($this->data_written) if($this->dataWritten)
{ {
throw new IOException('Cannot add a flag after data has been written to the package'); throw new IOException('Cannot add a flag after data has been written to the package');
} }
@ -227,7 +227,7 @@
} }
} }
if($this->data_written) if($this->dataWritten)
{ {
throw new IOException('Cannot remove a flag after data has been written to the package'); 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->temp_file), strlen($data)); $pointer = sprintf("%d:%d", ftell($this->tempFile), strlen($data));
$this->headers[PackageStructure::DIRECTORY->value][$name] = $pointer; $this->headers[PackageStructure::DIRECTORY->value][$name] = $pointer;
$this->data_written = true; $this->dataWritten = true;
fwrite($this->temp_file, $data); fwrite($this->tempFile, $data);
return explode(':', $pointer); return explode(':', $pointer);
} }
@ -395,7 +395,7 @@
public function merge(PackageReader $reader): void public function merge(PackageReader $reader): void
{ {
$progress_bar = new ConsoleProgressBar(sprintf('Merging %s', $reader->getAssembly()->getPackage()), count($reader->getDirectory())); $progress_bar = new ConsoleProgressBar(sprintf('Merging %s', $reader->getAssembly()->getPackage()), count($reader->getDirectory()));
$processed_resources = []; $processedResources = [];
foreach($reader->getDirectory() as $name => $pointer) foreach($reader->getDirectory() as $name => $pointer)
{ {
@ -411,15 +411,15 @@
break; break;
default: default:
if(isset($processed_resources[$pointer])) if(isset($processedResources[$pointer]))
{ {
Console::outDebug(sprintf('Merging %s as a pointer', $name)); Console::outDebug(sprintf('Merging %s as a pointer', $name));
$this->addPointer($name, (int)$processed_resources[$pointer][0], (int)$processed_resources[$pointer][1]); $this->addPointer($name, (int)$processedResources[$pointer][0], (int)$processedResources[$pointer][1]);
break; break;
} }
Console::outDebug(sprintf('Merging %s', $name)); Console::outDebug(sprintf('Merging %s', $name));
$processed_resources[$pointer] = $this->add($name, $reader->get($name)); $processedResources[$pointer] = $this->add($name, $reader->get($name));
} }
$progress_bar->increaseValue(1, true); $progress_bar->increaseValue(1, true);
@ -437,34 +437,34 @@
*/ */
public function close(): void public function close(): void
{ {
if(!is_resource($this->package_file) || !is_resource($this->temp_file)) if(!is_resource($this->packageFile) || !is_resource($this->tempFile))
{ {
throw new IOException('Package is already closed'); throw new IOException('Package is already closed');
} }
// Close the temporary data file // Close the temporary data file
fclose($this->temp_file); fclose($this->tempFile);
// Write the magic bytes "ncc_pkg" to the package and the header // Write the magic bytes "ncc_pkg" to the package and the header
fwrite($this->package_file, 'ncc_pkg'); fwrite($this->packageFile, 'ncc_pkg');
fwrite($this->package_file, ZiProto::encode($this->headers)); fwrite($this->packageFile, ZiProto::encode($this->headers));
fwrite($this->package_file, "\x1F\x1F\x1F\x1F"); fwrite($this->packageFile, "\x1F\x1F\x1F\x1F");
// Copy the temporary data file to the package // Copy the temporary data file to the package
$temp_file = fopen($this->temporary_path, 'rb'); $temp_file = fopen($this->temporaryPath, 'rb');
stream_copy_to_stream($temp_file, $this->package_file); stream_copy_to_stream($temp_file, $this->packageFile);
// End the package by writing the end-of-package delimiter (0xFFAA55F0) // End the package by writing the end-of-package delimiter (0xFFAA55F0)
fwrite($this->package_file, "\xFF\xAA\x55\xF0"); fwrite($this->packageFile, "\xFF\xAA\x55\xF0");
// Close the file handles // Close the file handles
fclose($this->package_file); fclose($this->packageFile);
fclose($temp_file); fclose($temp_file);
unlink($this->temporary_path); unlink($this->temporaryPath);
$this->package_file = null; $this->packageFile = null;
$this->temp_file = null; $this->tempFile = null;
} }
/** /**
@ -482,14 +482,14 @@
} }
finally finally
{ {
if(is_resource($this->package_file)) if(is_resource($this->packageFile))
{ {
fclose($this->package_file); fclose($this->packageFile);
} }
if(is_resource($this->temp_file)) if(is_resource($this->tempFile))
{ {
fclose($this->temp_file); fclose($this->tempFile);
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show more