-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print the expiration date of the license.
- Loading branch information
BennyR
committed
Aug 14, 2014
1 parent
c9ab5f7
commit 58d7dc1
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,13 @@ | |
* Author: Benjamin Reiner ([email protected]) | ||
*********************************************************************/ | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <ctime> | ||
|
||
#include <boost/algorithm/string/predicate.hpp> | ||
#include <boost/lexical_cast.hpp> | ||
|
||
#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<int>(line.substr(0, 4)); | ||
int month = boost::lexical_cast<int>(line.substr(4, 2)); | ||
int day = boost::lexical_cast<int>(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<int>(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) | ||
|