internal.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <cstdint>
  3. #include "../definition.h"
  4. #include "records/domains.h"
  5. namespace sunrise::state::build_data::cache {
  6. /** Result of opening and checking the one build-data cache file. */
  7. enum class LoadStatus {
  8. missing,
  9. loaded,
  10. stale,
  11. invalid,
  12. };
  13. /** Final-name rule for one all-or-nothing cache write. */
  14. enum class WriteDisposition {
  15. createOnly,
  16. replaceStale,
  17. };
  18. /**
  19. * Reads the build identity from this process's executable image.
  20. * @param configuredEquipmentHash Hash of the authored equipment and the score rules.
  21. * @param contentHash Identity of the installed and mod packages the mappings come from.
  22. * @param identity Receives the PE fields and both hashes.
  23. * @return True when the main executable is a valid Windows PE image.
  24. */
  25. [[nodiscard]] bool current_build_identity(std::uint64_t configuredEquipmentHash,
  26. std::uint64_t contentHash,
  27. BuildIdentity& identity) noexcept;
  28. /**
  29. * Loads one exact cache file into fixed caller storage.
  30. * @param path Null-terminated cache path.
  31. * @param expectedBuild Current executable build identity.
  32. * @param output Fixed caller storage for all generated domains.
  33. * @param counts Receives every checked domain count.
  34. * @return Missing, loaded, stale, or invalid. Never leaves partial counts.
  35. */
  36. [[nodiscard]] LoadStatus load(const wchar_t* path,
  37. const BuildIdentity& expectedBuild,
  38. records::MutableDomains output,
  39. records::DomainCounts& counts) noexcept;
  40. /**
  41. * Creates a missing cache, or replaces one marked stale, in one step.
  42. * @param directory Null-terminated cache directory.
  43. * @param path Null-terminated final cache path.
  44. * @param build Current executable build identity.
  45. * @param domains Complete mapping domains.
  46. * @param disposition Create only, or replace a stale cache.
  47. * @return True when the file is on disk under its requested final name.
  48. */
  49. [[nodiscard]] bool write(const wchar_t* directory,
  50. const wchar_t* path,
  51. const BuildIdentity& build,
  52. records::Domains domains,
  53. WriteDisposition disposition) noexcept;
  54. } // namespace sunrise::state::build_data::cache