aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
-rw-r--r--toolsrc/src/vcpkg.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index 6f10c503d..3589881a7 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -33,6 +33,12 @@
using namespace vcpkg;
+// 24 hours/day * 30 days/month * 6 months
+static constexpr int SURVEY_INTERVAL_IN_HOURS = 24 * 30 * 6;
+
+// Initial survey appears after 10 days. Therefore, subtract 24 hours/day * 10 days
+static constexpr int SURVEY_INITIAL_OFFSET_IN_HOURS = SURVEY_INTERVAL_IN_HOURS - 24 * 10;
+
void invalid_command(const std::string& cmd)
{
System::println(System::Color::error, "invalid command: %s", cmd);
@@ -113,19 +119,19 @@ static void inner(const VcpkgCmdArguments& args)
#endif
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed");
- if (args.command != "autocomplete")
+ if (args.command == "install" || args.command == "remove" || args.command == "export" || args.command == "update")
{
Commands::Version::warn_if_vcpkg_version_mismatch(paths);
std::string surveydate = *GlobalState::g_surveydate.lock();
auto maybe_surveydate = Chrono::CTime::parse(surveydate);
if (auto p_surveydate = maybe_surveydate.get())
{
- auto delta = std::chrono::system_clock::now() - p_surveydate->to_time_point();
- // 24 hours/day * 30 days/month
- if (std::chrono::duration_cast<std::chrono::hours>(delta).count() > 24 * 30)
+ const auto now = Chrono::CTime::get_current_date_time().value_or_exit(VCPKG_LINE_INFO);
+ const auto delta = now.to_time_point() - p_surveydate->to_time_point();
+ if (std::chrono::duration_cast<std::chrono::hours>(delta).count() > SURVEY_INTERVAL_IN_HOURS)
{
std::default_random_engine generator(
- static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count()));
+ static_cast<unsigned int>(now.to_time_point().time_since_epoch().count()));
std::uniform_int_distribution<int> distribution(1, 4);
if (distribution(generator) == 1)
@@ -214,7 +220,9 @@ static void load_config()
if (config.last_completed_survey.empty())
{
- config.last_completed_survey = config.user_time;
+ const auto now = Chrono::CTime::parse(config.user_time).value_or_exit(VCPKG_LINE_INFO);
+ const Chrono::CTime offset = now.add_hours(-SURVEY_INITIAL_OFFSET_IN_HOURS);
+ config.last_completed_survey = offset.to_string();
}
GlobalState::g_surveydate.lock()->assign(config.last_completed_survey);
@@ -261,6 +269,7 @@ int main(const int argc, const char* const* const argv)
#if defined(_WIN32)
GlobalState::g_init_console_cp = GetConsoleCP();
GlobalState::g_init_console_output_cp = GetConsoleOutputCP();
+ GlobalState::g_init_console_initialized = true;
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
@@ -275,6 +284,9 @@ int main(const int argc, const char* const* const argv)
locked_metrics->track_property("cmdline", trimmed_command_line);
#endif
}
+
+ Checks::register_console_ctrl_handler();
+
load_config();
const auto vcpkg_feature_flags_env = System::get_environment_variable("VCPKG_FEATURE_FLAGS");
@@ -293,8 +305,6 @@ int main(const int argc, const char* const* const argv)
if (const auto p = args.sendmetrics.get()) Metrics::g_metrics.lock()->set_send_metrics(*p);
if (const auto p = args.debug.get()) GlobalState::debugging = *p;
- Checks::register_console_ctrl_handler();
-
if (GlobalState::debugging)
{
inner(args);