Пример #1
0
CString TitanicEngine::getSavegameName(int slot) {
	// Try and open up the savegame for access
	Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(
		generateSaveName(slot));

	if (in) {
		// Read in the savegame header data
		CompressedFile file;
		file.open(in);

		TitanicSavegameHeader header;
		bool isValid = CProjectItem::readSavegameHeader(&file, header);
		if (header._thumbnail) {
			header._thumbnail->free();
			delete header._thumbnail;
		}

		file.close();

		if (isValid)
			// Set the name text
			return header._saveName;
	}

	return CString();
}
Пример #2
0
void CPetLoadSave::resetSlots() {
	for (int idx = 0; idx < SAVEGAME_SLOTS_COUNT; ++idx) {
		_slotNames[idx].setText(EMPTY);
		_slotInUse[idx] = false;

		// Try and open up the savegame for access
		Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(
			g_vm->generateSaveName(idx));

		if (in) {
			// Read in the savegame header data
			CompressedFile file;
			file.open(in);

			TitanicSavegameHeader header;
			if (CProjectItem::readSavegameHeader(&file, header)) {
				_slotInUse[idx] = true;
				_slotNames[idx].setText(header._saveName);
			}

			if (header._thumbnail) {
				header._thumbnail->free();
				delete header._thumbnail;
			}

			file.close();
		}
	}

	highlightSlot(_savegameSlotNum);
}
Пример #3
0
CompressionTest::CompressionTest(const std::string& testFile, CompressionTypes type)
{
    ifstream in;
    in.open(testFile, ios::binary);
    std::vector<char> inBuf;
    in.seekg(0, ios::end);
    size_t inSize = static_cast<size_t>(in.tellg());
    inBuf.resize(inSize);
    in.seekg(0, ios::beg);
    in.read(&inBuf[0], static_cast<streamsize>(inSize));
    in.close();

    CompressedFile outCompress;
    outCompress.open(testFile + ".compressed", ios::out | ios::binary, type);
    outCompress.write(&inBuf[0], static_cast<streamsize>(inSize));
    outCompress.close();

    CompressedFile inCompress;
    inCompress.open(testFile + ".compressed", ios::in | ios::binary);
    std::vector<char> resInBuf;
    inCompress.seekg(0, ios::end);
    size_t inCompressSize = inCompress.tellg();
    inCompress.seekg(0, ios::beg);
    resInBuf.resize(inCompressSize);
    inCompress.read(&resInBuf[0], static_cast<streamsize>(inCompressSize));
    inCompress.close();

    ofstream out;
    out.open(testFile + ".result", ios::binary);
    out.write(&resInBuf[0], static_cast<streamsize>(inCompressSize));
    out.close();

    // is the original file the same size as the resulting file
    ASSERT(inSize == inCompressSize);

    // is the content identical
    for (size_t i = 0; i < inSize; ++i)
    {
        ASSERT(inBuf[i] == resInBuf[i]);
    }
}
Пример #4
0
 MeshVersion getMeshVersion(const std::string& filename)
 {
     CompressedFile file;
     file.open(filename, ios::in | ios::binary);
     if (file.is_open())
     {
         MeshVersion version;
         file.read(reinterpret_cast<char*>(&version), sizeof(MeshVersion));
         file.close();
         return version;
     }
     return MeshVersion{};
 }
Пример #5
0
    void Mesh::saveToMemory(std::vector<char>& mem)
    {
        CompressedFile file;
        file.open(mem, ios::out | ios::binary);
        if (file.is_open())
        {
            file.write(reinterpret_cast<const char*>(&SupportedMeshVersion), sizeof(MeshVersion));
            for (const auto& mesh : m_subMeshes)
            {
                mesh.save(file);
            }

            file.close();
        }
    }
Пример #6
0
void CProjectItem::loadGame(int slotId) {
    CompressedFile file;

    // Clear any existing project contents and call preload code
    preLoad();
    clear();

    // Open either an existing savegame slot or the new game template
    if (slotId >= 0) {
        Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(
                                           g_vm->generateSaveName(slotId));
        file.open(saveFile);
    } else {
        Common::File *newFile = new Common::File();
        if (!newFile->open("newgame.st"))
            error("Could not open newgame.st");
        file.open(newFile);
    }

    // Load the savegame header in
    TitanicSavegameHeader header;
    readSavegameHeader(&file, header);
    delete header._thumbnail;

    // Load the contents in
    CProjectItem *newProject = loadData(&file);
    file.IsClassStart();
    getGameManager()->load(&file);

    file.close();

    // Clear existing project
    clear();

    // Detach each item under the loaded project, and re-attach them
    // to the existing project instance (this)
    CTreeItem *item;
    while ((item = newProject->getFirstChild()) != nullptr) {
        item->detach();
        item->addUnder(this);
    }

    // Loaded project instance is no longer needed
    newProject->destroyAll();

    // Post-load processing
    postLoad();
}
Пример #7
0
    void Mesh::load(ModelResources& modelResources)
    {
        CompressedFile file;
        file.open(m_filename, ios::in | ios::binary);
        if (file.is_open())
        {
            MeshVersion version;
            file.read(reinterpret_cast<char*>(&version), sizeof(MeshVersion));

            while (!file.eof())
            {
                m_subMeshes.emplace_back(SubMesh());
                if (!m_subMeshes.back().load(modelResources, file))
                {
                    m_subMeshes.pop_back();
                }
            }

            file.close();
        }
    }
Пример #8
0
void CProjectItem::saveGame(int slotId, const CString &desc) {
    CompressedFile file;
    Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(
                                        g_vm->generateSaveName(slotId), false);
    file.open(saveFile);

    // Signal the game is being saved
    preSave();

    // Write out the savegame header
    TitanicSavegameHeader header;
    header._saveName = desc;
    writeSavegameHeader(&file, header);

    // Save the contents out
    saveData(&file, this);

    // Save the game manager data
    _gameManager->save(&file);

    // Close the file and signal that the saving has finished
    file.close();
    postSave();
}