public function saveApk($file, $label, $name, $icon)
 {
     $fileSystem = new Filesystem();
     $parser = new ApkParser\Parser($file->getRealPath());
     $version = $parser->getManifest()->getVersionCode();
     $bundle = $parser->getManifest()->getPackageName();
     if (!$fileSystem->exists(public_path() . '/builds')) {
         $fileSystem->makeDirectory(public_path() . '/builds');
     }
     if (!$fileSystem->exists(public_path() . '/builds/android')) {
         $fileSystem->makeDirectory(public_path() . '/builds/android');
     }
     if (!$fileSystem->exists(public_path() . '/builds/android/' . $label)) {
         $fileSystem->makeDirectory(public_path() . '/builds/android/' . $label);
     }
     if (!$fileSystem->exists(public_path() . '/builds/android/' . $label . '/' . $version)) {
         $fileSystem->makeDirectory(public_path() . '/builds/android/' . $label . '/' . $version);
     }
     $label_model = Label::where('label_name', '=', $label)->where('build_type_id', '=', self::BUILD_ANDROID_TYPE_ID)->first();
     if ($label_model != null) {
         $version_model = $label_model->versions()->where('version', '=', $version)->first();
         if ($version_model != null) {
             $build_version_count = Build::where('version_id', '=', $version_model->id)->count();
             $build = Build::create(array('bundle' => $bundle, 'name' => $name, 'version_id' => $version_model->id, 'build' => $build_version_count + 1));
         } else {
             $version_model = Version::create(array('version' => $version, 'label_id' => $label_model->id));
             $build = Build::create(array('bundle' => $bundle, 'name' => $name, 'version_id' => $version_model->id, 'build' => 1));
         }
     } else {
         $label_model = Label::create(array('label_name' => $label, 'build_type_id' => self::BUILD_ANDROID_TYPE_ID));
         $version_model = Version::create(array('version' => $version, 'label_id' => $label_model->id));
         $build = Build::create(array('bundle' => $bundle, 'name' => $name, 'version_id' => $version_model->id, 'build' => 1));
     }
     $fn = public_path() . '/builds/android/' . $label . '/' . $version . '/' . $build->build . '/' . $bundle . '.apk';
     if (!$fileSystem->exists(public_path() . '/builds/android/' . $label . '/' . $version . '/' . $build->build)) {
         $fileSystem->makeDirectory(public_path() . '/builds/android/' . $label . '/' . $version . '/' . $build->build);
     }
     $fileSystem->move($file->getRealPath(), $fn);
     $fileSystem->move($icon->getRealPath(), public_path() . '/builds/android/' . $label . '/' . $version . '/' . $build->build . '/' . $bundle . '.png');
     return Config::get("app.domain") . "/android/builds/{$label}/{$version}/{$build->build}";
 }
 public function getIndex()
 {
     $builds = Build::where('is_published', '=', '1')->orderBy('updated_at', 'desc')->take(5)->get();
     $modversions = Modversion::whereNotNull('md5')->orderBy('updated_at', 'desc')->take(5)->get();
     $rawChangeLog = UpdateUtils::getLatestChangeLog();
     $changelogJson = array_key_exists('error', $rawChangeLog) ? $rawChangeLog : array_slice($rawChangeLog, 0, 10);
     return View::make('dashboard.index')->with('modversions', $modversions)->with('builds', $builds)->with('changelog', $changelogJson);
 }
 public function anyBuild($build_id = null)
 {
     $build = Build::find($build_id);
     if (empty($build)) {
         return Redirect::to('modpack/list')->withErrors(new MessageBag(array('Modpack not found')));
     }
     if (Input::get('action') == "delete") {
         if (Input::get('confirm-delete')) {
             $switchrec = 0;
             $switchlat = 0;
             $modpack = $build->modpack;
             if ($build->version == $modpack->recommended) {
                 $switchrec = 1;
             }
             if ($build->version == $modpack->latest) {
                 $switchlat = 1;
             }
             $build->modversions()->sync(array());
             $build->delete();
             if ($switchrec) {
                 $recbuild = Build::where('modpack_id', '=', $modpack->id)->orderBy('id', 'desc')->first();
                 $modpack->recommended = $recbuild->version;
             }
             if ($switchlat) {
                 $latbuild = Build::where('modpack_id', '=', $modpack->id)->orderBy('id', 'desc')->first();
                 $modpack->latest = $latbuild->version;
             }
             $modpack->save();
             Cache::forget('modpack.' . $modpack->slug);
             return Redirect::to('modpack/view/' . $build->modpack->id)->with('deleted', 'Build deleted.');
         }
         return View::make('modpack.build.delete')->with('build', $build);
     } else {
         if (Input::get('action') == "edit") {
             if (Input::get('confirm-edit')) {
                 $rules = array("version" => "required", "memory" => "numeric");
                 $messages = array('version.required' => "You must enter in the build number.", 'memory.numeric' => "You may enter in numbers only for the memory requirement");
                 $validation = Validator::make(Input::all(), $rules, $messages);
                 if ($validation->fails()) {
                     return Redirect::to('modpack/build/' . $build->id . '?action=edit')->withErrors($validation->messages());
                 }
                 $build->version = Input::get('version');
                 $minecraft = explode(':', Input::get('minecraft'));
                 $build->minecraft = $minecraft[0];
                 $build->minecraft_md5 = $minecraft[1];
                 $build->min_java = Input::get('java-version');
                 $build->min_memory = Input::get('memory-enabled') ? Input::get('memory') : '';
                 $build->save();
                 Cache::forget('modpack.' . $build->modpack->slug . '.build.' . $build->version);
                 return Redirect::to('modpack/build/' . $build->id);
             }
             $minecraft = MinecraftUtils::getMinecraft();
             return View::make('modpack.build.edit')->with('build', $build)->with('minecraft', $minecraft);
         } else {
             return View::make('modpack.build.view')->with('build', $build);
         }
     }
 }
