FreeScriptの練習2

提供:yonewiki
2024年12月29日 (日) 01:13時点におけるYo-net (トーク | 投稿記録)による版

FreeScriptの練習1


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <filesystem>
#include <windows.h>
#include <winhttp.h>
#include <typeinfo>
 
#\<span style="color: red !important;"\>include\</span\> <zip.h>
 
#pragma comment(lib, "winhttp.lib")
#pragma comment(lib, "Version.lib")
#pragma comment(lib, "zip.lib")
 
std::string GetVersion(const std::string& path) {
  DWORD handle;
  DWORD size = GetFileVersionInfoSizeA(path.c_str(), &handle);
  if (size == 0) {
    throw std::runtime_error("Failed to get version info size.");
  }
 
  std::vector<char> data(size);
  if (!GetFileVersionInfoA(path.c_str(), handle, size, data.data())) {
    throw std::runtime_error("Failed to get version info.");
  }
 
  VS_FIXEDFILEINFO* versionInfo;
  UINT len;
  if (!VerQueryValueA(data.data(), "\\", (LPVOID*)&versionInfo, &len)) {
    throw std::runtime_error("Failed to query version info.");
  }
 
  DWORD major = (versionInfo->dwFileVersionMS >> 16) & 0xffff;
  DWORD minor = versionInfo->dwFileVersionMS & 0xffff;
  DWORD build = (versionInfo->dwFileVersionLS >> 16) & 0xffff;
  DWORD revision = versionInfo->dwFileVersionLS & 0xffff;
 
  return std::to_string(major) + "." +
    std::to_string(minor) + "." +
    std::to_string(build) + "." +
    std::to_string(revision);
}

test string.