示例#1
0
        //--------------------------------------------------------------
        //--------------------------------------------------------------
		u32 FileSystem::GetFileChecksumCRC32(StorageLocation in_storageLocation, const std::string& in_filePath) const
		{
			u32 output = 0;

			//open the file
			FileStreamUPtr file = CreateFileStream(in_storageLocation, in_filePath, FileMode::k_readBinary);
			if (file != nullptr)
			{
				//get the length of the file
				file->SeekG(0, SeekDir::k_end);
				s32 length = file->TellG();
				file->SeekG(0, SeekDir::k_beginning);

				//read contents of file
				s8* contents = new s8[length];
				file->Read(contents, length);

				//get the hash
				output = HashCRC32::GenerateHashCode(contents, length);
				CS_SAFEDELETE_ARRAY(contents);
			}

			return output;
		}
		//--------------------------------------------------------------
		//--------------------------------------------------------------
        void GooglePlayExpansionSystem::Unzip(const std::string& instrZipPath, Json::Value& outjManifest)
        {
        	CSCore::Application::Get()->GetFileSystem()->CreateDirectoryPath(CSCore::StorageLocation::k_DLC, "");

        	unzFile ZippedFile = unzOpen(instrZipPath.c_str());

        	unz_global_info pInfo;
        	unzGetGlobalInfo(ZippedFile, &pInfo);
        	s32 dwTotalNumEntries = pInfo.number_entry;
        	s32 dwCurrentEntry = 1;

        	if(ZippedFile)
        	{
        		s32 dwStatus = unzGoToFirstFile(ZippedFile);
        		u32 udwBufferSize = 0;
        		s8* pbyDataBuffer = nullptr;

        		//Go to the first file in the zip
        		const u64 uddwFilenameLength = 256;
        		s8 byaFileName[uddwFilenameLength];

        		while(dwStatus == UNZ_OK)
        		{
        			//Open the next file
        			if (unzOpenCurrentFile(ZippedFile) != UNZ_OK)
        				break;

        			//Get file information
        			unz_file_info FileInfo;
        			unzGetCurrentFileInfo(ZippedFile, &FileInfo, byaFileName, uddwFilenameLength, 0, 0, 0, 0);

        			//Load the file into memory and then save it out to the directory
        			if(FileInfo.uncompressed_size > udwBufferSize)
        			{
        				udwBufferSize = FileInfo.uncompressed_size;
        				CS_SAFEDELETE_ARRAY(pbyDataBuffer);
        				pbyDataBuffer = new s8[udwBufferSize];
        			}

        			unzReadCurrentFile(ZippedFile, pbyDataBuffer, FileInfo.uncompressed_size);

					std::string strFilePath = std::string(byaFileName);

					Json::Value jManifestEntry;
					if(ContainsDirectoryPath(strFilePath))
					{
						//There is a nested folder so we need to create the directory structure
						jManifestEntry["IsDirectory"] = true;
						jManifestEntry["Path"] = GetRootFolderExcludingPath(strFilePath);

						std::string strPath = GetPathExcludingFileName(strFilePath);
						CSCore::Application::Get()->GetFileSystem()->CreateDirectoryPath(CSCore::StorageLocation::k_DLC, "/" + strPath);
					}
					else
					{
						//This is just a file
						jManifestEntry["IsDirectory"] = false;
						jManifestEntry["Path"] = GetFileNameExcludingPath(strFilePath);
					}

					if(IsFile(strFilePath))
					{
						CSCore::Application::Get()->GetFileSystem()->WriteFile(CSCore::StorageLocation::k_DLC, "/" + strFilePath, pbyDataBuffer, FileInfo.uncompressed_size);
					}

					outjManifest.append(jManifestEntry);

        			unzCloseCurrentFile(ZippedFile);
        			dwStatus = unzGoToNextFile(ZippedFile);

        			m_installProgress = (f32)dwCurrentEntry / (f32)dwTotalNumEntries;
        			dwCurrentEntry++;
        		}

        		CS_SAFEDELETE_ARRAY(pbyDataBuffer);
        	}
        }