Example #1
0
void cOverworld_Manager::Load_Dir(const fs::path& dir, bool user_dir /* = false */)
{
    // set world directory
    vector<fs::path> subdirs = Get_Directory_Files(dir, "", true, false);
    std::sort(subdirs.begin(), subdirs.end());

    for (vector<fs::path>::iterator curdir = subdirs.begin(); curdir != subdirs.end(); ++curdir) {
        try {
            fs::path current_dir = *curdir;

            // only directories with an existing description
            if (File_Exists(current_dir / "description.xml")) {
                cOverworld* overworld = Get_from_Path(current_dir);

                // already available
                if (overworld) {
                    overworld->m_description->m_user = 2; // 2 = available in system *and* in user dir
                    continue;
                }

                overworld = cOverworld::Load_From_Directory(current_dir, user_dir);
                objects.push_back(overworld);
            }
        }
        catch (const std::exception& ex) {
            printf("%s %s\n", path_to_utf8(*curdir).c_str(), ex.what());
        }
    }
}
Example #2
0
cOverworld* cOverworld_Manager::Get(const std::string& str)
{
    cOverworld* world = Get_from_Name(str);

    if (world) {
        return world;
    }

    return Get_from_Path(utf8_to_path(str));
}
Example #3
0
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) 
{
	// set world directory
// fixme : boost should use a codecvt_facet but for now we convert to UCS-2
#ifdef _WIN32
	fs::path full_path( utf8_to_ucs2( dir ) );
#else
	fs::path full_path( dir );
#endif
	fs::directory_iterator end_iter;

	for( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
	{
		try
		{
			std::string current_dir = dir_itr->path().filename().string();

			// only directories with an existing description
			if( fs::is_directory( *dir_itr ) && File_Exists( dir + "/" + current_dir + "/description.xml" ) )
			{
				cOverworld *overworld = Get_from_Path( current_dir );

				// already available
				if( overworld )
				{
					overworld->m_description->m_user = 2;
					continue;
				}

				overworld = new cOverworld();

				// set path
				overworld->m_description->m_path = current_dir;
				// default name is the path
				overworld->m_description->m_name = current_dir;
				// set user
				overworld->m_description->m_user = user_dir;

				objects.push_back( overworld );

				overworld->Load();
			}
		}
		catch( const std::exception &ex )
		{
			printf( "%s %s\n", dir_itr->path().filename().string().c_str(), ex.what() );
		}
	}
}
Example #4
0
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) 
{
	// set world directory
	vector<std::string> subdirs = Get_Directory_Files( dir, "", 1, 0 );

	for( vector<std::string>::iterator curdir = subdirs.begin(); curdir != subdirs.end(); ++curdir )
	{
		try
		{
			std::string current_dir = *curdir;

			// only directories with an existing description
			if( File_Exists( current_dir + "/description.xml" ) )
			{
				cOverworld *overworld = Get_from_Path( current_dir );

				// already available
				if( overworld )
				{
					overworld->m_description->m_user = 2;
					continue;
				}

				overworld = new cOverworld();

				// get relative path
				std::string relative_path( current_dir, current_dir.rfind( '/' ) );

				// set relative path
				overworld->m_description->m_path = relative_path;
				// default name is the path
				overworld->m_description->m_name = relative_path;
				// set user
				overworld->m_description->m_user = user_dir;

				objects.push_back( overworld );

				overworld->Load();
			}
		}
		catch( const std::exception &ex )
		{
			printf( "%s %s\n", curdir->c_str(), ex.what() );
		}
	}
}
Example #5
0
bool cOverworld_Manager::New(std::string name)
{
    string_trim(name, ' ');

    // no name given
    if (name.empty()) {
        return 0;
    }

    // name already exists
    if (Get_from_Path(name)) {
        return 0;
    }

    cOverworld* overworld = new cOverworld();
    overworld->New(name);
    objects.push_back(overworld);

    return 1;
}
Example #6
0
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) 
{
	// set world directory
	fs::path full_path( dir, fs::native );
	fs::directory_iterator end_iter;

	for( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
	{
		try
		{
			std::string current_dir = dir_itr->path().leaf();

			// only directories with an existing description
			if( fs::is_directory( *dir_itr ) && File_Exists( dir + "/" + current_dir + "/description.xml" ) )
			{
				// already available
				if( Get_from_Path( current_dir ) )
				{
					continue;
				}

				cOverworld *overworld = new cOverworld();

				// set path
				overworld->m_description->m_path = current_dir;
				// default name is the path
				overworld->m_description->m_name = current_dir;
				// set user
				overworld->m_description->m_user = user_dir;

				objects.push_back( overworld );

				overworld->Load();
			}
		}
		catch( const std::exception &ex )
		{
			printf( "%s %s\n", dir_itr->path().leaf().c_str(), ex.what() );
		}
	}
}