Beispiel #1
0
 /**
  * Unpack the archive and save the files in temporary folders
  * @return bool
  */
 function UnpackAndSort($file)
 {
     global $langmessage;
     $archive = new \gp\tool\Archive($file);
     $archive_root = $archive->GetRoot();
     if (is_null($archive_root)) {
         $this->msg($langmessage['error_unpacking'] . ' (no root)');
         return false;
     }
     $archive_root_len = strlen($archive_root);
     $archive_files = $archive->ListFiles();
     $this->msg($langmessage['package_unpacked']);
     foreach ($archive_files as $file) {
         if (strpos($file['name'], $archive_root) === false) {
             continue;
         }
         $rel_filename = substr($file['name'], $archive_root_len);
         $name_parts = explode('/', trim($rel_filename, '/'));
         $dir = array_shift($name_parts);
         $replace_dir = false;
         switch ($dir) {
             case 'include':
                 $replace_dir = 'include';
                 $rel_filename = implode('/', $name_parts);
                 break;
             case 'themes':
             case 'addons':
                 if (count($name_parts) == 0) {
                     continue 2;
                 }
                 $replace_dir = $dir . '/' . array_shift($name_parts);
                 $rel_filename = implode('/', $name_parts);
                 break;
         }
         if ($replace_dir === false) {
             continue;
         }
         $content = $archive->getFromName($file['name']);
         if (empty($content)) {
             return true;
         }
         $replace_dir = trim($replace_dir, '/');
         if (!isset($this->replace_dirs[$replace_dir])) {
             $this->replace_dirs[$replace_dir] = \gp\tool\FileSystem::TempFile($replace_dir);
         }
         $file_rel = $this->replace_dirs[$replace_dir] . '/' . $rel_filename;
         if (!$this->PutFile($file_rel, $content)) {
             return false;
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Write Archive
  *
  */
 private function ExtractArchive($archive_path)
 {
     global $langmessage, $dataDir;
     $archive = new \gp\tool\Archive($archive_path);
     $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon');
     if (!$archive->extractTo($extract_temp)) {
         $this->message($langmessage['download_failed'] . ' (Package not extracted)');
         return false;
     }
     //get archive root
     $archive_root = $archive->GetRoot();
     if (is_null($archive_root)) {
         $this->message($langmessage['download_failed'] . ' (Root not found)');
         return false;
     }
     //rename to source folder
     $rename_from = $extract_temp . '/' . ltrim($archive_root, '/');
     if (!\gp\tool\Files::Replace($rename_from, $this->source)) {
         $this->message($langmessage['download_failed'] . ' (Not replaced)');
         return false;
     }
     return true;
 }