Exemplo n.º 1
0
 /**
  * Execute the command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface  $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $client = new Client();
     $modname = $input->getArgument('modname');
     $modversion = $input->getArgument('modversion');
     $config = solder_config();
     $response = $client->get($config->api);
     $server = $response->json();
     $response = $client->get($config->api . '/mod/' . $modname . '/' . $modversion);
     $json = $response->json();
     if (isset($json['error'])) {
         throw new \Exception($json['error']);
     }
     $rows = array();
     foreach ($json as $key => $value) {
         if ($key == 'versions') {
             $rows[] = array("<info>{$key}</info>", implode($value, "\n"));
         } else {
             $rows[] = array("<info>{$key}</info>", mb_strimwidth($value, 0, 80, "..."));
         }
     }
     $output->writeln('<comment>Server:</comment>');
     $output->writeln(" <info>{$server['api']}</info> version {$server['version']}");
     $output->writeln(" {$api}");
     $output->writeln('');
     $output->writeln("<comment>Mod:</comment>");
     $table = new Table($output);
     $table->setRows($rows)->setStyle('compact')->render();
 }
Exemplo n.º 2
0
 private function getMod($output, $slug, $version)
 {
     if ($slug == '' || $version == '') {
         throw new \InvalidArgumentException('Invalid arguments');
     }
     $apiClient = new Client();
     $appConfig = solder_config();
     $apiResponse = $apiClient->get($appConfig->api . '/mod/' . $slug . '/' . $version)->json();
     if (isset($apiResponse['error'])) {
         throw new \Exception($apiResponse['error']);
     }
     $url = $apiResponse['url'];
     $filename = basename($url);
     $md5 = $apiResponse['md5'];
     downloadFile($url, $filename, $output, $md5);
     $output->writeln('');
     if (md5_file($filename) != $md5) {
         throw new \Exception('Hash dosen\'t match');
     }
 }
Exemplo n.º 3
0
 /**
  * Execute the command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface  $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $client = new Client();
     $slug = $input->getArgument('slug');
     $build = $input->getArgument('build');
     $config = solder_config();
     $response = $client->get($config->api);
     $server = $response->json();
     if ($slug != '' && $build == '') {
         // Slug, No Build
         $response = $client->get($config->api . '/modpack/' . $slug);
         $json = $response->json();
         if (isset($json['error'])) {
             throw new \Exception($json['error']);
         }
         $rows = array();
         foreach ($json as $key => $value) {
             if ($key == 'builds') {
                 $rows[] = array("<info>{$key}</info>", implode($value, "\n"));
             } else {
                 $rows[] = array("<info>{$key}</info>", $value);
             }
         }
         $output->writeln('<comment>Server:</comment>');
         $output->writeln(" <info>{$server['api']}</info> version {$server['version']}");
         $output->writeln(" {$config->api}");
         $output->writeln('');
         $output->writeln("<comment>Modpack:</comment>");
         $table = new Table($output);
         $table->setRows($rows)->setStyle('compact')->render();
     } elseif ($slug != '' && $build != '') {
         // Slug With Build
         if ($build == 'latest' || $build == 'recommended') {
             $response = $client->get($config->api . '/modpack/' . $slug);
             $json = $response->json();
             $build = $json[$build];
         }
         $response = $client->get($config->api . '/modpack/' . $slug . '/' . $build);
         $json = $response->json();
         if (isset($json['error'])) {
             throw new \Exception($json['error']);
         }
         $build = array();
         $mods = array();
         foreach ($json as $key => $value) {
             if ($key == 'mods') {
                 foreach ($value as $mod) {
                     $mods[] = array("<info>{$mod['name']}</info>", $mod['version']);
                 }
             } else {
                 $build[] = array("<info>{$key}</info>", $value);
             }
         }
         $output->writeln('<comment>Server:</comment>');
         $output->writeln(" <info>{$server['api']}</info> version {$server['version']}");
         $output->writeln(" {$config->api}");
         $output->writeln('');
         $output->writeln('<comment>Build:</comment>');
         $table = new Table($output);
         $table->setRows($build)->setStyle('compact')->render();
         $output->writeln('');
         $output->writeln('<comment>Mods:</comment>');
         $table = new Table($output);
         $table->setRows($mods)->setStyle('compact')->render();
     } else {
         $response = $client->get($config->api . '/modpack');
         $json = $response->json();
         if (isset($json['error'])) {
             throw new \Exception($json['error']);
         }
         $rows = array();
         foreach ($json['modpacks'] as $slug => $name) {
             $rows[] = array("<info>{$slug}</info>", $name);
         }
         $output->writeln('<comment>Server:</comment>');
         $output->writeln(" <info>{$server['api']}</info> version {$server['version']}");
         $output->writeln(" {$config->api}");
         $output->writeln('');
         $output->writeln('<comment>Available Modpacks:</comment>');
         $table = new Table($output);
         $table->setRows($rows)->setStyle('compact')->render();
     }
 }
 private function getModpack($output, $modpackSlug, $modpackBuild)
 {
     if ($modpackSlug == '' || $modpackBuild == '') {
         throw new \InvalidArgumentException('Invalid arguments');
     }
     $apiClient = new Client();
     $appConfig = solder_config();
     if ($modpackBuild == 'latest' || $modpackBuild == 'recommended') {
         $apiResponse = $apiClient->get($appConfig->api . '/modpack/' . $modpackSlug)->json();
         $modpackBuild = $apiResponse[$modpackBuild];
     }
     $apiResponse = $apiClient->get($appConfig->api . '/modpack/' . $modpackSlug . '/' . $modpackBuild)->json();
     if (isset($apiResponse['error'])) {
         throw new \Exception($apiResponse['error']);
     }
     if (!is_dir($modpackSlug . '-' . $modpackBuild)) {
         $output->writeln("creating: {$modpackSlug}-{$modpackBuild}" . DIRECTORY_SEPARATOR);
         mkdir($modpackSlug . '-' . $modpackBuild);
     }
     foreach ($apiResponse['mods'] as $mod) {
         $url = $mod['url'];
         $filename = basename($url);
         $md5 = $mod['md5'];
         downloadFile($url, $modpackSlug . '-' . $modpackBuild . DIRECTORY_SEPARATOR . $filename, $output, $md5);
         unpackFile($modpackSlug . '-' . $modpackBuild . DIRECTORY_SEPARATOR . $filename, $output);
     }
 }