aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsdcb <sdflysha@qq.com>2016-10-20 13:03:58 +0800
committersdcb <sdflysha@qq.com>2016-10-20 13:03:58 +0800
commit2b8bdeb0441c9fb83fc79bf10a761d1bf11cd287 (patch)
treebf2c24d11941d43b32ddd0f2c06dca7f34d7adf2
parentcb0d924ec3fcc4fa6ee7db75a522c697ee5035e1 (diff)
downloadvcpkg-2b8bdeb0441c9fb83fc79bf10a761d1bf11cd287.tar.gz
vcpkg-2b8bdeb0441c9fb83fc79bf10a761d1bf11cd287.zip
Add hash file support.
-rw-r--r--toolsrc/include/vcpkg_Commands.h1
-rw-r--r--toolsrc/src/commands_hash.cpp40
-rw-r--r--toolsrc/src/commands_other.cpp4
-rw-r--r--toolsrc/vcpkg/commands_hash.cpp40
-rw-r--r--toolsrc/vcpkg/vcpkg.vcxproj1
-rw-r--r--toolsrc/vcpkg/vcpkg.vcxproj.filters3
6 files changed, 88 insertions, 1 deletions
diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h
index 978519820..dc4699dc0 100644
--- a/toolsrc/include/vcpkg_Commands.h
+++ b/toolsrc/include/vcpkg_Commands.h
@@ -35,6 +35,7 @@ namespace vcpkg
void version_command(const vcpkg_cmd_arguments& args);
void contact_command(const vcpkg_cmd_arguments& args);
+ void hash_command(const vcpkg_cmd_arguments& args);
using command_type_a = void(*)(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
using command_type_b = void(*)(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);
diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp
new file mode 100644
index 000000000..672e24a24
--- /dev/null
+++ b/toolsrc/src/commands_hash.cpp
@@ -0,0 +1,40 @@
+#include "vcpkg_Commands.h"
+#include "vcpkg_System.h"
+#include "vcpkg.h"
+#include <iostream>
+#include <iomanip>
+#include <Windows.h>
+
+namespace fs = std::tr2::sys;
+
+namespace vcpkg
+{
+ void file_hash_sha512(fs::path const & path, char const * hash)
+ {
+ auto cmd_line = Strings::format("Powershell -Command (Get-FileHash %s -Algorithm %s).Hash.ToLower()",
+ Strings::utf16_to_utf8(path.c_str()),
+ hash);
+ auto ec_data = System::cmd_execute_and_capture_output(Strings::utf8_to_utf16(cmd_line));
+ Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line);
+ System::print(ec_data.output.c_str());
+ }
+
+ void hash_command(const vcpkg_cmd_arguments& args)
+ {
+ static const std::string example = Strings::format(
+ "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2"));
+ args.check_min_arg_count(1, example.c_str());
+ args.check_max_arg_count(2, example.c_str());
+
+ if (args.command_arguments.size() == 1)
+ {
+ file_hash_sha512(args.command_arguments[0], "SHA512");
+ }
+ if (args.command_arguments.size() == 2)
+ {
+ file_hash_sha512(args.command_arguments[0], args.command_arguments[1].c_str());
+ }
+
+ exit(EXIT_SUCCESS);
+ }
+}
diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp
index 07549a437..53d6f2506 100644
--- a/toolsrc/src/commands_other.cpp
+++ b/toolsrc/src/commands_other.cpp
@@ -14,6 +14,7 @@ namespace vcpkg
" vcpkg remove --purge <pkg> Uninstall and delete a package. \n"
" vcpkg list List installed packages\n"
" vcpkg update Display list of packages for updating\n"
+ " vcpkg hash <file> [alg] Hash a file by specific algorithm, default SHA512\n"
"\n"
"%s" // Integration help
"\n"
@@ -93,7 +94,8 @@ namespace vcpkg
{
static std::vector<package_name_and_function<command_type_c>> t = {
{"version", &version_command},
- {"contact", &contact_command}
+ {"contact", &contact_command},
+ {"hash", &hash_command },
};
return t;
}
diff --git a/toolsrc/vcpkg/commands_hash.cpp b/toolsrc/vcpkg/commands_hash.cpp
new file mode 100644
index 000000000..e4e0e1747
--- /dev/null
+++ b/toolsrc/vcpkg/commands_hash.cpp
@@ -0,0 +1,40 @@
+#include "vcpkg_Commands.h"
+#include "vcpkg_System.h"
+#include "vcpkg.h"
+#include <iostream>
+#include <iomanip>
+#include <Windows.h>
+
+namespace fs = std::tr2::sys;
+
+namespace vcpkg
+{
+ void file_hash_sha512(fs::path const & path, char const * hash)
+ {
+ auto cmd_line = Strings::format("Powershell -Command (Get-FileHash %s -Algorithm %s).Hash.ToLower()",
+ Strings::utf16_to_utf8(path.c_str()),
+ hash);
+ auto ec_data = System::cmd_execute_and_capture_output(Strings::utf8_to_utf16(cmd_line));
+ Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line);
+ System::print(ec_data.output.c_str());
+ }
+
+ void hash_command(const vcpkg_cmd_arguments& args)
+ {
+ static const std::string example = Strings::format(
+ "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2 "));
+ args.check_min_arg_count(1, example.c_str());
+ args.check_max_arg_count(2, example.c_str());
+
+ if (args.command_arguments.size() == 1)
+ {
+ file_hash_sha512(args.command_arguments[0], "SHA512");
+ }
+ if (args.command_arguments.size() == 2)
+ {
+ file_hash_sha512(args.command_arguments[0], args.command_arguments[1].c_str());
+ }
+
+ exit(EXIT_SUCCESS);
+ }
+}
diff --git a/toolsrc/vcpkg/vcpkg.vcxproj b/toolsrc/vcpkg/vcpkg.vcxproj
index 82d3e2163..ec877d09c 100644
--- a/toolsrc/vcpkg/vcpkg.vcxproj
+++ b/toolsrc/vcpkg/vcpkg.vcxproj
@@ -133,6 +133,7 @@
<ClCompile Include="..\src\commands_cache.cpp" />
<ClCompile Include="..\src\commands_create.cpp" />
<ClCompile Include="..\src\commands_edit.cpp" />
+ <ClCompile Include="..\src\commands_hash.cpp" />
<ClCompile Include="..\src\commands_import.cpp" />
<ClCompile Include="..\src\commands_list.cpp" />
<ClCompile Include="..\src\commands_owns.cpp" />
diff --git a/toolsrc/vcpkg/vcpkg.vcxproj.filters b/toolsrc/vcpkg/vcpkg.vcxproj.filters
index 96a11162f..e46652d90 100644
--- a/toolsrc/vcpkg/vcpkg.vcxproj.filters
+++ b/toolsrc/vcpkg/vcpkg.vcxproj.filters
@@ -78,6 +78,9 @@
<ClCompile Include="..\MachineType.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\src\commands_hash.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\post_build_lint.h">