Created
May 16, 2011 10:49
-
-
Save sudhanshuraheja/974227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function processFile() { | |
// The final response to send back to the browser | |
$response = array(); | |
// Get the post value for file (we're passing the name of the file here) | |
// And make sure you check your routines for checking if this is valid etc | |
$file = $_POST['file'] | |
// DISK_ROOT is defined in the project | |
$base_path = DISK_ROOT . '/app/cache/uploads/'; | |
// Create a variable with the hash of the project | |
$project_path = $base_path . $project_info[0]['hash']; | |
if(file_exists($project_path) && is_dir($project_path)) { | |
// The structure should look like this | |
// l234o23o4oiu2o3u42/ (hash for the project) | |
// 22978349273/ (has for the release) | |
// manifest.plist | |
// project-release.ipa | |
// embedded.mobileprovision | |
// archive.zip | |
// tmp/ | |
// project-release-copy.ipa | |
// expanded files go here | |
$release_path = createHash($file . time(), 10); | |
while(file_exists($release_path)) { | |
$release_path = createHash($file . rand(10,99) . time(), 10); | |
} | |
mkdir($project_path . '/' . $release_path, 0777, true); | |
mkdir($project_path . '/' . $release_path . '/tmp', 0777, true); | |
// Copy the ipa to project/release/.ipa | |
copy($base_path . $file, $project_path . '/' . $release_path . '/' . $file); | |
// Copy the ipa to project/release/tmp/.ipa | |
copy($base_path . $file, $project_path . '/' . $release_path . '/tmp/' . $file); | |
// save the current directory and go to tmp | |
$current_working_directory = getcwd(); | |
chdir($project_path . '/' . $release_path . '/tmp/'); | |
// Unzip the ipa file | |
$message = ''; | |
exec('unzip ' . $file, $message); | |
if(!is_dir($project_path . '/' . $release_path . '/tmp/Payload')) { | |
$response = array('error' => 'This ipa is invalid'); | |
$this->set('response', $response); | |
return; | |
} | |
$r = dir($project_path . '/' . $release_path . '/tmp/Payload'); | |
$app_path = ''; | |
while(false !== ($entry = $r->read())) { | |
if( ($entry != '.') && ($entry != '..') && (strpos($entry, '.app') !== false) ) { | |
$app_path = $entry; | |
} | |
} | |
if($app_path == '') { | |
$response = array('error' => 'This ipa is invalid'); | |
$this->set('response', $response); | |
return; | |
} | |
$info_plist_path = $project_path . '/' . $release_path . '/tmp/Payload/' . $app_path . '/Info.plist'; | |
$provision_path = $project_path . '/' . $release_path . '/tmp/Payload/' . $app_path . '/embedded.mobileprovision'; | |
// Copy mobile provision to release folder | |
copy($provision_path, $project_path . '/' . $release_path . '/embedded.mobileprovision'); | |
// Read the info.plist and get values out of it | |
require_once(DISK_ROOT . '/app/external/plist/CFPropertyList.php'); | |
$plist = new CFPropertyList( $info_plist_path, CFPropertyList::FORMAT_BINARY ); | |
$plist_data = $plist->toArray(); | |
$ipa_url = APPLICATION_ROOT . '/app/cache/uploads/' . $project_info[0]['hash'] . '/' . $release_path . '/' . $file; | |
$bundle_id = _g($plist_data, 'CFBundleIdentifier'); | |
$bundle_version = _g($plist_data, 'CFBundleVersion'); | |
$title = _g($plist_data, 'CFBundleDisplayName'); | |
$xml_data = $this->createManifest($ipa_url, $bundle_id, $bundle_version, $title); | |
// Write the manifest.plist | |
$f = new File(); | |
$f->write('/app/cache/uploads/' . $project_info[0]['hash'] . '/' . $release_path . '/manifest.plist', $xml_data); | |
// Save values to database | |
} else { | |
$response = array('error' => 'The project directory does not exist'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment