void* LibraryManager::getFctFromName(const std::string &fctname, LibraryType libraryType)
    {
        void *fct;
        boost::filesystem::directory_iterator end_iter;
        std::string extension = EXTENSION_LIB;

        if (libLoaded.empty())
        {
            scanPlugins();
        }

        for (std::map<std::string, IDynLibrary*>::iterator it = libLoaded.begin(); it != libLoaded.end(); ++it)
        {
            try
            {
                if ((*it).second != NULL && hasEnding((*it).first, enumType[libraryType] + extension)
		    && (fct = (*it).second->getSymbol(fctname.c_str())) != NULL)
                    return fct;
            }
            catch (...) {}
        }

        return NULL;
    }
Esempio n. 2
0
void					OnEditor::loadFromDirectory(std::string const &directory, std::vector<std::string> *storage)
{
	DIR					*dir;
	struct dirent		*ent;
	std::string			repertory(directory);
	std::string			wantedType(".png");

	if ((dir = opendir(directory.c_str())) == NULL)
		throw RTypeException("Could not open" + directory);

	while ((ent = readdir(dir)) != NULL)
	{
		std::string		image(ent->d_name);
		if (hasEnding(image, wantedType))
		{
			std::string		name(image.substr(0, image.size() - wantedType.size()));

			if (storage != NULL)
				storage->push_back(name);
			this->gameData->resourceBank->setTexture(name, repertory + image);
		}
	}
	closedir(dir);
}
Esempio n. 3
0
void FilesManager::SendBrowsePath(string pathT) const
{
	string directoryArray;
	string filesArray;

	string browseInfos;

	WIN32_FIND_DATA w32fd;
	LARGE_INTEGER filesize;
	//std::unique_ptr<char[]> szDir(new char[MAX_PATH]);
	HANDLE hFind;
	DWORD dwError;

	string toBrowse = pathT;
	if (hasEnding(toBrowse, "\\")) 
	{
		toBrowse += "*";
	}
	else 
	{
		toBrowse += "\\*";
	}

	if (pathT.length() > MAX_PATH - 3)
		return;


	hFind = FindFirstFile(toBrowse.c_str(), &w32fd);

	if (hFind == INVALID_HANDLE_VALUE)
		return;


	do
	{
		if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
		{
			string filNa = w32fd.cFileName;

			if (!filNa.compare(".") || !filNa.compare(".."))
			{
				continue;
			}
			if (directoryArray.length() != 0) 
			{
				directoryArray += "*";
			}
			directoryArray += w32fd.cFileName;
		}
		else 
		{
			filesize.LowPart = w32fd.nFileSizeLow;
			filesize.HighPart = w32fd.nFileSizeHigh;
			// File + size

			if (filesArray.length() != 0)  
			{
				filesArray += "*";
			}

			string file;
			file += w32fd.cFileName;
			file += ":";
			file += to_string(filesize.QuadPart);

			filesArray += file;
		}
	}
	while (FindNextFile(hFind, &w32fd) != 0);

	dwError = GetLastError();
	if (dwError != ERROR_NO_MORE_FILES) 
	{
		// error ? 
	}

	FindClose(hFind);


	if (directoryArray.length() > 0 || filesArray.length() > 0) 
	{
		browseInfos += directoryArray;
		browseInfos += "?";
		browseInfos += filesArray;
	}

	packetBuilder *bld = new packetBuilder(_filesManager, browsePath);
	bld->WriteData((unsigned char*)browseInfos.c_str(), browseInfos.length(), _string);
	bld->FinalizePacket();
//	m_sendSerializedPacketCallback(bld->GetSerializedPacket(), bld->GetPacketSize());
	SendPacketCallback(bld);

	//delete bld;

}
bool hasEndingLower(std::string const &fullString_, std::string const &_ending)
{
	std::string fullstring = fullString_, ending = _ending;
	transform(fullString_.begin(), fullString_.end(), fullstring.begin(), ::tolower);
	return hasEnding(fullstring, ending);
}
Esempio n. 5
0
void exportGraphColors (std::string solution)
{
  std::ofstream outFile("graph.data");

  std::istringstream iss(solution);
  std::string token;
  while(getline(iss, token, ';'))
  {
    std::string prefix = token.substr(2,2);

    if (hasEnding(token, "true"))
    {
      if (hasBegining(token, "[R"))
      {
        if (colorMap.find(prefix) != colorMap.end())
        {
          colorMap.at(prefix) += 10;
        }
        else
        {
          colorMap.insert(std::pair<std::string, int>(prefix, 10));
        }
      }
      else if (hasBegining(token, "[B"))
      {
        if (colorMap.find(prefix) != colorMap.end())
        {
          colorMap.at(prefix) += 1;
        }
        else
        {
          colorMap.insert(std::pair<std::string, int>(prefix, 1));
        }
      }
    }
    else
    {
      if (prefix != "]]" && colorMap.find(prefix) == colorMap.end())
      {
        colorMap.insert(std::pair<std::string, int>(prefix, 0));
      }
    }
  }

  std::map<std::string, int>::const_iterator it;
  std::ostringstream oss;

  for (it = colorMap.begin(); it != colorMap.end(); ++it)
  {
    switch ((*it).second) {
      case 11:
		    oss << (*it).first << " red" << std::endl;
        break;
      case 10:
        oss << (*it).first << " green" << std::endl;
        break;
      case 1:
        oss << (*it).first << " blue" << std::endl;
        break;
      default:
        oss << (*it).first << " yellow" << std::endl;
        break;
    }
  }
  std::cout << oss.str() << std::endl;

  outFile << oss.str();


  outFile.close();
}
    void LibraryManager::scanPlugins()
    {
        void* fct = NULL;
        boost::filesystem::directory_iterator end_iter;
        std::string extension = EXTENSION_LIB;
        Settings* setting = Settings::getInstance();
        std::string fctname = "getLibraryName";

        for (std::vector<std::string>::iterator it = setting->PluginFolders.begin(); it != setting->PluginFolders.end(); ++it)
        {
            boost::filesystem::path pluginDir(*it);
            if (boost::filesystem::exists(pluginDir) && boost::filesystem::is_directory(pluginDir))
            {
                LOG(LogLevel::PLUGINS) << "Scanning library folder " << pluginDir.string() << " ...";
                for (boost::filesystem::directory_iterator dir_iter(pluginDir); dir_iter != end_iter; ++dir_iter)
                {
                    LOG(LogLevel::PLUGINS) << "Checking library " << dir_iter->path().filename().string() << "...";
                    if ((boost::filesystem::is_regular_file(dir_iter->status()) || boost::filesystem::is_symlink(dir_iter->status()))
                        && dir_iter->path().extension() == extension
                        && (hasEnding(dir_iter->path().filename().string(), enumType[LibraryManager::CARDS_TYPE] + extension)
                        || hasEnding(dir_iter->path().filename().string(), enumType[LibraryManager::READERS_TYPE] + extension)
                        || hasEnding(dir_iter->path().filename().string(), enumType[LibraryManager::UNIFIED_TYPE] + extension)))
                    {
                        try
                        {
                            if (libLoaded.find(dir_iter->path().filename().string()) == libLoaded.end())
                            {
                                IDynLibrary* lib = newDynLibrary(dir_iter->path().string());
                                fct = lib->getSymbol(fctname.c_str());
                                if (fct != NULL)
                                {
                                    LOG(LogLevel::PLUGINS) << "Library " << dir_iter->path().filename().string() << " loaded.";
                                    libLoaded[dir_iter->path().filename().string()] = lib;
                                }
                                else
                                {
                                    LOG(LogLevel::PLUGINS) << "Cannot found library entry point in " << dir_iter->path().filename().string() << ". Skipped.";
                                    delete lib;
                                }
                            }
                            else
                            {
                                LOG(LogLevel::PLUGINS) << "Library " << dir_iter->path().filename().string() << " already loaded. Skipped.";
                            }
                        }
                        catch (const std::exception &e)
                        {
                            LOG(LogLevel::ERRORS) << "Something bad happened when handling " << dir_iter->path().filename().string() <<
                            ": " << e.what();
                        }
                    }
                    else
                    {
                        LOG(LogLevel::PLUGINS) << "File " << dir_iter->path().filename().string() << " does not match excepted filenames. Skipped.";
                    }
                }
            }
            else
            {
                LOG(LogLevel::WARNINGS) << "Cannot found plug-in folder " << (*it);
            }
        }
    }
