示例#1
0
idStr CMissionManager::GetNewFoundModsText()
{
	if (_newFoundMods.Num() == 0)
	{
		return "";
	}

	idStr text;

	for (int i = 0; i < _newFoundMods.Num(); ++i)
	{
		CModInfoPtr info = GetModInfo(_newFoundMods[i]);

		if (info == NULL) continue;

		text += (text.IsEmpty()) ? "" : "\n";
		text += info->displayName;

		if (i == 1 && _newFoundMods.Num() > 3)
		{
			// Truncate the text
			int rest = _newFoundMods.Num() - (i + 1);
			text += va("\nAnd %d more mission%s.", rest, rest == 1 ? "" : "s");

			break;
		}
	}

	return text;
}
示例#2
0
CMissionManager::InstallResult CMissionManager::InstallMod(const idStr& name)
{
	CModInfoPtr info = GetModInfo(name); // result is always non-NULL

	const idStr& modName = info->modName;

	// Ensure that the target folder exists
	fs::path targetFolder = g_Global.GetModPath(modName.c_str());

	if (!fs::create_directory(targetFolder))
	{
		// Directory exists, not a problem, but log this
		DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("FM targetFolder already exists: %s\r", targetFolder.string().c_str());
	}

#if 0
	// Path to the darkmod directory
	fs::path darkmodPath = GetDarkmodPath();

	// greebo: We don't copy PK4s around anymore, they remain in the fms/ subfolders

	// Copy all PK4s from the FM folder (and all subdirectories)
	idFileList* pk4Files = fileSystem->ListFilesTree(info->pathToFMPackage, ".pk4", false);

	for (int i = 0; i < pk4Files->GetNumFiles(); ++i)
	{
		// Source file (full OS path)
		fs::path pk4fileOsPath = GetDarkmodPath() / pk4Files->GetFile(i);

		// Target location
		fs::path targetFile = targetFolder / pk4fileOsPath.leaf();

		DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Copying file %s to %s\r", pk4fileOsPath.string().c_str(), targetFile.string().c_str());

		// Use boost::filesystem instead of id's (comments state that copying large files can be problematic)
		//fileeSystem->CopyFile(pk4fileOsPath, targetFile.string().c_str());

		// Copy the PK4 file and make sure any target file with the same name is removed beforehand
		if (!DoCopyFile(pk4fileOsPath, targetFile, true))
		{
			// Failed copying
			return COPY_FAILURE;
		}
	}

	fileSystem->FreeFileList(pk4Files);
#endif

	// Save the name to currentfm.txt
	WriteCurrentFmFile(modName);

    // taaaki: now that fms are loaded directly from <basepath>/darkmod/fms/ 
    //         we don't need to copy config files around (i.e. just use the 
    //         one in <basepath>/darkmod/ (same with config.spec)

	return INSTALLED_OK;
}
//--------------------------------------------------------------------
// @mfunc Init
//
// Init used to create extended error object
//
//--------------------------------------------------------------------
BOOL COLEDB::Init()
{
	WCHAR* pwszValue = NULL;

	//If not called from LTM, setup CTestCases info...
	if(!m_fInsideTestCase)
		SetOwningMod(0, GetModInfo()->GetThisTestModule());

	// Check for the Localize keyword
	if(GetModInfo()->GetInitStringValue(L"LOCALIZE", &pwszValue))
		m_fLocalize = TRUE;

	// Create an object for checking extended errors, which will use
	// m_pError to increment the error count as needed.
	m_pExtError = new CExtError(m_pThisTestModule->m_ProviderClsid, m_pError, m_fLocalize);
	PROVIDER_FREE(pwszValue);

	return m_pExtError != NULL;
}
示例#4
0
//--------------------------------------------------------------------
// @mfunc ReleaseDataSourceObject
//
// Gets a Data Source Object for the current provider and returns
// an ITransactionDispenser interface on that object if ppITransactionDispenser
// is not null. <nl>
//
// NOTE:  The user must call the following function to be fully released
// from the provider:
//
//--------------------------------------------------------------------
HRESULT	CDataSourceObject::CreateDataSourceObject(void)
{
	HRESULT hr = S_OK;

	// If we don't have a Data Source yet	
	if(m_pIDBInitialize == NULL)
		CHECK(hr = GetModInfo()->CreateProvider(NULL, IID_IDBInitialize, (IUnknown**)&m_pIDBInitialize), S_OK);

	return hr;
}									   
示例#5
0
CModInfoPtr CMissionManager::GetModInfo(int index)
{
	if (index < 0 || index >= _availableMods.Num())
	{
		return CModInfoPtr(); // out of bounds
	}

	// Pass the call to the getbyname method
	return GetModInfo(_availableMods[index]);
}
//--------------------------------------------------------------------
// @mfunc Tokenize the Provider info
//
// @rdesc BOOL
//      @flag TRUE | Parsing yielded no Error
//
BOOL CParseInitFile::ParseProviderInfo()
{
	//move to beginning of file
    seekg(0L);
	CHAR* pszStart = NULL;
	CHAR* pszEnd = NULL;
	CHAR szVersion[100];

	TRACE_CALL(L"PRIVLIB: CParseInitFile::ParseProviderInfo.\n");

	//Skip over any lines, until the [INFO] section is reached...
	//Make sure the INI contains the required version (at least)
	if( FindSection("[INFO]")==S_OK &&
		GetNextLine(m_pvInput, MAX_INPUT_BUFFER)==S_OK  &&
		(pszStart = strstr(m_pvInput, START_OF_TYPE)) &&
		(pszStart = strstr(pszStart, "VERSION=")) &&
		(pszStart = strstr(pszStart, ",")) &&
		(pszStart = strstr(pszStart+1, ",")) &&
		(pszEnd = strstr(pszStart+1, ",")) )
	{
		//Build Version is between 2nd and 3rd comma.  (1,50,3518,00)
		pszStart++;
		strncpy(szVersion, pszStart, (size_t)(pszEnd - pszStart));
		szVersion[pszEnd - pszStart] = '\0';
		ULONG ulVersion = strtoul(szVersion, NULL, 10);
		if(ulVersion == ULONG_MAX || ulVersion < 3518)
		{
			odtLog << "ERROR:  This version of the Privlib requires a INI File generated from " << ENDL;
			odtLog << "ERROR:  from TableDump.exe 1.50.3518.00 or later." << ENDL;
			return FALSE;
		}
	}
	else
	{
		odtLog << "ERROR:  Unable to find Versioning Information in INI <File:" << m_pszFileName << ">" << ENDL;
		odtLog << "ERROR:  This version of the Privlib requires a INI with a version section" << ENDL;
		odtLog << "ERROR:  and generated using a version of TableDump.exe 1.50.3518.00 or later." << ENDL;
		return FALSE;
	}

	//Get the NextLine {(TABLE=; DEFAULTQUERY=; DATASOURCE=; USERID=; PASSWORD=; etc... )}
	if(GetNextLine(m_pvInput, MAX_INPUT_BUFFER)!=S_OK ||
		(pszStart = strstr(m_pvInput, START_OF_TYPE))==NULL ||
		(pszStart = strstr(pszStart, "TABLE="))==NULL)
	{
		odtLog << "ERROR:  Unable to find InitString containing Initialization Information in INI <File:" << m_pszFileName << ">" << ENDL;
		odtLog << "ERROR:  Make sure your using a correctly generated INI File from TableDump.exe" << ENDL;
		return FALSE;
	}
    
	//We just need to append the InitString from the FILE to the InitString 
	//Already stored in the CModInfo from LTM.  And we will parse both together...
	GetModInfo()->AddToInitString(pszStart);
	return  TRUE;
}
示例#7
0
文件: main.c 项目: Smilex/OpenHydorah
int main(int argc, char* argv[])
{
	if (Initialize(600, 480, argv) != 0)
	{
		return 1;
	}
	SDL_SetRenderDrawBlendMode(g_renderer, SDL_BLENDMODE_ADD);

	ModInfo* info = GetModInfo("mods/libhydorah.so");
	if (info == NULL)
		return 1;

	printf("Found mod:\n\t%s - %s\n", info->name, info->description);

	Mod* mod = CreateMod(info);

	TextureList* textures = NULL;

	Map* map = CreateMapFromFile("maps/test.map", &textures);
	Editor* editor = CreateEditor(map);

	int running = 1;
	while (running)
	{
		SDL_Event event;
		while (SDL_PollEvent(&event))
		{
			if (event.type == SDL_QUIT)
				running = 0;
			
			HandleEditorEvents(editor, &event);
		}

		SDL_RenderClear(g_renderer);

		DrawMap(map, g_renderer);

		DrawEditor(editor, g_renderer);

		SDL_RenderPresent(g_renderer);
	}

	DestroyMap(map);
	DestroyTextureList(textures);
	DestroyEditor(editor);
	DestroyMod(mod);

	Cleanup(g_window, g_renderer);

	return 0;
}
示例#8
0
CModInfoPtr CMissionManager::GetCurrentModInfo()
{
	idStr gameBase = cvarSystem->GetCVarString("fs_mod");

	// We only have a mod if fs_mod is set correctly, otherwise we're in "darkmod".
	idStr curMission = (!gameBase.IsEmpty()) ? cvarSystem->GetCVarString("fs_currentfm") : "";

	if (curMission.IsEmpty() || curMission == BASE_TDM) 
	{
		// return NULL when no mission is installed or "darkmod"
		return CModInfoPtr();
	}

	return GetModInfo(curMission);
}
示例#9
0
void CMissionManager::CleanupModFolder(const idStr& name)
{
	CModInfoPtr info = GetModInfo(name);

	if (info == NULL)
	{
		DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Cannot erase mission folder for mod %s, mission info not found\r", name.c_str());
		return;
	}

	// Delete folder contents
	fs::path modPath = info->GetModFolderPath().c_str();

	if (fs::exists(modPath))
	{
		// Iterate over all files in the mod folder
		for (fs::directory_iterator i(modPath); i != fs::directory_iterator(); ++i)
		{
			if (boost::algorithm::to_lower_copy(fs::extension(*i)) == ".pk4")
			{
				DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Won't erase PK4 files %s\r", i->path().string().c_str());
				continue;
			}

			if (i->path().filename() == cv_tdm_fm_desc_file.GetString() || 
				i->path().filename() == cv_tdm_fm_notes_file.GetString() || 
				i->path().filename() == cv_tdm_fm_splashimage_file.GetString())
			{
				DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Won't erase meta data file %s\r", i->path().string().c_str());
				continue;
			}

			DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Will erase recursively: %s\r", i->path().string().c_str());
			fs::remove_all(*i);
		}
	}
	else
	{
		DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Cannot erase mod folder %s, directory not found\r", modPath.string().c_str());
		return;
	}

	info->ClearModFolderSize();
}
示例#10
0
void CMissionManager::RefreshMetaDataForNewFoundMods()
{
	// greebo: If we have new found mods, refresh the meta data of the corresponding MissionDB entries
	// otherwise we end up with empty display names after downloading a mod we had on the HDD before
	for (int i = 0; i < _newFoundMods.Num(); ++i)
	{
		CModInfoPtr info = GetModInfo(_newFoundMods[i]);

		if (info != NULL) 
		{
			if (info->LoadMetaData())
			{
				DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Successfully read meta data for newly found mod %s\r", _newFoundMods[i].c_str());
			}
			else
			{
				DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Could not read meta data for newly found mod %s\r", _newFoundMods[i].c_str());
			}
		}
	}
}
//---------------------------------------------------------------------------
// The routine creates a Data Source object with ITransactionDispenser interface,
// initialize it and create a table.
//
// @mfunc Init
//
// @rdesc Success or Failure
//
//---------------------------------------------------------------------------
BOOL CTransaction::Init(CTestCases * pTestCase, CTable * pCTable)
{
	BOOL				fInitSuccess		= FALSE;
	IDBInitialize *		pIDBInitialize		= NULL;
	IDBProperties *		pIDBProperties		= NULL;
	ULONG 				cPropertySets		= 0;
	DBPROPSET *			rgPropertySets		= NULL;

	if (!pTestCase)
	{
		if (!CTestCases::Init())
			return FALSE;
   
		//Skip Transactions if using CONF_STRICT
		if(!IsUsableInterface(SESSION_INTERFACE, IID_ITransactionLocal))
			return FALSE;
			
		// Get IDBInitialize Pointer
		if(!CHECK(GetModInfo()->CreateProvider(NULL, IID_IDBInitialize, (IUnknown**)&pIDBInitialize), S_OK))
			return FALSE;

		// Get the Initialize parameters from LTM for this provider
		if(!GetInitProps(&cPropertySets, &rgPropertySets))
			goto END;

		// Get IDBProperties Pointer
		if(!VerifyInterface(pIDBInitialize, IID_IDBProperties, DATASOURCE_INTERFACE, (IUnknown**)&pIDBProperties))
			goto END;

		// Set the properties before we Initialize
		if (!CHECK(pIDBProperties->SetProperties(cPropertySets,rgPropertySets), S_OK))
			goto END;

		// Initialize and Check to see if the Initialize FAILED
		if(!CHECK(m_hr = pIDBInitialize->Initialize(),S_OK))
			goto END;

		// Get IDBCreateSession Pointer
		if(!VerifyInterface(pIDBInitialize, IID_IDBCreateSession, DATASOURCE_INTERFACE, (IUnknown**)&m_pIDBCreateSession))
			goto END;

		// Create a DB Session object, asking for ITransactionLocal pointer
		if(FAILED(m_hr=m_pIDBCreateSession->CreateSession(NULL, IID_ITransactionLocal, (IUnknown**)&m_pITransactionLocal)))
		{
			// m_pITransactionDispenser should be NULL
			assert(!m_pITransactionLocal);
			CHECK(m_hr, E_NOINTERFACE);
			odtLog<<wszTransactionNotSupported;
			goto END;
		}

		//IOpenRowset
		if(!VerifyInterface(m_pITransactionLocal, IID_IOpenRowset, SESSION_INTERFACE, (IUnknown**)&m_pIOpenRowset))
			 goto END;

		//IDBCreateCommand (optional)
		if(VerifyInterface(m_pITransactionLocal, IID_IDBCreateCommand, SESSION_INTERFACE, (IUnknown**)&m_pIDBCreateCommand))
		{
			//Create a ICommandProperties Object
			if(!CHECK(m_pIDBCreateCommand->CreateCommand(NULL, IID_ICommand, (IUnknown **)&m_pICommand), S_OK))
				goto END;
		}

		// Create a Table
		if (!(m_pCTable = new CTable(m_pIOpenRowset, m_pwszTestCaseName, USENULLS)))
			goto END;

		// Insert 30 rows into the table
		if (!CHECK(m_pCTable->CreateTable(TRANSACTION_ROW_COUNT,1,NULL,PRIMARY,TRUE),S_OK))
			 goto END;
	}
	else
	{
		m_fInTestCase = TRUE;

		//Skip Transactions if using CONF_STRICT
		if(!IsUsableInterface(SESSION_INTERFACE, IID_ITransactionLocal))
			return FALSE;

		// Get IDBCreateSession Pointer
		if (!m_pIDBCreateSession)
			m_pIDBCreateSession = (IDBCreateSession *)pTestCase->m_pThisTestModule->m_pIUnknown;

		if (!COMPARE(m_pIDBCreateSession != NULL, TRUE))
			goto END;

		//ITransactionLocal
		if (!m_pITransactionLocal && !VerifyInterface(pTestCase->m_pThisTestModule->m_pIUnknown2,
			IID_ITransactionLocal, SESSION_INTERFACE, (IUnknown**)&m_pITransactionLocal))
		{
			// m_pITransaction should be NULL
			assert(!m_pITransactionLocal);
			CHECK(m_hr, E_NOINTERFACE);
			odtLog<<wszTransactionNotSupported;
			goto END;
		}

		//IOpenRowset
		if(!m_pIOpenRowset && !VerifyInterface(m_pITransactionLocal, IID_IOpenRowset, SESSION_INTERFACE, (IUnknown**)&m_pIOpenRowset))
			 goto END;

		//IDBCreateCommand (optional)
		if(!m_pIDBCreateCommand && VerifyInterface(m_pITransactionLocal, IID_IDBCreateCommand, SESSION_INTERFACE, (IUnknown**)&m_pIDBCreateCommand))
		{
			//Create a ICommandProperties Object
			if(!m_pICommand && !CHECK(m_pIDBCreateCommand->CreateCommand(NULL, IID_ICommand, (IUnknown **)&m_pICommand), S_OK))
				goto END;
		}

		//Get the table
		if (!COMPARE(pCTable != NULL, TRUE))
			goto END;

		m_pCTable = pCTable;
			
	}

	fInitSuccess = TRUE;

END:

	SAFE_RELEASE(pIDBInitialize);
	SAFE_RELEASE(pIDBProperties);
	FreeProperties(&cPropertySets,&rgPropertySets);
	return fInitSuccess;
}