file_version_info_win.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_FILE_VERSION_INFO_WIN_H_
  5. #define BASE_FILE_VERSION_INFO_WIN_H_
  6. #include <windows.h>
  7. #include <stdint.h>
  8. #include <memory>
  9. #include <string>
  10. #include <vector>
  11. #include "base/base_export.h"
  12. #include "base/file_version_info.h"
  13. #include "base/memory/raw_ptr.h"
  14. #include "base/version.h"
  15. struct tagVS_FIXEDFILEINFO;
  16. typedef tagVS_FIXEDFILEINFO VS_FIXEDFILEINFO;
  17. class BASE_EXPORT FileVersionInfoWin : public FileVersionInfo {
  18. public:
  19. FileVersionInfoWin(const FileVersionInfoWin&) = delete;
  20. FileVersionInfoWin& operator=(const FileVersionInfoWin&) = delete;
  21. ~FileVersionInfoWin() override;
  22. // Accessors to the different version properties.
  23. // Returns an empty string if the property is not found.
  24. std::u16string company_name() override;
  25. std::u16string company_short_name() override;
  26. std::u16string product_name() override;
  27. std::u16string product_short_name() override;
  28. std::u16string internal_name() override;
  29. std::u16string product_version() override;
  30. std::u16string special_build() override;
  31. std::u16string original_filename() override;
  32. std::u16string file_description() override;
  33. std::u16string file_version() override;
  34. // Lets you access other properties not covered above. |value| is only
  35. // modified if GetValue() returns true.
  36. bool GetValue(const char16_t* name, std::u16string* value) const;
  37. // Similar to GetValue but returns a std::u16string (empty string if the
  38. // property does not exist).
  39. std::u16string GetStringValue(const char16_t* name) const;
  40. // Get file version number in dotted version format.
  41. base::Version GetFileVersion() const;
  42. // Behaves like CreateFileVersionInfo, but returns a FileVersionInfoWin.
  43. static std::unique_ptr<FileVersionInfoWin> CreateFileVersionInfoWin(
  44. const base::FilePath& file_path);
  45. private:
  46. friend FileVersionInfo;
  47. // |data| is a VS_VERSION_INFO resource. |language| and |code_page| are
  48. // extracted from the \VarFileInfo\Translation value of |data|.
  49. FileVersionInfoWin(std::vector<uint8_t>&& data,
  50. WORD language,
  51. WORD code_page);
  52. FileVersionInfoWin(void* data, WORD language, WORD code_page);
  53. const std::vector<uint8_t> owned_data_;
  54. const raw_ptr<const void> data_;
  55. const WORD language_;
  56. const WORD code_page_;
  57. // This is a reference for a portion of |data_|.
  58. const VS_FIXEDFILEINFO& fixed_file_info_;
  59. };
  60. #endif // BASE_FILE_VERSION_INFO_WIN_H_