Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Check extensions hash #10144

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions addons/common/ACE_ExtensionsHashes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ACE_ExtensionsHashes {
class ace {
dll = "b83c2c9c7c989eaf888c885d13a2fdf4a61d1c5f";
dll_x64 = "356a61c4bd2aa13556a8ba0b467c819b3b438d6c";
};
};
2 changes: 2 additions & 0 deletions addons/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ class ACE_Tests {
mapConfigs = QPATHTOF(dev\test_mapConfigs.sqf);
cfgPatches = QPATHTOF(dev\test_cfgPatches.sqf);
};

#include "ACE_ExtensionsHashes.hpp"
25 changes: 25 additions & 0 deletions addons/common/functions/fnc_checkFiles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ if (_platform in ["linux", "osx"]) then {
};



if (hasInterface && {_platform == "windows"}) then {
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
if (isFilePatchingEnabled) exitWith {};
{
private _extName = configName _x;
private _extensionType = "dll";
if (productVersion select 7 == "x64") then { _extensionType = format ["%1_x64", _extensionType]; };
private _expectedHash = getText (_x >> _extensionType);

private _extensionHash = "";
{
if ((_x getOrDefault ["name", ""]) == _extName) exitWith {
_extensionHash = _x getOrDefault ["hash", ""];
};
} forEach allExtensions;

if (_extensionHash != _expectedHash) then {
private _errorMsg = format ["Extension %1 wrong version [%2 vs %3].", _extName, _extensionHash, _expectedHash];
ERROR(_errorMsg);
["[ACE] ERROR", _errorMsg] call FUNC(errorMessage);
};
} forEach ("true" configClasses (configFile >> "ACE_ExtensionsHashes"));
};


///////////////
// Check server version/addons
///////////////
Expand Down
10 changes: 9 additions & 1 deletion extension/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@ dependencies = ["build_x32_release"]
[tasks.debug]
dependencies = ["move_x32_debug", "move_x64_debug"]

[tasks.release]
[tasks.updateSigs]
script_runner = "python"
script_extension = "py"
script_runner_args = ["../tools/getExtensionHash.py"]
script = '''
'''
dependencies = ["move_x32_release", "move_x64_release"]

[tasks.release]
dependencies = ["updateSigs"]
8 changes: 4 additions & 4 deletions tools/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
"kind": "build",
"isDefault": true
}
}
},
{
"label": "Extension: x64",
"label": "Extension: make move_x64_release",
"command": "cargo",
"options": {
"cwd": "${workspaceFolder}"
Expand All @@ -131,9 +131,9 @@
"group": {
"kind": "build"
}
}
},
{
"label": "Extension: Release",
"label": "Extension: make release",
"command": "cargo",
"options": {
"cwd": "${workspaceFolder}"
Expand Down
36 changes: 36 additions & 0 deletions tools/getExtensionHash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pathlib
import os
import hashlib

addon_base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

extensions = {}

for file in os.listdir(addon_base_path):
path = pathlib.Path(addon_base_path, file)
extension_type = "dll"
if path.suffix == ".dll":
key = path.stem
if key.endswith("_x64"):
key = key.removesuffix("_x64")
extension_type += "_x64"
print(f"looking at {path}")
with open(path, 'rb') as file_read:
sha1 = hashlib.sha1()
data = file_read.read()
sha1.update(data)
arr = extensions.get(key, {})
arr[extension_type] = sha1.hexdigest()
extensions[key] = arr

file_out = pathlib.Path(addon_base_path, "addons", "common", "ACE_ExtensionsHashes.hpp")
with open(file_out, 'w') as file_write:
print(f"class ACE_ExtensionsHashes {{", file=file_write)
for key, values in extensions.items():
print(f" class {key} {{", file=file_write)
for type, hash in values.items():
print(f" {type} = \"{hash}\";", file=file_write)
print(f" }};", file=file_write)
print(f"}};", file=file_write)

print(f"Wrote {len(extensions)} to {file_out}")
Loading