std::string CCFileUtils::fullPathForFilename(const char* pszFileName) { CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path"); // Return directly if it's an absolute path. if (strlen(pszFileName) > 3 && pszFileName[0] >= 'a' && pszFileName[0] <= 'z' && pszFileName[0] >= 'A' && pszFileName[0] <= 'Z' && (pszFileName[1] == ':') && (pszFileName[2] == '\\' || pszFileName[2] == '/') ) { //CCLOG("Probably invoking fullPathForFilename recursively, return the full path: %s", pszFileName); return pszFileName; } // Already Cached ? std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName); if (cacheIter != s_fullPathCache.end()) { //CCLOG("Return full path from cache: %s", cacheIter->second.c_str()); return cacheIter->second; } std::string newFileName = getNewFilename(pszFileName); std::string fullpath; for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin(); searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) { for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin(); resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) { fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter); // if (GetFileAttributesA(fullpath.c_str()) != -1) // { // // Adding the full path to cache if the file was found. // s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath)); ////CCLOG("Returning path: %s", fullpath.c_str()); // return fullpath; // } } } // The file wasn't found, return the file name passed in. return pszFileName; }
std::string FileUtils::fullPathFromRelativeFile(const std::string &filename, const std::string &relativeFile) { return relativeFile.substr(0, relativeFile.rfind('/')+1) + getNewFilename(filename); }
int interface_capture (SDL_Surface *screen, int w, int h) {{{ const char *extension[]={".jpeg",".png",".bmp"}; /* This function is called to take a picure from the cam * and save it to a file */ char *capture_filename; SDL_Surface *tmp_surface; struct stat file_stat; int file_size = -1; /* Get a free filename */ capture_filename = getNewFilename (Dump_Path(), Dump_Prefix(), extension [configuration.dump_mode]); if (NULL == capture_filename) return -1; /* Capture the image*/ tmp_surface = get_ImageSurface(screen, w, h); /* {{{ Write image */ { unsigned char *data; int i; unsigned char tmp; data = (unsigned char*)tmp_surface->pixels; if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError()); free (capture_filename); return -1; } } /* swap Red and blue */ for (i=0; i<tmp_surface->w*tmp_surface->h*3; i+=3) { tmp = data[i]; data[i] = data[i+2]; data[i+2] = tmp; } if ( SDL_MUSTLOCK (screen) ) { SDL_UnlockSurface (screen); } switch (configuration.dump_mode) { case 0: write_file_jpeg (capture_filename, (unsigned char*)tmp_surface->pixels, tmp_surface->w, tmp_surface->h); break; case 1: write_file_png (capture_filename, (unsigned char*)tmp_surface->pixels, (unsigned int)tmp_surface->w, (unsigned int)tmp_surface->h); break; case 2: SDL_SaveBMP(tmp_surface, capture_filename); break; default: fprintf(stderr, "Unsuported capture format.\n"); break; } } /* }}} */ SDL_FreeSurface(tmp_surface); // if (configuration.debug > 0) printf("Saved file: %s\n", capture_filename); /* {{{ FTP-Stuff */ if( configuration.ftp_host !=NULL && configuration.ftp_user !=NULL && configuration.ftp_pass !=NULL && configuration.ftp_file !=NULL ) { if (init_ftp (configuration.ftp_host, configuration.ftp_user, configuration.ftp_pass)) { if (configuration.debug > 0) printf ("Starte FTP Upload\n"); if (configuration.ftp_temp != NULL) { if (configuration.debug > 0) printf ("Using FTP Rename Method\n"); if (ftp_send (capture_filename, configuration.ftp_temp)) ftp_rename (configuration.ftp_temp, configuration.ftp_file); } else ftp_send (capture_filename, configuration.ftp_file); } } /* }}} */ if (!stat (capture_filename, &file_stat)) { file_size = file_stat.st_size; } free (capture_filename); return file_size; }}}