Browse Source

Check DevilutionX version

This is similar to how we handle extra fonts
pull/7341/head
Gleb Mazovetskiy 2 years ago
parent
commit
7d5bef724d
  1. 3
      .editorconfig
  2. 1
      CMake/Assets.cmake
  3. 2
      Source/diablo.cpp
  4. 37
      Source/init.cpp
  5. 13
      Source/init.h
  6. 1
      assets/ASSETS_VERSION

3
.editorconfig

@ -83,3 +83,6 @@ end_of_line = lf
[Dockerfile] [Dockerfile]
end_of_line = lf end_of_line = lf
[ASSETS_VERSION]
end_of_line = lf

1
CMake/Assets.cmake

@ -41,6 +41,7 @@ if (Gettext_FOUND)
endif() endif()
set(devilutionx_assets set(devilutionx_assets
ASSETS_VERSION
arena/church.dun arena/church.dun
arena/circle_of_death.dun arena/circle_of_death.dun
arena/hell.dun arena/hell.dun

2
Source/diablo.cpp

@ -1145,7 +1145,7 @@ void CheckArchivesUpToDate()
#ifdef UNPACKED_MPQS #ifdef UNPACKED_MPQS
const bool devilutionxMpqOutOfDate = false; const bool devilutionxMpqOutOfDate = false;
#else #else
const bool devilutionxMpqOutOfDate = devilutionx_mpq && (!devilutionx_mpq->HasFile("data\\charbg.clx") || devilutionx_mpq->HasFile("fonts\\12-00.bin")); const bool devilutionxMpqOutOfDate = IsDevilutionXMpqOutOfDate();
#endif #endif
const bool fontsMpqOutOfDate = AreExtraFontsOutOfDate(); const bool fontsMpqOutOfDate = AreExtraFontsOutOfDate();

37
Source/init.cpp

@ -77,6 +77,7 @@ std::optional<MpqArchive> font_mpq;
namespace { namespace {
constexpr char DevilutionXMpqVersion[] = "1\n";
constexpr char ExtraFontsVersion[] = "1\n"; constexpr char ExtraFontsVersion[] = "1\n";
#ifdef UNPACKED_MPQS #ifdef UNPACKED_MPQS
@ -174,22 +175,44 @@ std::vector<std::string> GetMPQSearchPaths()
return paths; return paths;
} }
bool CheckExtraFontsVersion(AssetRef &&ref) bool AssetContentsEq(AssetRef &&ref, std::string_view expected)
{ {
const size_t size = ref.size(); const size_t size = ref.size();
AssetHandle handle = OpenAsset(std::move(ref), false); AssetHandle handle = OpenAsset(std::move(ref), false);
if (!handle.ok()) if (!handle.ok()) return false;
return true; std::unique_ptr<char[]> contents { new char[size] };
if (!handle.read(contents.get(), size)) return false;
return std::string_view { contents.get(), size } == expected;
}
std::unique_ptr<char[]> version_contents { new char[size] }; bool CheckDevilutionXMpqVersion(AssetRef &&ref)
if (!handle.read(version_contents.get(), size)) {
return true; return !AssetContentsEq(std::move(ref), DevilutionXMpqVersion);
}
return std::string_view { version_contents.get(), size } != ExtraFontsVersion; bool CheckExtraFontsVersion(AssetRef &&ref)
{
return !AssetContentsEq(std::move(ref), ExtraFontsVersion);
} }
} // namespace } // namespace
#ifndef UNPACKED_MPQS
bool IsDevilutionXMpqOutOfDate(MpqArchive &archive)
{
const char filename[] = "ASSETS_VERSION";
const MpqFileHash fileHash = CalculateMpqFileHash(filename);
uint32_t fileNumber;
if (!archive.GetFileNumber(fileHash, fileNumber))
return true;
AssetRef ref;
ref.archive = &archive;
ref.fileNumber = fileNumber;
ref.filename = filename;
return CheckDevilutionXMpqVersion(std::move(ref));
}
#endif
#ifdef UNPACKED_MPQS #ifdef UNPACKED_MPQS
bool AreExtraFontsOutOfDate(const std::string &path) bool AreExtraFontsOutOfDate(const std::string &path)
{ {

13
Source/init.h

@ -99,6 +99,19 @@ inline bool AreExtraFontsOutOfDate()
#endif #endif
} }
#ifndef UNPACKED_MPQS
bool IsDevilutionXMpqOutOfDate(MpqArchive &archive);
#endif
inline bool IsDevilutionXMpqOutOfDate()
{
#ifdef UNPACKED_MPQS
return false;
#else
return !devilutionx_mpq.has_value() || IsDevilutionXMpqOutOfDate(*devilutionx_mpq);
#endif
}
void init_cleanup(); void init_cleanup();
void LoadCoreArchives(); void LoadCoreArchives();
void LoadLanguageArchive(); void LoadLanguageArchive();

1
assets/ASSETS_VERSION

@ -0,0 +1 @@
1
Loading…
Cancel
Save