Esempio n. 1
0
    /**
     * Creates the distribution artifact.
     *
     * @param \Generator $emoteGenerator Contains a generator which will yield objects
     *     of type GbsLogistics\Emotes\EmoteBundle\Entity\Emote .
     * @return ReleaseArtifact
     */
    public function generateArtifact(\Generator $emoteGenerator)
    {
        $zipDir = $this->getNamespace();
        $outputFilename = tempnam(sys_get_temp_dir(), $this->getNamespace());
        $zip = new \ZipArchive();
        if (!$zip->open($outputFilename)) {
            throw new \RuntimeException(sprintf('Can\'t open file %s for writing', $outputFilename));
        }
        $zip->addEmptyDir($zipDir);
        $header = $this->generateHeader();
        $themeFile = sprintf(<<<EOTXT
Name=%s
Description=%s
Icon=%s
Author=%s

[default]

EOTXT
, $header->getName(), $header->getDescription(), $header->getIcon(), $header->getAuthor());
        /** @var Emote $emote */
        foreach ($emoteGenerator as $emote) {
            $themeFile .= $this->generateEmoteEntry($emote);
            $zip->addFile($this->dataStorage->getImageSourcePath($emote->getPath()), $zipDir . '/' . $emote->getPath());
        }
        $zip->addFromString($zipDir . '/theme', $themeFile);
        $zip->close();
        $artifact = new ReleaseArtifact();
        $artifact->setNamespace($this->getNamespace());
        $artifact->setPath($outputFilename);
        $artifact->setName($this->getName());
        return $artifact;
    }
Esempio n. 2
0
    /**
     * Creates the distribution artifact.
     *
     * @param \Generator $emoteGenerator Contains a generator which will yield objects
     *     of type GbsLogistics\Emotes\EmoteBundle\Entity\Emote .
     * @return ReleaseArtifact
     */
    public function generateArtifact(\Generator $emoteGenerator)
    {
        $zipDir = 'GoonfleetEmotes.AdiumEmoticonSet';
        $outputFilename = tempnam(sys_get_temp_dir(), $this->getNamespace());
        $zip = new \ZipArchive();
        if (!$zip->open($outputFilename)) {
            throw new \RuntimeException(sprintf('Can\'t open file %s for writing', $outputFilename));
        }
        $zip->addEmptyDir($zipDir);
        $plist = <<<PLISTHEADER
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AdiumSetVersion</key>
<integer>1</integer>
<key>Emoticons</key>
<dict>
PLISTHEADER;
        foreach ($emoteGenerator as $emote) {
            $plist .= $this->getPlistEntry($emote);
            $zip->addFile($this->dataStorage->getImageSourcePath($emote->getPath()), $zipDir . '/' . $emote->getPath());
        }
        $plist .= '</dict></dict></plist>';
        $zip->addFromString($zipDir . '/Emoticons.plist', $plist);
        $zip->close();
        $artifact = new ReleaseArtifact();
        $artifact->setNamespace($this->getNamespace());
        $artifact->setPath($outputFilename);
        $artifact->setName($this->getNamespace());
        return $artifact;
    }
Esempio n. 3
0
 /**
  * @param string $directoryPath The path to the directory containing all of
  *     the emote images and the pidgin "theme" file.
  */
 public function populateDatabase($directoryPath)
 {
     $themeFile = $directoryPath . DIRECTORY_SEPARATOR . 'theme';
     if (!is_file($themeFile)) {
         throw new \InvalidArgumentException(sprintf('Could not locate "%s".', $themeFile));
     }
     if (false === ($themeHandle = fopen($themeFile, 'r'))) {
         throw new \InvalidArgumentException(sprintf('Could not open "%s".', $themeFile));
     }
     // Seek through the theme until we find where the emotes are located.
     while (false !== ($line = fgets($themeHandle))) {
         $line = trim($line);
         if ('[default]' === $line) {
             break;
         }
     }
     if (feof($themeHandle)) {
         throw new \RuntimeException(sprintf('Could not find emote information in "%s".', $themeFile));
     }
     while (false !== ($line = fgets($themeHandle))) {
         $line = trim($line);
         if (preg_match('/(?:! )?(\\S+)\\s+(.+)/', $line, $matches)) {
             $file = $matches[1];
             $emoteCodes = preg_split('/\\s+/', $matches[2]);
             $sourcePath = $directoryPath . DIRECTORY_SEPARATOR . $file;
             $destinationPath = $this->dataStorage->getImageSourcePath($file);
             $emote = $this->emoteRepository->findOneBy(['path' => $file]);
             if (null === $emote) {
                 $emote = new Emote();
                 $emote->setPath($file);
                 if (null === $destinationPath) {
                     $this->dataStorage->copyImageToSource($sourcePath);
                 }
                 $this->entityManager->persist($emote);
                 $this->entityManager->flush($emote);
             }
             $newCodes = array_diff($emoteCodes, $emote->getTextCodesAsArray());
             foreach ($newCodes as $code) {
                 $textCode = new TextCode($emote, $code);
                 $this->entityManager->persist($textCode);
                 $this->entityManager->flush($textCode);
             }
         }
     }
     $this->entityManager->flush();
 }
 /**
  * @param ReleaseArtifact $artifact
  * @return PublishedRelease
  */
 public function publish(ReleaseArtifact $artifact)
 {
     $releaseFilename = $this->dataStorage->getDistDirectory($artifact->getNamespace()) . DIRECTORY_SEPARATOR . date('YmdHis') . '.zip';
     copy($artifact->getPath(), $releaseFilename);
     return new PublishedRelease($artifact->getName(), realpath($releaseFilename));
 }