Пример #1
0
std::vector<std::string> CSimulation2::GetRMSData()
{
	VfsPath path(L"maps/random/");
	VfsPaths pathnames;

	std::vector<std::string> data;

	// Find all ../maps/random/*.json
	Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames);
	if (ret == INFO::OK)
	{
		for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
		{
			// Load JSON file
			CVFSFile file;
			PSRETURN ret = file.Load(g_VFS, *it);
			if (ret != PSRETURN_OK)
			{
				LOGERROR(L"Failed to load file '%ls': %hs", path.string().c_str(), GetErrorString(ret));
			}
			else
			{
				data.push_back(file.DecodeUTF8()); // assume it's UTF-8
			}
		}
	}
	else
	{
		// Some error reading directory
		wchar_t error[200];
		LOGERROR(L"Error reading directory '%ls': %ls", path.string().c_str(), StatusDescription(ret, error, ARRAY_SIZE(error)));
	}

	return data;
}
Пример #2
0
static std::vector<std::string> GetJSONData(const VfsPath& path)
{
	VfsPaths pathnames;
	Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames);
	if (ret != INFO::OK)
	{
		// Some error reading directory
		wchar_t error[200];
		LOGERROR("Error reading directory '%s': %s", path.string8(), utf8_from_wstring(StatusDescription(ret, error, ARRAY_SIZE(error))));
		return std::vector<std::string>();
	}

	std::vector<std::string> data;
	for (const VfsPath& p : pathnames)
	{
		// Load JSON file
		CVFSFile file;
		PSRETURN ret = file.Load(g_VFS, p);
		if (ret != PSRETURN_OK)
		{
			LOGERROR("GetJSONData: Failed to load file '%s': %s", p.string8(), GetErrorString(ret));
			continue;
		}

		data.push_back(file.DecodeUTF8()); // assume it's UTF-8
	}

	return data;
}
Пример #3
0
std::vector<std::string> CComponentManager::Script_FindJSONFiles(void* UNUSED(cbdata), std::wstring subPath, bool recursive)
{
	FindJSONFilesCallbackData cbData;
	cbData.path = VfsPath(L"simulation/data/" + subPath + L"/");
	
	int dir_flags = 0;
	if (recursive) {
		dir_flags = vfs::DIR_RECURSIVE;
	}

	// Find all simulation/data/{subPath}/*.json recursively
	Status ret = vfs::ForEachFile(g_VFS, cbData.path, FindJSONFilesCallback, (uintptr_t)&cbData, L"*.json", dir_flags);
	if (ret != INFO::OK)
	{
		// Some error reading directory
		wchar_t error[200];
		LOGERROR(L"Error reading directory '%ls': %ls", cbData.path.string().c_str(), StatusDescription(ret, error, ARRAY_SIZE(error)));
	}
	
	return cbData.templates;
}
Пример #4
0
/**
 * @return the newly created and unique instance of the next best counter
 * that is deemed safe, or 0 if all have already been created.
 **/
static ICounter* GetNextBestSafeCounter()
{
	for(;;)
	{
		static size_t nextCounterId = 0;
		ICounter* counter = CreateCounter(nextCounterId++);
		if(!counter)
			return 0;	// tried all, none were safe

		Status err = ActivateCounter(counter);
		if(err == INFO::OK)
		{
			debug_printf(L"HRT: using name=%ls freq=%f\n", counter->Name(), counter->NominalFrequency());
			return counter;	// found a safe counter
		}
		else
		{
			wchar_t buf[100];
			debug_printf(L"HRT: activating %ls failed: %ls\n", counter->Name(), StatusDescription(err, buf, ARRAY_SIZE(buf)));
			DestroyCounter(counter);
		}
	}
}
Пример #5
0
// not thread-safe!
static const wchar_t* HardcodedErrorString(int err)
{
    static wchar_t description[200];
    StatusDescription((Status)err, description, ARRAY_SIZE(description));
    return description;
}
Пример #6
0
std::vector<std::string> CSimulation2::GetCivData()
{
	VfsPath path(L"civs/");
	VfsPaths pathnames;

	std::vector<std::string> data;

	// Load all JSON files in civs directory
	Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames);
	if (ret == INFO::OK)
	{
		for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
		{
			// Load JSON file
			CVFSFile file;
			PSRETURN ret = file.Load(g_VFS, *it);
			if (ret != PSRETURN_OK)
			{
				LOGERROR(L"CSimulation2::GetCivData: Failed to load file '%ls': %hs", path.string().c_str(), GetErrorString(ret));
			}
			else
			{
				data.push_back(std::string(file.GetBuffer(), file.GetBuffer() + file.GetBufferSize()));
			}
		}
	}
	else
	{
		// Some error reading directory
		wchar_t error[200];
		LOGERROR(L"CSimulation2::GetCivData: Error reading directory '%ls': %ls", path.string().c_str(), StatusDescription(ret, error, ARRAY_SIZE(error)));
	}

	return data;
}
Пример #7
0
bool CMapGeneratorWorker::LoadScripts(const std::wstring& libraryName)
{
    // Ignore libraries that are already loaded
    if (m_LoadedLibraries.find(libraryName) != m_LoadedLibraries.end())
    {
        return true;
    }

    // Mark this as loaded, to prevent it recursively loading itself
    m_LoadedLibraries.insert(libraryName);

    VfsPath path = L"maps/random/" + libraryName + L"/";
    VfsPaths pathnames;

    // Load all scripts in mapgen directory
    Status ret = vfs::GetPathnames(g_VFS, path, L"*.js", pathnames);
    if (ret == INFO::OK)
    {
        for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
        {
            LOGMESSAGE(L"Loading map generator script '%ls'", it->string().c_str());

            if (!m_ScriptInterface->LoadGlobalScriptFile(*it))
            {
                LOGERROR(L"CMapGeneratorWorker::LoadScripts: Failed to load script '%ls'", it->string().c_str());
                return false;
            }
        }
    }
    else
    {
        // Some error reading directory
        wchar_t error[200];
        LOGERROR(L"CMapGeneratorWorker::LoadScripts: Error reading scripts in directory '%ls': %ls", path.string().c_str(), StatusDescription(ret, error, ARRAY_SIZE(error)));
        return false;
    }

    return true;
}
Пример #8
0
std::vector<std::string> CMapGeneratorWorker::GetCivData(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
{
    VfsPath path(L"civs/");
    VfsPaths pathnames;

    std::vector<std::string> data;

    // Load all JSON files in civs directory
    Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames);
    if (ret == INFO::OK)
    {
        for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
        {
            // Load JSON file
            CVFSFile file;
            PSRETURN ret = file.Load(g_VFS, *it);
            if (ret != PSRETURN_OK)
            {
                LOGERROR(L"CMapGeneratorWorker::GetCivData: Failed to load file '%ls': %hs", path.string().c_str(), GetErrorString(ret));
            }
            else
            {
                data.push_back(file.DecodeUTF8()); // assume it's UTF-8
            }
        }
    }
    else
    {
        // Some error reading directory
        wchar_t error[200];
        LOGERROR(L"CMapGeneratorWorker::GetCivData: Error reading directory '%ls': %ls", path.string().c_str(), StatusDescription(ret, error, ARRAY_SIZE(error)));
    }

    return data;

}