bool gui_settings::unserialize(tools::binary_stream& _bs) { if (!_bs.available()) { return false; } tools::tlvpack pack; if (!pack.unserialize(_bs)) return false; for (auto tlv_val = pack.get_first(); tlv_val; tlv_val = pack.get_next()) { tools::binary_stream val_data = tlv_val->get_value<tools::binary_stream>(); tools::tlvpack pack_val; if (!pack_val.unserialize(val_data)) return false; auto tlv_name = pack_val.get_item(gui_settings_types::gst_name); auto tlv_value_data = pack_val.get_item(gui_settings_types::gst_value); if (!tlv_name || !tlv_value_data) { assert(false); return false; } values_[tlv_name->get_value<std::string>()] = tlv_value_data->get_value<tools::binary_stream>(); } return true; }
int32_t run_installer(const tools::binary_stream& _data) { #ifdef _WIN32 wchar_t temp_path[1024]; if (!::GetTempPath(1024, temp_path)) return -1; wchar_t temp_file_name[1024]; if (!::GetTempFileName(temp_path, L"icqsetup", 0, temp_file_name)) return -1; _data.save_2_file(temp_file_name); PROCESS_INFORMATION pi = {0}; STARTUPINFO si = {0}; si.cb = sizeof(si); wchar_t command[1024]; swprintf_s(command, 1023, L"\"%s\" -update", temp_file_name); if (!::CreateProcess(0, command, 0, 0, 0, 0, 0, 0, &si, &pi)) return -1; ::CloseHandle( pi.hProcess ); ::CloseHandle( pi.hThread ); #endif //_WIN32 return 0; }
bool hosts_map::parse(tools::binary_stream& _bs) { if (!_bs.available()) { return false; } rapidjson::Document doc; if (doc.ParseInsitu(_bs.read_available()).HasParseError()) { return false; } for (auto iter = doc.MemberBegin(), end = doc.MemberEnd(); iter != end; ++iter) { if (!iter->value.IsString() || !iter->name.IsString()) continue; hosts_[rapidjson_get_string(iter->name)] = tools::trim_right<std::string>(rapidjson_get_string(iter->value), std::string(" ")); } return true; }
bool statistics::unserialize(tools::binary_stream& _bs) { if (!_bs.available()) { assert(false); return false; } tools::tlvpack pack; if (!pack.unserialize(_bs)) return false; int counter = 0; for (auto tlv_val = pack.get_first(); tlv_val; tlv_val = pack.get_next()) { tools::binary_stream val_data = tlv_val->get_value<tools::binary_stream>(); tools::tlvpack pack_val; if (!pack_val.unserialize(val_data)) return false; if (counter++ == 0) { auto tlv_last_sent_time = pack_val.get_item(statistics_info_types::last_sent_time); if (!tlv_last_sent_time) { assert(false); return false; } time_t last_time = tlv_last_sent_time->get_value<int64_t>(); last_sent_time_ = std::chrono::system_clock::from_time_t(last_time); } else { auto curr_event_name = pack_val.get_item(statistics_info_types::event_name); if (!curr_event_name) { assert(false); return false; } stats_event_names name = curr_event_name->get_value<stats_event_names>(); auto tlv_event_time = pack_val.get_item(statistics_info_types::event_time); auto tlv_event_id = pack_val.get_item(statistics_info_types::event_id); if (!tlv_event_time || !tlv_event_id) { assert(false); return false; } event_props_type props; const auto tlv_prop_pack = pack_val.get_item(statistics_info_types::event_props); assert(tlv_prop_pack); if (tlv_prop_pack) { auto prop_pack = tlv_prop_pack->get_value<tools::tlvpack>(); if (!unserialize_props(prop_pack, &props)) { assert(false); return false; } } auto read_event_time = std::chrono::system_clock::from_time_t(tlv_event_time->get_value<int64_t>()); auto read_event_id = tlv_event_id->get_value<int64_t>(); insert_event(name, props, read_event_time, read_event_id); } } return true; }