Ejemplo n.º 1
0
bool ReadModListFromSaveGame(const char* path)
{
	_MESSAGE("Reading mod list from savegame");

	IFileStream savefile;
	if (!savefile.Open(path)) {
		_MESSAGE("Couldn't open .ess file when attempting to read plugin list");
		return false;
	}
	else {
		static const UInt32 kSaveHeaderSizeOffset = 34;
		savefile.SetOffset(kSaveHeaderSizeOffset);
		UInt32 headerSize = savefile.Read32();
		savefile.SetOffset(headerSize + kSaveHeaderSizeOffset + sizeof(UInt32));

		s_numPreloadMods = savefile.Read8();
		char pluginName[0x100];
		for (UInt32 i = 0; i < s_numPreloadMods; i++) {
			UInt8 nameLen = savefile.Read8();
			savefile.ReadBuf(pluginName, nameLen);
			pluginName[nameLen] = 0;
			_MESSAGE("Save file contains plugin %s", pluginName);
			s_preloadModRefIDs[i] = (*g_dataHandler)->GetModIndex(pluginName);
		}

		savefile.Close();
	}

	return true;
}
bool LoadJsonFromFile(const char * filePath, Json::Value &jsonData)
{
	IFileStream		currentFile;
	if (!currentFile.Open(filePath))
	{
		_ERROR("%s: couldn't open file (%s) Error (%d)", __FUNCTION__, filePath, GetLastError());
		return true;
	}

	char buf[512];

	std::string jsonString;
	while (!currentFile.HitEOF()){
		currentFile.ReadString(buf, sizeof(buf) / sizeof(buf[0]));
		jsonString.append(buf);
	}
	currentFile.Close();
	
	Json::Features features;
	features.all();

	Json::Reader reader(features);

	bool parseSuccess = reader.parse(jsonString, jsonData);
	if (!parseSuccess) {
		_ERROR("%s: Error occured parsing json for %s.", __FUNCTION__, filePath);
		return true;
	}
	return false;
}
bool WriteDisplayData(Json::Value jDisplayList)
{
	Json::StyledWriter writer;
	std::string jsonString = writer.write(jDisplayList);
	
	if (!jsonString.length()) {
		return true;
	}

	char filePath[MAX_PATH];
	sprintf_s(filePath, "%s/DBM_MuseumData.json", GetUserDirectory().c_str());

	IFileStream	currentFile;
	IFileStream::MakeAllDirs(filePath);
	if (!currentFile.Create(filePath))
	{
		_ERROR("%s: couldn't create preset file (%s) Error (%d)", __FUNCTION__, filePath, GetLastError());
		return true;
	}

	currentFile.WriteBuf(jsonString.c_str(), jsonString.length());
	currentFile.Close();

	return false;
}
Ejemplo n.º 4
0
	void ImportTranslationFiles(BSScaleformTranslator * translator)
	{
		char	appdataPath[MAX_PATH];
		ASSERT(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdataPath)));

		std::string	modlistPath = appdataPath;
		modlistPath += "\\Skyrim Special Edition\\plugins.txt";

		// Parse mod list file to acquire translation filenames
		IFileStream modlistFile;
		if(modlistFile.Open(modlistPath.c_str()))
		{
			while(!modlistFile.HitEOF())
			{
				char buf[512];
				modlistFile.ReadString(buf, 512, '\n', '\r');

				// skip comments
				if(buf[0] == '#')
					continue;				

				// Determine extension type
				std::string line = buf;

				// SE: added this
				if (line.length() > 0)
				{
					if (line.front() != '*')
						continue; // Skip not enabled files

					line = line.substr(1); // Remove the * from name
				}					

				std::string::size_type lastDelim = line.rfind('.');
				if(lastDelim != std::string::npos)
				{
					std::string ext = line.substr(lastDelim);

					if(_stricmp(ext.c_str(), ".ESM") == 0 || _stricmp(ext.c_str(),".ESP") == 0)
					{
						std::string name = line.substr(0, lastDelim);
						ParseTranslation(translator, name);
					}
				}
			}
		}

		modlistFile.Close();
	}