Exemplo n.º 1
0
bool CExtUpdate::applySettings(std::string & filename, int mode)
{
	if(!FileHelpers)
		FileHelpers = new CFileHelpers();

	if (mode == MODE_EXPERT)
		imgFilename = (std::string)g_settings.update_dir + "/" + FILESYSTEM_ENCODING_TO_UTF8_STRING(filename);
	else
		imgFilename = FILESYSTEM_ENCODING_TO_UTF8_STRING(filename);

	DBG_TIMER_START()

	std::string oldFilename = imgFilename;
	std::string hostName    = netGetHostname();
	std::string orgPath     = getPathName(imgFilename);
	std::string orgName     = getBaseName(imgFilename);
	orgName                 = getFileName(orgName);
	std::string orgExt      = "." + getFileExt(imgFilename);
	std::string timeStr     = getNowTimeStr("_%Y%m%d_%H%M");
	std::string settingsStr = "+settings";

	if (orgPath != "/tmp") {
		if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_HOSTNAME_TIME)
			imgFilename = orgPath + "/" + hostName + timeStr + settingsStr + orgExt;
		else if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_ORGNAME_TIME)
			imgFilename = orgPath + "/" + orgName + timeStr  + settingsStr + orgExt;
		else
			imgFilename = orgPath + "/" + orgName  + settingsStr + orgExt;
		FileHelpers->copyFile(oldFilename.c_str(), imgFilename.c_str(), 0644);
	}
	else
		imgFilename = oldFilename;
	filename = imgFilename;

	bool ret = applySettings();
	DBG_TIMER_STOP("Image editing")
	if (!ret) {
		if ((mtdRamError != "") && (!flashErrorFlag))
			DisplayErrorMessage(mtdRamError.c_str());

		// error, delete image file
		unlink(imgFilename.c_str());
	}
	else {
		if (mode == MODE_EXPERT) {
			if ((mtdNumber < 3) || (mtdNumber > 4)) {
				const char *err = "invalid mtdNumber\n";
				printf(err);
				DisplayErrorMessage(err);
				WRITE_UPDATE_LOG("ERROR: %s", err);
				return false;
			}
		}
		WRITE_UPDATE_LOG("\n");
		WRITE_UPDATE_LOG("##### Settings taken. #####\n");
		if (mode == MODE_EXPERT)
			CFlashExpert::getInstance()->writemtd(filename, mtdNumber);
	}
	return ret;
}
Exemplo n.º 2
0
// This is a recursive function that goes through each file or folder, starting in "startingPath", and if it's a file, it adds it to the "fileNames" array, if it's a folder, it goes inside this folder and does the same thing
void goInside(char* startingPath, char*** fileNames, char* extFilter, long* currentFile)
{
    // Opens the current dir
    DIR* pDir = opendir (startingPath);
    struct dirent *pDirent;

    if (pDir == NULL)
    {
        printf ("Cannot open directory: '%s'\n", startingPath);
        exit(1);
    }

    // Writes all the file names in this dir, into the file
    while ((pDirent = readdir(pDir)) != NULL)
    {
        char* fileName = pDirent->d_name;

         //Makes sure it doesn't write stuff like "." or ".." into the file
        if((strcmpi(fileName,".") != 0) && (strcmpi(fileName,"..") != 0))
        {
            //Creates the complete path (E.g. from C:\folder goes to c:\folder\something)
            char* completePath = buildFullPath(startingPath,fileName);

            // If it's a file, not a folder
            if (!isDirectory(completePath))
            {
                // If there is no extension restriction or the file we are reading matches the extension restriction
                if ((strcmpi(extFilter,"*") == 0) || (strcmpi(getFileExt(fileName),extFilter) == 0))
                {
                    (*fileNames) = (char**) realloc((*fileNames),((*currentFile) + 1) * sizeof(char*));
                    (*fileNames)[(*currentFile)] = (char*) malloc(strlen(fileName) + 1); // Allocates the string
                    strcpy((*fileNames)[(*currentFile)],fileName); // Copies the file name to that string
                    (*currentFile)++;
                }
            }
            else
            {
                strcat(completePath,"\\");
                goInside(completePath,fileNames,extFilter,currentFile);
            }
        }
    }

    //Closes the dir and the file
    closedir (pDir);
}
Exemplo n.º 3
0
int countFilesSingleFolder(char* pathToFolder, char* extFilter)
{
    int filesToPatchCount = 0;
     // Opens the current dir
    DIR* pDir = opendir (pathToFolder);
    struct dirent *pDirent;

    if (pDir == NULL)
    {
        printf ("Cannot open directory: '%s'\n", pathToFolder);
        exit(1);
    }

    // Writes all the file names in this dir, into the file
    while ((pDirent = readdir(pDir)) != NULL)
    {
        char* fileOrFolder = pDirent->d_name;

         //Makes sure it doesn't write stuff like "." or ".." into the file
        if((strcmpi(fileOrFolder,".") != 0) && (strcmpi(fileOrFolder,"..") != 0))
        {
            //Creates the complete path (E.g. from C:\folder goes to c:\folder\something)
            char* completePath = buildFullPath(pathToFolder,fileOrFolder);


            if (!isDirectory(completePath))
            {
                if ((strcmpi(extFilter,"*") == 0) || (strcmpi(getFileExt(fileOrFolder),extFilter) == 0))
                {
                    filesToPatchCount++;
                }
            }
        }
    }

    //Closes the dir and the file
    closedir (pDir);
    return filesToPatchCount;
}
Exemplo n.º 4
0
void resources_process()
{
    StringArray input_file_list;
    scan_dir(input_file_list, g_config->m_inputDir.c_str(), "*", SCAN_FILES, true);

    LOGI("input file num = %d.", input_file_list.size());
    bool shaderIncludedAdded = false;

    for (size_t i=0; i<input_file_list.size(); ++i)
    {
        const std::string& input = input_file_list[i];
        std::string ext = getFileExt(input);
        if(ext == EngineNames::LEVEL)
            continue;
        BaseCompiler* compiler = g_config->create_compiler(ext);
        if(!compiler)
        {
            LOGW("can not find any compiler for this resource %s.", input.c_str());
            continue;
        }
        std::string output = input_to_output(input);
        if(ext == "dds") output =
            replaceExtension(output, EngineNames::TEXTURE);
        compiler->m_input = input;
        compiler->m_output = output;
        if(!compiler->checkProcessing())
        {
            delete compiler;
            continue;
        }
        LOGI("data compile %s --> %s", input.c_str(), output.c_str());
        g_config->m_compilers.push_back(compiler);
    }
    for(size_t i=0; i<g_config->m_compilers.size(); ++i)
    {
        g_config->m_compilers[i]->preProcess();
    }
}
Exemplo n.º 5
0
/**
 *\fn           int getFileExtId(const char *filename)
 *\brief        得到文件扩展名ID
 *\param[in]    const char * filename 文件名
 *\return       int 扩展名ID
 */
