}
 // echo 'Downloading images for ' . $appName . "\n";
 //date_default_timezone_set('America/Los_Angeles');
 //$date = date("Ymd");
 //$topImageFolder = "../../Icons_and_Splash_Screens/Source_Files";
 $iconAndSplashFolder = "../Icons_and_Splash_Screens";
 if (!file_exists($iconAndSplashFolder)) {
     mkdir($iconAndSplashFolder);
 }
 $sourceFileFolder = $iconAndSplashFolder . "/Source_Files";
 if (!file_exists($sourceFileFolder)) {
     mkdir($sourceFileFolder);
 }
 $imageFolder = $sourceFileFolder . '/' . sanitize($appName);
 //echo($imageFolder."\n");
 rmDashRF($imageFolder);
 $query = 'SELECT photo_id from upclose_app_icon_candidates WHERE app_id =' . $appId;
 $result = mysql_query($query);
 // Check result
 // This shows the actual query sent to MySQL, and the error. Useful for debugging.
 if (!$result) {
     $message = 'Invalid query: ' . mysql_error() . "\n";
     $message .= 'Whole query: ' . $query;
     die($message);
 }
 $imageIds = array();
 while ($row = mysql_fetch_assoc($result)) {
     $imageIds[] = $row['photo_id'];
 }
 // $imageId = 287026;
 foreach ($imageIds as $imageId) {
     array_push($brokenImages, $appIconPhotoId);
 } else {
     echo "Download unsuccessful\n";
     system('convert ' . escapeshellarg($appIconJPG) . ' -resize 1024x1024! ' . escapeshellarg($appIconPNG));
 }
 $genericProjectFolder = $appFolder . '/TheProject.xcodeproj';
 $genericProjectFile = $genericProjectFolder . '/project.pbxproj';
 $projectContents = file_get_contents($genericProjectFile);
 $projectContents = preg_replace('/PRODUCT_NAME = .*;/', 'PRODUCT_NAME = ' . $cleanProductName . ';', $projectContents);
 $projectContents = preg_replace('/BestofSF/', $cleanProductName, $projectContents);
 file_put_contents($genericProjectFile, $projectContents);
 $appSpecificProjectFolder = $appFolder . '/' . $cleanProductName . '.xcodeproj';
 echo 'appSpecificProjectFolder = ' . $appSpecificProjectFolder . '
    ';
 cpDashR($genericProjectFolder, $appSpecificProjectFolder);
 rmDashRF($genericProjectFolder);
 $staticContentFolder = $appFolder . '/' . $appId . ' Static Content';
 putenv("SUTRO_STATIC_CONTENT_ROOT=" . realpath($staticContentFolder));
 // ****** Delete offline media folder *********
 $dirPath = $staticContentFolder . "/offline-media/";
 echo "directory = " . $dirPath . "\n";
 $files = glob($dirPath . '*', GLOB_MARK);
 foreach ($files as $file) {
     unlink($file);
 }
 //foreach ($files as $file) echo($file . "\n");
 rmdir($dirPath);
 // ****** Download and populate offline map database ***********
 $allMapTilesFolder = '../map-tile-cache-take2/' . $appProperties['map_tile_url_prefix'];
 if (!file_exists($allMapTilesFolder)) {
     mkdir($allMapTilesFolder, 0777, true);
 $allAppsFolder = '../app-installs/';
 if (!file_exists($allAppsFolder)) {
     mkdir($allAppsFolder);
 }
 $allPhotosFolder = '../iphone-sized-photos/';
 if (!file_exists($allPhotosFolder)) {
     mkdir($allPhotosFolder);
 }
 $allContentFolder = '../content/';
 if (!file_exists($allContentFolder)) {
     mkdir($allContentFolder);
 }
 $appFolder = $allAppsFolder . $appId . "_screenshots";
 $contentFolder = $allContentFolder . $appId;
 rmDashRF($contentFolder);
 rmDashRF($appFolder);
 if (file_exists($appFolder)) {
     deleteDirectory($appFolder);
 }
 system('svn export . ' . $appFolder);
 $screenshotFolder = $appFolder . '/screenshots/';
 mkdir($screenshotFolder, 0777, true);
 // $staticContentZipURL = 'http://sutroproject.com/published-content/' . $appId . '/' . $appId . ' Static Content.zip';
 //$staticContentZipFile = $contentFolder . '/' . $appId . '.zip';
 //  if(file_exists($staticContentZipFile)) unlink($staticContentZipFile);
 //  system('wget ' . escapeshellarg($staticContentZipURL) . ' -O ' . escapeshellarg($staticContentZipFile));
 //  system('unzip -q ' . escapeshellarg($staticContentZipFile) . ' -d ' . escapeshellarg($contentFolder));
 // unlink($staticContentZipFile);
 // cpDashR($contentFolder, $appFolder);
 //system('wget ' . escapeshellarg('http://sutroproject.com/published-content/' . $appId . '/Info.plist'));
 //rename('Info.plist', $appFolder . '/Info.plist');