Skip to content

Commit

Permalink
Merge pull request #1 from retroluxfilm/omm1.2.x_support
Browse files Browse the repository at this point in the history
Update to supprt OMM 1.2.x
  • Loading branch information
retroluxfilm authored Jan 3, 2024
2 parents 0647f8c + 089ae8c commit 34eee1a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
18 changes: 12 additions & 6 deletions src/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Package
/**
* Package descriptor file
*/
private const PACKAGE_DESCRIPTOR_FILE = "package.omp";
private const PACKAGE_DESCRIPTOR_FILE_LEAGACY = "package.omp";
private const PACKAGE_DESCRIPTOR_FILE = "modpack.xml";

private PackageXML $packageXML;
protected string $packageArchiveFile;
Expand Down Expand Up @@ -92,7 +93,7 @@ public function createRemotePackageDescriptor(): RemotePackageDescriptor
$xml->preserveWhiteSpace = false;

//create remote root element
$remote = $xml->createElement(RemotePackageDescriptor::TAG_REMOTE);
$remote = $xml->createElement(RemotePackageDescriptor::TAG_MOD);
$remote->setAttribute(RemotePackageDescriptor::ATTRIBUTE_IDENT, $this->packageXML->getIdentifier());
$remote->setAttribute(RemotePackageDescriptor::ATTRIBUTE_FILE, $this->packageArchiveFile);
$remote->setAttribute(RemotePackageDescriptor::ATTRIBUTE_BYTES, $this->packageByteSize);
Expand All @@ -119,7 +120,7 @@ public function createRemotePackageDescriptor(): RemotePackageDescriptor
// Crop & Resize logo to max 128x128 pixels in size
$thumbnail = PackageHelper::createThumbnail($this->logoImageData);

$picture = $xml->createElement(RemotePackageDescriptor::TAG_PICTURE, PackageHelper::encodePackageLogo($thumbnail));
$picture = $xml->createElement(RemotePackageDescriptor::TAG_MOD_PICTURE, PackageHelper::encodePackageLogo($thumbnail));
$remote->appendChild($picture);
}

Expand Down Expand Up @@ -170,9 +171,14 @@ protected function retrieveInformationFromArchive(string $packageArchiveFilePath
// read package descriptor contents
$packageDescriptorData = $packageZip->getFromName(self::PACKAGE_DESCRIPTOR_FILE);
if ($packageDescriptorData === false) {
throw new Exception(
"OMM Package Descriptor (" . self::PACKAGE_DESCRIPTOR_FILE . ") not found or invalid in" . $packageArchiveFilePath
);

// read package descriptor contents (Legacy Mod package below OMM 1.2.x)
$packageDescriptorData = $packageZip->getFromName(self::PACKAGE_DESCRIPTOR_FILE_LEAGACY);
if ($packageDescriptorData === false) {
throw new Exception(
"OMM Package Descriptor (" . self::PACKAGE_DESCRIPTOR_FILE_LEAGACY . " or " . self::PACKAGE_DESCRIPTOR_FILE .") not found or invalid in" . $packageArchiveFilePath
);
}
}

// load package XML from the descriptor file
Expand Down
8 changes: 4 additions & 4 deletions src/Repository/RemotePackageDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class RemotePackageDescriptor
* Tags of the remote package descriptor
*/
public const
TAG_REMOTE = "remote",
TAG_PICTURE = "picture",
TAG_MOD = "mod",
TAG_MOD_PICTURE = "thumbnail",
TAG_DESCRIPTION = "description",
TAG_URL = "url";
/**
Expand All @@ -46,7 +46,7 @@ class RemotePackageDescriptor
ATTRIBUTE_FILE = "file",
ATTRIBUTE_BYTES = "bytes",
ATTRIBUTE_MD5 = "md5sum",
ATTRIBUTE_CHECKSUM = "checksum",
ATTRIBUTE_CHECKSUM = "xxhsum",
ATTRIBUTE_CATEGORY = "category";

/**
Expand All @@ -64,7 +64,7 @@ class RemotePackageDescriptor
public function __construct(DOMElement $remoteXMLElement)
{

if($remoteXMLElement->nodeName != self::TAG_REMOTE){
if($remoteXMLElement->nodeName != self::TAG_MOD){
throw new InvalidArgumentException("Passed remote xml element is not valid");
}

Expand Down
6 changes: 3 additions & 3 deletions src/Repository/RemoteRepositoryXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RemoteRepositoryXML
TAG_UUID = "uuid",
TAG_TITLE = "title",
TAG_DOWNPATH = "downpath",
TAG_REMOTES = "remotes";
TAG_REFERENCES = "references";

/**
* Attributes of the remote repository xml
Expand Down Expand Up @@ -144,9 +144,9 @@ protected function updateRepositoryFromXMLData(string $repositoryTitle, string $
}

// add remote package element and store it for later modification
$remotesList = $this->root->getElementsByTagName(self::TAG_REMOTES);
$remotesList = $this->root->getElementsByTagName(self::TAG_REFERENCES);
if ($remotesList->length == 0) {
$this->remotes = $this->xml->createElement(self::TAG_REMOTES);
$this->remotes = $this->xml->createElement(self::TAG_REFERENCES);
$this->remotes->setAttribute(self::ATTRIBUTE_COUNT, 0);
$this->root->appendChild($this->remotes);

Expand Down
5 changes: 3 additions & 2 deletions src/Task/GenerateFolderRepositoryTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ private static function getAvailableArchives($searchDir, bool $recursive): array
}
else
{
// skip non zip archives
if (strcasecmp("zip", pathinfo($fileEntry, PATHINFO_EXTENSION)) != 0) {
// skip non zip archives or ozd archives
if (strcasecmp("zip", pathinfo($fileEntry, PATHINFO_EXTENSION)) != 0
&& strcasecmp("ozp", pathinfo($fileEntry, PATHINFO_EXTENSION)) != 0) {
continue;
}

Expand Down

0 comments on commit 34eee1a

Please sign in to comment.