2
0
Эх сурвалжийг харах

- fixed several cases of accessing full path to files in archives

Ivan Savenko 12 жил өмнө
parent
commit
77496bcea9

+ 2 - 5
client/CBitmapHandler.cpp

@@ -130,13 +130,10 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
 	}
 	else
 	{ //loading via SDL_Image
-		CFileInfo info(*CResourceHandler::get()->getResourceName(ResourceID(path + fname, EResType::IMAGE)));
-
-		ret = IMG_LoadTyped_RW(
+		ret = IMG_Load_RW(
 		          //create SDL_RW with our data (will be deleted by SDL)
 		          SDL_RWFromConstMem((void*)readFile.first.get(), readFile.second),
-		          1, // mark it for auto-deleting
-		          &info.getExtension()[0] + 1); //pass extension without dot (+1 character)
+		          1); // mark it for auto-deleting
 		if (ret)
 		{
 			if (ret->format->palette)

+ 2 - 2
client/CMT.cpp

@@ -660,7 +660,7 @@ void processCommand(const std::string &message)
 		{
 			CDefEssential * cde = CDefHandler::giveDefEss(URI);
 
-			std::string outName = *CResourceHandler::get()->getResourceName(ResourceID("SPRITES/" + URI));
+			std::string outName = URI;
 			std::string outPath = VCMIDirs::get().userCachePath() + "/extracted/";
 
 			boost::filesystem::create_directories(outPath + outName);
@@ -681,7 +681,7 @@ void processCommand(const std::string &message)
 
 		if (CResourceHandler::get()->existsResource(ResourceID(URI)))
 		{
-			std::string outName = *CResourceHandler::get()->getResourceName(ResourceID(URI));
+			std::string outName = URI;
 			std::string outPath = VCMIDirs::get().userCachePath() + "/extracted/";
 			std::string fullPath = outPath + outName;
 

+ 8 - 8
client/CVideoHandler.cpp

@@ -412,20 +412,20 @@ bool CVideoPlayer::open(std::string name)
 		// We can handle only videos in form of single file, no archive support yet.
 		{
 			ResourceID videoID = ResourceID("VIDEO/" + name, EResType::VIDEO);
-			std::string realVideoFilename = CResourceHandler::get()->getResourceName(videoID).get();
+			auto data = CResourceHandler::get()->load(videoID)->readAll();
 
-			if(boost::algorithm::iends_with(realVideoFilename, ".BIK"))
+			// try to determine video format using magic number from header (3 bytes, SMK or BIK)
+			std::string magic(reinterpret_cast<char*>(data.first.get()), 3);
+			if (magic == "BIK")
 				current = &bikPlayer;
-			else
+			else if (magic == "SMK")
 				current = &smkPlayer;
-
-			auto myVideo = CResourceHandler::get()->load(videoID);
-			unique_ptr<char[]> data = unique_ptr<char[]>(new char[myVideo->getSize()]);
-			myVideo->read((ui8*)data.get(), myVideo->getSize());
+			else
+				throw std::runtime_error("Unknown video format: " + magic);
 
 			std::ofstream out(name, std::ofstream::binary);
 			out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
-			out.write(data.get(), myVideo->getSize());
+			out.write(data.first.get(), data.second);
 		}
 
 		current->open(name);