vector<string> LevelPackManager::enumLevelPacks(int type){
	//vector가 return 될 것이다.
	vector<string> v;

	//Now do the type dependent adding.
	switch(type){
		case ALL_PACKS:
		{
			std::map<std::string,LevelPack*>::iterator i;
			for(i=levelpacks.begin();i!=levelpacks.end();++i){
				//levels안에있는 "Custom Levels" pack 을 제외한 모든것을 추가
				if(i->first!="Custom Levels")
					v.push_back(i->first);
			}
			break;
		}
		case CUSTOM_PACKS:
		{
			std::map<std::string,LevelPack*>::iterator i;
			for(i=levelpacks.begin();i!=levelpacks.end();++i){
				//"Custom Levels" levelpack.일 경우에 custom 폴더 안에 있는 levelpacks를 추가한다.
				if(i->second->levelpackPath.find(getUserPath(USER_DATA)+"custom/")==0 || i->first=="Custom Levels"){
					v.push_back(i->first);
				}
			}
			break;
		}
	}

	//vector를 return
	return v;
}
Beispiel #2
0
void initPython()
{
    //init python
    qputenv("PYTHONIOENCODING", "utf-8");
    Py_Initialize();
    if (!Py_IsInitialized())
    {
        qDebug("Cannot initialize python.");
        exit(-1);
    }

    //init module
    geturl_obj = new GetUrl(qApp);
#if PY_MAJOR_VERSION >= 3
    apiModule = PyModule_Create(&moonplayerModule);
    PyObject *modules = PySys_GetObject("modules");
    PyDict_SetItemString(modules, "moonplayer", apiModule);
#else
    apiModule = Py_InitModule("moonplayer", methods);
#endif

    PyModule_AddStringConstant(apiModule, "final_url", "");
    Py_IncRef(exc_GetUrlError);
    PyModule_AddObject(apiModule, "GetUrlError", exc_GetUrlError);

    // plugins' dir
    PyRun_SimpleString("import sys");
    PyRun_SimpleString(QString("sys.path.insert(0, '%1/plugins')").arg(getAppPath()).toUtf8().constData());
    PyRun_SimpleString(QString("sys.path.append('%1/plugins')").arg(getUserPath()).toUtf8().constData());
}
 bool FilesystemData::doesUserExist( string name ) {
     ENTER( "FilesystemData::doesUserExist" );
     string path = getUserPath( name );
     bool toReturn = Io::fileExists( path );
     
     EXIT( "FilesystemData::doesUserExist" );
     return toReturn;
 }
 void FilesystemData::createUser( string name, UserRole role ) {
     ENTER( "FilesystemData::createUser" );
     
     if( doesUserExist( name ) ) {
         Logger::error() << "User already exists!" <<endl;
         throw std::exception();
     }
     string serRole = User::roleToString( role );
     Io::createFile( getUserPath( name ), serRole );
     Io::appendLineToFile(getAccountListPath(), name);
     
     EXIT( "FilesystemData::createUser" );
 }
 User FilesystemData::getUser( string name ) {
     ENTER( "FilesystemData::getUser" );
     
     if( !doesUserExist(name) ) {
         Logger::error() << "No such user";
         throw std::exception();
     }
     
     string serRole;
     Io::initFromFile( getUserPath( name ), serRole );
     
     User toReturn( name, User::roleFromString(serRole) );
     
     EXIT( "FilesystemData::getUser" );
     return toReturn;
 }