Example #4
0
 public function action_build($build_id = null)
 {
     if (empty($build_id)) {
         return Redirect::to('modpack');
     }
     $build = Build::find($build_id);
     if (empty($build)) {
         return Redirect::to('modpack');
     }
     if (Input::get('action') == "delete") {
         if (Input::get('confirm-delete')) {
             $switchrec = 0;
             $switchlat = 0;
             $modpack = $build->modpack;
             if ($build->version == $modpack->recommended) {
                 $switchrec = 1;
             }
             if ($build->version == $modpack->latest) {
                 $switchlat = 1;
             }
             $build->modversions()->delete();
             $build->delete();
             if ($switchrec) {
                 $recbuild = Build::where('modpack_id', '=', $modpack->id)->order_by('id', 'desc')->first();
                 $modpack->recommended = $recbuild->version;
             }
             if ($switchlat) {
                 $latbuild = Build::where('modpack_id', '=', $modpack->id)->order_by('id', 'desc')->first();
                 $modpack->latest = $latbuild->version;
             }
             $modpack->save();
             Cache::forget('modpack.' . $modpack->slug);
             return Redirect::to('modpack/view/' . $build->modpack->id)->with('deleted', 'Build deleted.');
         }
         return View::make('modpack.build.delete')->with('build', $build);
     } else {
         return View::make('modpack.build.view')->with('build', $build);
     }
 }
 public function addBundle()
 {
     if (!Input::hasFile('ipa')) {
         exit(0);
     } else {
         $ipa = Input::file('ipa');
     }
     $payload = exec("unzip -l " . $ipa->getRealPath() . " | sed -e 's/ /\\n/g' | grep app/Info.plist | sed -e 's/Info.plist//g'");
     $default_icon = public_path() . "/images/default_icon.png";
     $fileSystem = new Filesystem();
     if (!$fileSystem->exists('/tmp/bundle')) {
         $fileSystem->makeDirectory('/tmp/bundle');
     }
     if (!$fileSystem->exists('/tmp/bundle/tmp')) {
         $fileSystem->makeDirectory('/tmp/bundle/tmp');
     }
     $path = "/tmp/bundle" . $ipa->getRealPath();
     if ($fileSystem->exists($path)) {
         $fileSystem->deleteDirectory($path);
     }
     $fileSystem->makeDirectory($path);
     $zip = new ZipArchive();
     $res = $zip->open($ipa->getRealPath());
     if ($res === TRUE) {
         $zip->extractTo($path);
         $zip->close();
     }
     $dirs = scandir($path);
     array_shift($dirs);
     array_shift($dirs);
     $APP_PATH = $path . "/" . $dirs[0];
     $dirs = scandir($APP_PATH);
     array_shift($dirs);
     array_shift($dirs);
     $APP_PATH = $APP_PATH . "/" . $dirs[0];
     $plist = CFPropertyList::getInstance();
     $plist->setFile($APP_PATH . "/Info.plist");
     $plist->load();
     $info = $plist->toArray();
     $name = $info['CFBundleName'];
     $build = isset($info['CFBundleVersion']) && array_key_exists("CFBundleVersion", $info) ? $info['CFBundleVersion'] : 1;
     $version = isset($info['CFBundleShortVersionString']) && array_key_exists("CFBundleShortVersionString", $info) ? $info['CFBundleShortVersionString'] : 0;
     if (array_key_exists("CFBundleIconFiles", $info)) {
         $icons = $info['CFBundleIconFiles'];
     } else {
         if (array_key_exists("CFBundleIcons", $info)) {
             $icons = $info["CFBundleIcons"]["CFBundlePrimaryIcon"]["CFBundleIconFiles"];
         } else {
             $icons = array();
         }
     }
     $bundle = $info['CFBundleIdentifier'];
     $label = $_POST['label'];
     if (!$fileSystem->exists(public_path() . '/builds')) {
         $fileSystem->makeDirectory(public_path() . '/builds');
     }
     if (!$fileSystem->exists(public_path() . '/builds/ios')) {
         $fileSystem->makeDirectory(public_path() . '/builds/ios');
     }
     if (!$fileSystem->exists(public_path() . '/builds/ios/' . $label)) {
         $fileSystem->makeDirectory(public_path() . '/builds/ios/' . $label);
     }
     if (!$fileSystem->exists(public_path() . '/builds/ios/' . $label . '/' . $version)) {
         $fileSystem->makeDirectory(public_path() . '/builds/ios/' . $label . '/' . $version);
     }
     $icons_ready = array();
     foreach ($icons as $icon) {
         $img = "{$path}/tmp5646431.png";
         $icon = str_replace(".png", "", $icon) . ".png";
         $processor = PPngUncrush::getInstance();
         if (is_file("{$APP_PATH}/{$icon}")) {
             $processor->setFilePath("{$APP_PATH}/{$icon}");
             try {
                 $processor->decode($img . $icon);
             } catch (ErrorException $e) {
                 $img = $default_icon;
                 $icon = "";
             }
             $sz = getimagesize($img . $icon);
             $icons_ready[] = array("image" => $img . $icon, "size" => $sz);
         }
         //            $fileSystem->copy($img.$icon ,public_path().'/builds/ios/'.$label.'/'.$version.'/'.$bundle.$sz[0].'x'.$sz[1].'.png');
     }
     $label_model = Label::where('label_name', '=', $label)->where('build_type_id', '=', self::BUILD_IOS_TYPE_ID)->first();
     if ($label_model != null) {
         $version_model = $label_model->versions()->where('version', '=', $version)->first();
         if ($version_model != null) {
             $build_version_count = Build::where('version_id', '=', $version_model->id)->count();
             $build = Build::create(array('bundle' => $bundle, 'name' => $name, 'version_id' => $version_model->id, 'build' => $build_version_count + 1));
         } else {
             $version_model = Version::create(array('version' => $version, 'label_id' => $label_model->id));
             $build = Build::create(array('bundle' => $bundle, 'name' => $name, 'version_id' => $version_model->id, 'build' => 1));
         }
     } else {
         $label_model = Label::create(array('label_name' => $label, 'build_type_id' => self::BUILD_IOS_TYPE_ID));
         $version_model = Version::create(array('version' => $version, 'label_id' => $label_model->id));
         $build = Build::create(array('bundle' => $bundle, 'name' => $name, 'version_id' => $version_model->id, 'build' => 1));
     }
     $fn = public_path() . '/builds/ios/' . $label . '/' . $version . '/' . $build->build . '/' . $bundle . '.ipa';
     if (!$fileSystem->exists(public_path() . '/builds/ios/' . $label . '/' . $version . '/' . $build->build)) {
         $fileSystem->makeDirectory(public_path() . '/builds/ios/' . $label . '/' . $version . '/' . $build->build);
     }
     $fileSystem->move($ipa->getRealPath(), $fn);
     $max_size = 0;
     foreach ($icons_ready as $icon) {
         if ($icon["size"][0] > $max_size) {
             $max_size = $icon["size"][0];
         }
     }
     foreach ($icons_ready as $icon) {
         if ($icon["size"][0] == $max_size) {
             $fileSystem->copy($icon["image"], public_path() . '/builds/ios/' . $label . '/' . $version . '/' . $build->build . '/' . $bundle . '.png');
         }
     }
     if (empty($icons_ready)) {
         $fileSystem->copy($default_icon, public_path() . '/builds/ios/' . $label . '/' . $version . '/' . $build->build . '/' . $bundle . '.png');
     }
     $fileSystem->deleteDirectory('/tmp/bundle/tmp');
     echo Config::get("app.domain") . "/ios/builds/{$label}/{$version}/{$build->build}\n";
     return "";
 }
Example #6
0
 private function getModpackBuilds($modpack, $details)
 {
     foreach ($details['builds'] as $version => $data) {
         $build = Build::where('version', '=', $version)->first();
         if (empty($build)) {
             $build = new Build();
             $build->modpack_id = $modpack->id;
             $build->version = $version;
             $build->minecraft = $data['minecraft'];
             if (isset($data['forge'])) {
                 $build->forge = $data['forge'];
             }
             $build->save();
         } else {
             $build->minecraft = $data['minecraft'];
             if (isset($data['forge'])) {
                 $build->forge = $data['forge'];
             }
             $build->save();
         }
         if (!$this->getBuildMods($build, $data['mods'])) {
             return false;
         }
     }
     return true;
 }