Esempio n. 7
0
void HiresTexture::Update()
{
	s_check_native_format = false;
	s_check_new_format = false;

	if (s_prefetcher.joinable())
	{
		s_textureCacheAbortLoading.Set();
		s_prefetcher.join();
	}

	if (!g_ActiveConfig.bHiresTextures)
	{
		s_textureMap.clear();
		s_textureCache.clear();
		size_sum.store(0);
		return;
	}

	if (!g_ActiveConfig.bCacheHiresTextures)
	{
		s_textureCache.clear();
		size_sum.store(0);
	}
	
	s_textureMap.clear();
	const std::string& gameCode = SConfig::GetInstance().m_strUniqueID;
	std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str());	
	std::string ddscode(".dds");
	std::string cddscode(".DDS");
	std::vector<std::string> Extensions = {
		".png",
		".dds"
	};

	auto rFilenames = DoFileSearch(Extensions, { szDir }, /*recursive*/ true);

	const std::string code = StringFromFormat("%s_", gameCode.c_str());
	const std::string miptag = "mip";
	const std::string normaltag = ".nrm";
	for (u32 i = 0; i < rFilenames.size(); i++)
	{
		std::string FileName;
		std::string Extension;
		SplitPath(rFilenames[i], nullptr, &FileName, &Extension);
		if (FileName.substr(0, code.length()) == code)
		{
			s_check_native_format = true;
		}
		else if (FileName.substr(0, s_format_prefix.length()) == s_format_prefix)
		{
			s_check_new_format = true;
		}
		else
		{
			// Discard wrong files
			continue;
		}
		const bool is_compressed = Extension.compare(ddscode) == 0 || Extension.compare(cddscode) == 0;
		const bool is_normal_map = hasEnding(FileName, normaltag);
		if (is_normal_map)
		{
			FileName = FileName.substr(0, FileName.size() - normaltag.size());
		}
		hires_mip_level mip_level_detail(rFilenames[i], Extension, is_compressed);
		u32 level = 0;
		size_t idx = FileName.find_last_of('_');
		std::string miplevel = FileName.substr(idx + 1, std::string::npos);
		if (miplevel.substr(0, miptag.length()) == miptag)
		{
			sscanf(miplevel.substr(3, std::string::npos).c_str(), "%i", &level);
			FileName = FileName.substr(0, idx);
		}
		HiresTextureCache::iterator iter = s_textureMap.find(FileName);
		u32 min_item_size = level + 1;
		if (iter == s_textureMap.end())
		{
			HiresTextureCacheItem item(min_item_size);
			if (is_normal_map)
			{
				item.normal_map.resize(min_item_size);
			}
			std::vector<hires_mip_level> &dst = is_normal_map ? item.normal_map : item.color_map;
			dst[level] = mip_level_detail;
			s_textureMap.emplace(FileName, item);
		}
		else
		{
			std::vector<hires_mip_level> &dst = is_normal_map ? iter->second.normal_map : iter->second.color_map;
			if (dst.size() < min_item_size)
			{
				dst.resize(min_item_size);
			}
			dst[level] = mip_level_detail;
		}
	}

	if (g_ActiveConfig.bCacheHiresTextures && s_textureMap.size() > 0)
	{
		// remove cached but deleted textures
		auto iter = s_textureCache.begin();
		while (iter != s_textureCache.end())
		{
			if (s_textureMap.find(iter->first) == s_textureMap.end())
			{
				size_sum.fetch_sub(iter->second->m_cached_data_size);
				iter = s_textureCache.erase(iter);
			}
			else
			{
				iter++;
			}
		}
		s_textureCacheAbortLoading.Clear();
		s_prefetcher = std::thread(Prefetch);
	}
}
Esempio n. 8
0
void CLIMenu::start() {

    //Einlesen des Bildnamens
    std::cout << "Willkommen bei der Photoshop-Alternative! Sogar OpenSource ;)" << std::endl;

    std::string bildname = "";
    do {
        std::cout << "Bildname eingeben:" << std::endl;
        bildname = this->leseText();

    } while (!hasEnding(bildname.c_str(), ".pgm"));

    try {

        PGMBild bild = PGMBild(bildname);

        std::cout << "Menü Start: \n g Glättung \n i Invertierung \n k Kantenbildung \n s Schärfung \n c Kopieren \n e Ende \n" << std::endl;
        std::string menuEingabe = "";
        while (true) {
            
            std::cout << "Auswahl :" << std::endl;
            
            menuEingabe = this->leseText();

            if (menuEingabe.size() == 1) {

                switch ((char) menuEingabe[0]) {
                    case 'i':
                        bild.invert(std::string("invert") + std::string(bildname));
                        continue;
                    case 'g':
                        bild.antiAliasing(std::string("glatt") + std::string(bildname));
                        continue;
                    case 'k':
                        bild.edgeDetection(std::string("kante") + std::string(bildname));
                        continue;
                    case 's':
                        bild.sharpening(std::string("scharf") + std::string(bildname));
                        continue;
                    case 'c':
                        bild.copy(std::string("kopie") + std::string(bildname));
                        continue;
                    case 'e':
                        std::cout << "Programm Ende" << std::endl;
                        return;
                    default:
                        std::cout << "Ungütlige Eingabe" << std::endl;
                        continue;
                }

            } else {
                std::cout << "Ungültige Eingabe" << std::endl;
            }
        } 

        return;

    } catch (const char* msg) {
        std::cout << msg << std::endl;
        std::cout << "Programmende" << std::endl;
        return;
    }
}
Esempio n. 9
0
void MSBuildProvider::writeFileListToProject(const FileNode &dir, std::ofstream &projectFile, const int, const StringList &duplicate,
                                             const std::string &objPrefix, const std::string &filePrefix) {
	// Reset lists
	_filters.clear();
	_compileFiles.clear();
	_includeFiles.clear();
	_otherFiles.clear();
	_resourceFiles.clear();
	_asmFiles.clear();

	// Compute the list of files
	_filters.push_back(""); // init filters
	computeFileList(dir, duplicate, objPrefix, filePrefix);
	_filters.pop_back();    // remove last empty filter

	// Output compile files
	if (!_compileFiles.empty()) {
		projectFile << "\t<ItemGroup>\n";
		for (std::list<FileEntry>::const_iterator entry = _compileFiles.begin(); entry != _compileFiles.end(); ++entry) {
			const bool isDuplicate = (std::find(duplicate.begin(), duplicate.end(), (*entry).name + ".o") != duplicate.end());

			// Deal with duplicated file names
			if (isDuplicate) {
				projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\">\n"
				               "\t\t\t<ObjectFileName>$(IntDir)" << (*entry).prefix << "%(Filename).obj</ObjectFileName>\n";

				if (hasEnding((*entry).path, "base\\version.cpp"))
					projectFile <<  "\t\t\t<PreprocessorDefinitions Condition=\"'$(Configuration)'=='Debug'\">SCUMMVM_SVN_REVISION#&quot; $(SCUMMVM_REVISION_STRING)&quot;;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n";

				projectFile << "\t\t</ClCompile>\n";
			} else {
				projectFile << "\t\t<ClCompile Include=\"" << (*entry).path << "\" />\n";
			}
		}
		projectFile << "\t</ItemGroup>\n";
	}

	// Output include, other and resource files
	OUPUT_FILES_MSBUILD(_includeFiles, "ClInclude")
	OUPUT_FILES_MSBUILD(_otherFiles, "None")
	OUPUT_FILES_MSBUILD(_resourceFiles, "ResourceCompile")

	// Output asm files
	if (!_asmFiles.empty()) {
		projectFile << "\t<ItemGroup>\n";
		for (std::list<FileEntry>::const_iterator entry = _asmFiles.begin(); entry != _asmFiles.end(); ++entry) {

			const bool isDuplicate = (std::find(duplicate.begin(), duplicate.end(), (*entry).name + ".o") != duplicate.end());

			projectFile << "\t\t<CustomBuild Include=\"" << (*entry).path << "\">\n"
			               "\t\t\t<FileType>Document</FileType>\n";

			OUTPUT_NASM_COMMAND_MSBUILD("Debug")
			OUTPUT_NASM_COMMAND_MSBUILD("Analysis")
			OUTPUT_NASM_COMMAND_MSBUILD("Release")

			projectFile << "\t\t</CustomBuild>\n";
		}
		projectFile << "\t</ItemGroup>\n";
	}
}
Esempio n. 10
0
vector<string> FileBrowser::GetFolderList()
{
	vector<string> retVal;
	if(m_CurrentFolder.size()==0)
	{
		//List Drives
		retVal.push_back("Game:");

		if (SETTINGS::getInstance().getSambaClientOn()) 
			retVal.push_back("smb:");

		std::vector<Drive* const> mountedDrives;
	
		DrivesManager::getInstance().getMountedDrives(&mountedDrives);
		for(unsigned int x=0;x<mountedDrives.size();x++)
		{

			retVal.push_back(mountedDrives[x]->GetCleanDriveName() + ":");
		}

		return retVal;
	}
	else
	{
		retVal.push_back("..");

		string path = GetCurrentPath();
		if (path.substr(0,4).compare("smb:") == 0) {
			map<string, unsigned int> m_SambaTypes;

			int dir;
			if (path.length() == 5) {
				if (SambaClient::getInstance().m_SambaTopLevelTypes.size() > 0) {
					for (map<string, unsigned int>::const_iterator it = SambaClient::getInstance().m_SambaTopLevelTypes.begin(); it != SambaClient::getInstance().m_SambaTopLevelTypes.end(); ++it)
					{
						retVal.push_back(it->first);
					}
					return retVal;
				}
			}
			path.append("/");
			if ((dir = smbc_opendir(path.c_str())) < 0)
			{
				DebugMsg("FileBrowser", "Could not open directory [%s] (%d:%s)\n", path.c_str(), errno, strerror(errno));
				if (errno == 13) {  // permission denied
					string user;
					string password;
					string share;
					string rawpath = GetRawSmbPath(user, password, share);

					XUIMessage xuiMsg;
					XuiMessage(&xuiMsg, XM_SMB_PERMISSION_DENIED);
					Credentials * cred = new Credentials();
					_XuiMessageExtra(&xuiMsg,(XUIMessageData*) cred, sizeof(*cred));
					cred->smbPath = rawpath;
					cred->user = user;
					cred->password = password;
					cred->share = share;

					XuiSendMessage( parentScene , &xuiMsg );
				}
				return retVal;
			}
			struct smbc_dirent *        dirent;
		    while ((dirent = smbc_readdir(dir)) != NULL)
			{
				if (dirent->smbc_type != SMBC_WORKGROUP &&
					dirent->smbc_type != SMBC_SERVER &&
					dirent->smbc_type != SMBC_FILE_SHARE &&
					dirent->smbc_type != SMBC_DIR)
					continue;
				if (strcmp(dirent->name, ".") == 0 || strcmp(dirent->name, "..") == 0)
					continue;
				if (hasEnding(dirent->name, "$"))
					continue;

				if (m_CurrentFolder.size() == 1) {
					SambaClient::getInstance().m_SambaTopLevelTypes[dirent->name] = dirent->smbc_type;
				}

				// filter ourselves out of the list of servers
				if (SETTINGS::getInstance().getSambaServerOn() && CFreestyleApp::getInstance().hasInternetConnection()) {
					if (m_CurrentFolder.size() == 2) {
						string wrkgroup = SETTINGS::getInstance().getSambaClientWorkgroup();
						if (stricmp(wrkgroup.c_str(), m_CurrentFolder[1].c_str()) == 0) {
							string hostname = SETTINGS::getInstance().getHostname();
							if (stricmp(hostname.c_str(), dirent->name) == 0)
								continue;
						}
					}
				}
				retVal.push_back(dirent->name);
			}
//			if (m_CurrentFolder.size() == 1) {
//				m_SambaTopLevelTypes = m_SambaTypes;
//				//m_CurrentFolderSambaTypes.push_back(m_SambaTypes);
//			}
			smbc_closedir(dir);
			return retVal;
		}
		WIN32_FIND_DATA findFileData;
		memset(&findFileData,0,sizeof(WIN32_FIND_DATA));
		string searchcmd = GetCurrentPath() + "\\*";
	
		HANDLE hFind = FindFirstFile(searchcmd.c_str(), &findFileData);
		if (hFind == INVALID_HANDLE_VALUE)
			return retVal;
		do {
			string s = findFileData.cFileName;
			if(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				retVal.push_back(s);
			}
		} while (FindNextFile(hFind, &findFileData));
		FindClose(hFind);
		return retVal;
	}

}
Esempio n. 11
0
void handleStory(const Options& options, vector<HistoryItem>& history, json_value* story)
{
	string id;
	string title;
	string selftext;
	int score;
	bool over_18;
	string thumbnail;
	string url;
	double created_utc;
	string permalink;

	for (json_value* it = story->first_child; it; it = it->next_sibling)
	{
		if (!strcmp(it->name, "id")) 
			id = it->string_value;
		if (!strcmp(it->name, "title")) 
			title = it->string_value;
		if (!strcmp(it->name, "selftext")) 
			selftext = it->string_value;
		if (!strcmp(it->name, "score")) 
			score = it->int_value;
		if (!strcmp(it->name, "over_18")) 
			over_18 = it->int_value ? true : false;
		if (!strcmp(it->name, "thumbnail")) 
			thumbnail = it->string_value;
		if (!strcmp(it->name, "url")) 
			url = it->string_value;
		if (!strcmp(it->name, "created_utc")) 
			created_utc = it->float_value;
		if (!strcmp(it->name, "permalink")) 
			permalink = it->string_value;
	}

    replaceAll(url, "&amp;", "&");
    
	bool inHistory = isInHistory(history, id);

	if (inHistory && !options.openAll)
		return;

	if (options.imageOnly)
	{
		bool image = false;
		
		if (url.find("imgur.com") != string::npos)	image = true;
		if (url.find("gfycat.com") != string::npos)	image = true;

		if (hasEnding(url, ".gif")) image = true;
		if (hasEnding(url, ".jpg")) image = true;
		if (hasEnding(url, ".png")) image = true;
		
		if (!image)
			return;
	}

	if (options.openPermalink)
		openUrl("http://reddit.com" + permalink);

	if (options.openLink)
		openUrl(url);	

	if (!inHistory)
	{
		HistoryItem hi;
		hi.id   = id;
		hi.date = time(NULL);
		history.push_back(hi);
	}
	gTotal++;
}