From 58d7dc14833bd9ee4b7a53ae851bb7c063779ba3 Mon Sep 17 00:00:00 2001 From: BennyR Date: Thu, 14 Aug 2014 15:03:06 +0200 Subject: [PATCH] Print the expiration date of the license. --- cerevoice_tts/src/CerevoiceTts.cpp | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cerevoice_tts/src/CerevoiceTts.cpp b/cerevoice_tts/src/CerevoiceTts.cpp index d4041a3..1191e9c 100644 --- a/cerevoice_tts/src/CerevoiceTts.cpp +++ b/cerevoice_tts/src/CerevoiceTts.cpp @@ -34,6 +34,13 @@ * Author: Benjamin Reiner (reineben@hs-weingarten.de) *********************************************************************/ +#include +#include +#include + +#include +#include + #include "ros/ros.h" #include "XmlRpcException.h" #include "XmlRpcValue.h" @@ -130,6 +137,42 @@ bool CerevoiceTts::init() return false; } + // search for license expiration date and print it if there's one + std::ifstream license_file(license.c_str()); + std::string line; + if(license_file.is_open()) + { + while(getline(license_file, line)) + { + if(boost::algorithm::starts_with(line, "EXP=")) + { + line = line.substr(std::string("EXP=").length()); // cut this string away + int year = boost::lexical_cast(line.substr(0, 4)); + int month = boost::lexical_cast(line.substr(4, 2)); + int day = boost::lexical_cast(line.substr(6, 2)); + + struct std::tm expires = {0, 0, 0, day, month, year - 1900}; + std::time_t now = time(0); + std::time_t expires_time = std::mktime(&expires); + + int difference = static_cast(std::difftime(expires_time, now) / (60 * 60 * 24)); + + if(difference < 50) + ROS_WARN("Your license expires in %d days on %d/%02d/%02d", difference, year, month, day); + else if(difference < 21) + ROS_ERROR("Your license expires in %d days on %d/%02d/%02d. Go buy a new one!", difference, year, month, day); + else + ROS_INFO("Your license expires in %d days on %d/%02d/%02d", difference, year, month, day); + } + } + + license_file.close(); + } + else + { + ROS_WARN("Can't open license file '%s", license.c_str()); + } + // load this voice success = CPRCEN_engine_load_voice(engine_, license.c_str(), NULL, path.c_str(), CPRC_VOICE_LOAD); if(!success)