Exemple #1
0
/**
 * @brief Write user customized hosts list into the hosts file if the customized
 * hosts file exists.
 */
void MakeHosts::write_customized()
{
    qDebug()<<"custom in";
    if(QFile::exists(custom)){
        QFile custom_file(custom);
        custom_file.open(QIODevice::ReadWrite);
        hosts_file->write((eol + "# Section Customized: " + eol).toLocal8Bit());
        char a[250];
        while(!custom_file.atEnd()){
            custom_file.readLine(a, 250);
            QString line(a);
            if(line.startsWith("#")){
                hosts_file->write((line + eol).toLocal8Bit());
            }
            int a = line.indexOf(" ");
            if(a >= 0){
                QString ip = line.left(a);
                QString host = line.mid(a);
                if(ip.length() < 16){
                    ip = ip.leftJustified(16);
                }
                hosts_file->write((ip + " " +  host + eol).toLocal8Bit());
            }
        }
        hosts_file->write((eol + "# Section End: Customized: " + eol).toLocal8Bit());
        custom_file.close();
    }
    qDebug()<<"custom out";
}
Exemple #2
0
// static
void LLSpellChecker::refreshDictionaryMap()
{
	const std::string app_path = getDictionaryAppPath();
	const std::string user_path = getDictionaryUserPath();

	// Load dictionary information (file name, friendly name, ...)
    std::string user_filename(user_path + DICT_FILE_MAIN);
	llifstream user_file(user_filename.c_str(), std::ios::binary);
	if ( (!user_file.is_open()) 
		|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(sDictMap, user_file)) 
		|| (0 == sDictMap.size()) )
	{
        std::string app_filename(app_path + DICT_FILE_MAIN);
		llifstream app_file(app_filename.c_str(), std::ios::binary);
		if ( (!app_file.is_open()) 
			|| (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXMLDocument(sDictMap, app_file)) 
			|| (0 == sDictMap.size()) )
		{
			return;
		}
	}

	// Load user installed dictionary information
	llifstream custom_file(user_filename.c_str(), std::ios::binary);
	if (custom_file.is_open())
	{
		LLSD custom_dict_map;
		LLSDSerialize::fromXMLDocument(custom_dict_map, custom_file);
		for (LLSD::array_iterator it = custom_dict_map.beginArray(); it != custom_dict_map.endArray(); ++it)
		{
			LLSD& dict_info = *it;
			dict_info["user_installed"] = true;
			setDictionaryData(dict_info);
		}
		custom_file.close();
	}

	// Look for installed dictionaries
	std::string tmp_app_path, tmp_user_path;
	for (LLSD::array_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
	{
		LLSD& sdDict = *it;
		tmp_app_path = (sdDict.has("name")) ? app_path + sdDict["name"].asString() : LLStringUtil::null;
		tmp_user_path = (sdDict.has("name")) ? user_path + sdDict["name"].asString() : LLStringUtil::null;
		sdDict["installed"] = 
			(!tmp_app_path.empty()) && ((gDirUtilp->fileExists(tmp_user_path + ".dic")) || (gDirUtilp->fileExists(tmp_app_path + ".dic")));
	}

	sSettingsChangeSignal();
}