int CBrowseWnd::getFileExtId(const char *filename)
{
    int id = 0;
    const char *ext = getFileExt(filename);

    mapStrInt::iterator iter = mapExtImage_.find(ext);

    if (iter == mapExtImage_.end())
    {
        SHFILEINFO info = {0};
        SHGetFileInfo(filename, 0, &info, sizeof(info), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES );

        id = ImageList_AddIcon(hImageList_, info.hIcon);

        mapExtImage_[ext] = id;
    }
    else
    {
        id = iter->second;
    }

    return id;
}
Exemplo n.º 6
0
//---------------------------------------------------------------------------
void LogFile::rotate(AsyncFile & file)
{
  if( rotatedFileCount_ == 0 || file.std() || file.size() <= rotationThreshold_ ) return;
  file.close();
  file.exclusive(true).open();
  utf8::String fileExt(getFileExt(file.fileName()));
  uintptr_t i = rotatedFileCount_;
  while( i >= 1 ){
    if( i == rotatedFileCount_ ){
      remove(changeFileExt(file.fileName(),"." + utf8::int2Str(i - 1)) + fileExt,true);
    }
    else {
      rename(
        changeFileExt(file.fileName(),"." + utf8::int2Str(i - 1)) + fileExt,
        changeFileExt(file.fileName(),"." + utf8::int2Str(i)) + fileExt,
	      true,
	      true
      );
    }
    i--;
  }
  file.close();
  rename(file.fileName(),changeFileExt(file.fileName(),".0") + fileExt,true,true);
}
Exemplo n.º 7
0
bool TextureCompiler::processImage( const std::string& input, const std::string& output )
{
    if(!isFileExist(input))
    {
        LOGE("file not exist, return.");
        return false;
    }

    bool fileExist = isFileExist(output);
    bool fileChanged = g_config->is_file_changed(input, m_modifyTime);
    if(fileExist && !fileChanged)
    {
        m_skipped = true;
        return true;
    }

    if(g_config->m_ignoreTextures)
    {
        m_skipped = true;
        return true;
    }

    std::string fileName = getFileName(input);
    std::string ddsFile = getFilePath(output) + fileName + ".dds";

    bool bConvert = false;
    std::string ext = getFileExt(input);
    toLower(ext);
    if(ext != "dds")
        bConvert = true;

#ifndef WIN32
    bConvert = false; //in linux we just copy it to dest
#endif

    if(bConvert)
    {
        //1. first convert the source texture to dds file.
        texconv_compress(input, getFilePath(output), m_format);
        copy_file(input, ddsFile);
    }
    else
        ddsFile = input;

    addDependency("texture", input);

    //2. read the dds file back
    {
        FileReader texutreReader(ddsFile);
        if(!texutreReader.m_size)
            return false;

        //3. back the whole file to one blob.
        uint32_t memSize = texutreReader.m_size + sizeof(Texture);
        MemoryBuffer mem(memSize);
        Texture* tex = (Texture*)mem.m_buf;
        tex->m_handle.idx = bgfx::invalidHandle;
        tex->m_data_size = texutreReader.m_size;
        tex->m_data_offset = sizeof(Texture);
        memcpy(mem.m_buf + sizeof(Texture), texutreReader.m_buf, texutreReader.m_size);
        write_file(output, mem.m_buf, memSize);
    }

    //3. delete the temp dds file.
    if(bConvert)
        delete_file(ddsFile);

    return true;
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
	//Check for minimum number of required arguments
	if(argc < 2)
	{
		std::cerr << "Usage: Executable Input-File Optional-Command" << std::endl;
		return -1;
	}
	//If command argument is given, set it
	std::string argCommand;
	if(argc == 3)
	{
		argCommand = argv[2];
	}

	int counter = 0;
	std::vector<vtkSmartPointer<vtkPolyData> > polyVect;
	float scale[3];
	std::vector<std::string> fileNames;
	std::vector<std::string> plyFiles;

	std::string fileName;
	std::string colorFile;
	std::string outputFile;
	std::string fileExt;
	std::string plyFile;

	//Open parameters file
	ifstream segParam(argv[1]);
	if(!segParam)
	{
		std::cerr << "Error opening segmentation parameter file" << std::endl;
		return -1;
	}
 
	//Read in image scale
	segParam >> scale[0] >> scale[1] >> scale[2];

	//Read in label image file name
	segParam >> fileName;

	segParam.close();

	//Check the image file extension
	if(fileName != " " && fileName != "")
	{	
		//Get file extension and output file base (file name without extension)
		fileExt = getFileExt(fileName);
		outputFile = getOrigFileName(fileName);

		//If tif, process
		if(fileExt == "tif" || fileExt == "tiff" || fileExt == "TIF" || fileExt == "TIFF")
		{ 
			//If running from cache
			if(argCommand == "-c")
			{
				std::cout << "Running from cache..." << std::endl;
				std::vector<std::string> *dirFiles = listFilesDir("cache");
				if(dirFiles->size() <= 2)
				{
					std::cout << "Cache doesn't exist/nothing in cache" << std::endl;
					return -1;
				}
				std::string cacheFileExt;

				//Iterate through vector of strings containing file names in the cache directory
				for(std::vector<std::string>::iterator it = dirFiles->begin(); it != dirFiles->end(); ++it)
				{
					//If the proper file name base is found
					if((*it).find(outputFile) == 0)
					{
						//Get cache file extension
						cacheFileExt = getFileExt((*it));
						//If the file is a poly data file
						if (cacheFileExt == "ply")
						{
							//Add it to the poly data file list
							std::string output = "cache/";
							counter++;
							output.append((*it));
							plyFiles.push_back(output);
						}
					}
				}
				//Render poly data
				if(counter == 0)
				{
					std::cout << "No cached files for this image" << std::endl;
					return -1;
				}
				renderPolyData(counter, scale, plyFiles);
			}
			else
			{				
				//Make a cache directory if one isn't already there	
				MKDIR("cache");
	
				//Append ouput string to original file name for colored images			
				outputFile.append("_out.tif");
				
				//Create relative address string for the colored images to be cached
				std::string output = "cache/";
				output.append(outputFile);
				std::cout << "here" << std::endl;
				//Run graph coloring on the original image, to divide it into colored images
				ftk::NuclearSegmentation *segmentation = new ftk::NuclearSegmentation();
				std::vector<std::string> colorFiles = segmentation->RunGraphColoring(fileName, output);

				//Set counter variable to number of outputted color images
				counter = (int)colorFiles.size();
				//Cycle through the colored images
				for(int i = 0; i < counter; i++)
				{
					//Create string for .ply file name
					colorFile = colorFiles[i];
					plyFile = colorFiles[i].append(".ply");
					//Add this .ply file to the vector of poly data files to be rendered later
					plyFiles.push_back(plyFile);
					//If this .ply file doesn't already exist, generate the poly data and write the 
					//.ply file from the colored image files
					generatePolyData(colorFile, plyFiles[i], polyVect);
				}
				delete segmentation;
				renderPolyData(counter, scale, plyFiles);
				//renderPolyData(counter, scale, polyVect, plyFiles);
			}
		}
		//If file not of the proper type, print error
		else
		{
			std::cerr << "Invalid file type for segmentation output" << std::endl;
			return -1;
		}
	}
	//If parameter file can't be opened, print error
	else
	{
		std::cerr << "Invalid filename in parameters, load valid parameter file" << std::endl;
		return -1;
	}
	return 0;
}
Exemplo n.º 9
0
static bool compare_less_resource(const std::string& nameA, const std::string& nameB)
{
    int orderA = g_resourceMgr.get_resource_order(stringid_caculate(getFileExt(nameA).c_str()));
    int orderB = g_resourceMgr.get_resource_order(stringid_caculate(getFileExt(nameB).c_str()));
    return orderA < orderB;
}