FreeScriptの練習2
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <filesystem>
#include <windows.h>
#include <winhttp.h>
#include <typeinfo>
#\<span style="font-weight: 900 !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.