logic: Added update checker connecting to online API

* connects to https://www.sourcetrail.com/api/v1/versions/latest
* sends information about OS, platform, license type, current version and a unique user token
* Automatic update check is enabled via Startscreen and performed once every 24 hours on window focus
* Update check can be forced by clicking on "check for new version" on start screen
* renamed TimePoint to TimeStamp

fortune cookie message = In Träumen und im Leben ist nichts unmöglich.
This commit is contained in:
Eberhard Graether
2017-08-08 14:18:14 +02:00
parent db1c3b3f40
commit ff65a3f285
67 changed files with 680 additions and 251 deletions
-40
View File
@@ -1,40 +0,0 @@
#ifndef TIME_POINT_H
#define TIME_POINT_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimePoint // that name sounds pretty silly, was time stamp not ok?
{
public:
static TimePoint now();
TimePoint();
TimePoint(boost::posix_time::ptime t);
//TimePoint(time_t t);
TimePoint(std::string s);
bool isValid() const;
std::string toString() const;
std::string getDDMMYYYYString() const;
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
inline bool operator!=(const TimePoint& rhs){ return m_time != rhs.m_time; }
inline bool operator<(const TimePoint& rhs){ return m_time < rhs.m_time; }
inline bool operator>(const TimePoint& rhs){ return m_time > rhs.m_time; }
inline bool operator<=(const TimePoint& rhs){ return m_time <= rhs.m_time; }
inline bool operator>=(const TimePoint& rhs){ return m_time >= rhs.m_time; }
inline float operator-(const TimePoint& rhs){ return deltaMS(rhs) / 1000.0f; }
size_t deltaMS(const TimePoint& other) const;
size_t deltaS(const TimePoint& other) const;
bool isSameDay(const TimePoint& other) const;
size_t deltaDays(const TimePoint& other) const; // days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_POINT_H
@@ -1,26 +1,21 @@
#include "TimePoint.h"
#include "TimeStamp.h"
TimePoint TimePoint::now()
TimeStamp TimeStamp::now()
{
return TimePoint(boost::posix_time::microsec_clock::local_time());
return TimeStamp(boost::posix_time::microsec_clock::local_time());
}
TimePoint::TimePoint()
TimeStamp::TimeStamp()
: m_time(boost::posix_time::not_a_date_time)
{
}
TimePoint::TimePoint(boost::posix_time::ptime t)
TimeStamp::TimeStamp(boost::posix_time::ptime t)
: m_time(t)
{
}
//TimePoint::TimePoint(time_t t)
//{
// needs an implementation
//}
TimePoint::TimePoint(std::string s)
TimeStamp::TimeStamp(std::string s)
: m_time(boost::posix_time::not_a_date_time)
{
if (s.size())
@@ -29,12 +24,12 @@ TimePoint::TimePoint(std::string s)
}
}
bool TimePoint::isValid() const
bool TimeStamp::isValid() const
{
return m_time != boost::posix_time::not_a_date_time;
}
std::string TimePoint::toString() const
std::string TimeStamp::toString() const
{
std::stringstream stream;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
@@ -44,7 +39,7 @@ std::string TimePoint::toString() const
return stream.str();
}
std::string TimePoint::getDDMMYYYYString() const
std::string TimeStamp::getDDMMYYYYString() const
{
std::stringstream stream;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
@@ -54,17 +49,17 @@ std::string TimePoint::getDDMMYYYYString() const
return stream.str();
}
size_t TimePoint::deltaMS(const TimePoint& other) const
size_t TimeStamp::deltaMS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_milliseconds();
}
size_t TimePoint::deltaS(const TimePoint& other) const
size_t TimeStamp::deltaS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_seconds();
}
bool TimePoint::isSameDay(const TimePoint& other) const
bool TimeStamp::isSameDay(const TimeStamp& other) const
{
if (m_time.date().day() == other.m_time.date().day() &&
m_time.date().month() == other.m_time.date().month() &&
@@ -76,8 +71,14 @@ bool TimePoint::isSameDay(const TimePoint& other) const
return false;
}
size_t TimePoint::deltaDays(const TimePoint& other) const
size_t TimeStamp::deltaDays(const TimeStamp& other) const
{
boost::gregorian::date_duration deltaDate = m_time.date() - other.m_time.date();
return size_t(std::abs(deltaDate.days()));
}
long TimeStamp::deltaHours(const TimeStamp& other) const
{
boost::posix_time::time_duration delta = m_time - other.m_time;
return delta.total_seconds() / 3600;
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef TIME_STAMP_H
#define TIME_STAMP_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimeStamp
{
public:
static TimeStamp now();
TimeStamp();
TimeStamp(boost::posix_time::ptime t);
TimeStamp(std::string s);
bool isValid() const;
std::string toString() const;
std::string getDDMMYYYYString() const;
inline bool operator==(const TimeStamp& rhs) { return m_time == rhs.m_time; }
inline bool operator!=(const TimeStamp& rhs) { return m_time != rhs.m_time; }
inline bool operator<(const TimeStamp& rhs) { return m_time < rhs.m_time; }
inline bool operator>(const TimeStamp& rhs) { return m_time > rhs.m_time; }
inline bool operator<=(const TimeStamp& rhs) { return m_time <= rhs.m_time; }
inline bool operator>=(const TimeStamp& rhs) { return m_time >= rhs.m_time; }
size_t deltaMS(const TimeStamp& other) const;
size_t deltaS(const TimeStamp& other) const;
bool isSameDay(const TimeStamp& other) const;
// days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
size_t deltaDays(const TimeStamp& other) const;
long deltaHours(const TimeStamp& other) const;
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_STAMP_H
+1 -1
View File
@@ -10,7 +10,7 @@ FileInfo::FileInfo(const FilePath& path)
{
}
FileInfo::FileInfo(const FilePath& path, const TimePoint& lastWriteTime)
FileInfo::FileInfo(const FilePath& path, const TimeStamp& lastWriteTime)
: path(path)
, lastWriteTime(lastWriteTime)
{
+3 -3
View File
@@ -6,16 +6,16 @@
#include "boost/date_time.hpp"
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
struct FileInfo
{
FileInfo();
FileInfo(const FilePath& path);
FileInfo(const FilePath& path, const TimePoint& lastWriteTime);
FileInfo(const FilePath& path, const TimeStamp& lastWriteTime);
FilePath path;
TimePoint lastWriteTime;
TimeStamp lastWriteTime;
};
#endif // FILE_INFO_H
+2 -2
View File
@@ -143,7 +143,7 @@ unsigned long long FileSystem::getFileByteSize(const FilePath& filePath)
return boost::filesystem::file_size(filePath.path());
}
TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
TimeStamp FileSystem::getLastWriteTime(const FilePath& filePath)
{
boost::posix_time::ptime lastWriteTime;
if (filePath.exists())
@@ -151,7 +151,7 @@ TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
std::time_t t = boost::filesystem::last_write_time(filePath.path());
lastWriteTime = boost::posix_time::from_time_t(t);
}
return TimePoint(lastWriteTime);
return TimeStamp(lastWriteTime);
}
std::string FileSystem::getTimeStringNow() // TODO: move to utility
+2 -2
View File
@@ -5,7 +5,7 @@
#include <vector>
#include "utility/file/FileInfo.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class FileSystem
{
@@ -20,7 +20,7 @@ public:
static unsigned long long getFileByteSize(const FilePath& filePath);
static TimePoint getLastWriteTime(const FilePath& filePath);
static TimeStamp getLastWriteTime(const FilePath& filePath);
static std::string getTimeStringNow();
static bool exists(const FilePath& path);
@@ -3,7 +3,7 @@
#include <thread>
#include "utility/logging/logging.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/utility.h"
std::string SharedMemoryGarbageCollector::s_memoryNamePrefix = "grbg_cllctr_";
@@ -101,11 +101,11 @@ void SharedMemoryGarbageCollector::stop()
}
bool otherRunningInstances = false;
TimePoint now = TimePoint::now();
TimeStamp now = TimeStamp::now();
for (SharedMemory::Map<SharedMemory::String, SharedMemory::String>::iterator it = instances->begin();
it != instances->end(); it++)
{
TimePoint timestamp = TimePoint(std::string(it->second.c_str()));
TimeStamp timestamp = TimeStamp(std::string(it->second.c_str()));
if (now.deltaS(timestamp) <= s_deleteThresholdSeconds)
{
otherRunningInstances = true;
@@ -163,7 +163,7 @@ void SharedMemoryGarbageCollector::update()
}
SharedMemory::String t(access.getAllocator());
t = TimePoint::now().toString().c_str();
t = TimeStamp::now().toString().c_str();
// update instances
{
@@ -231,11 +231,11 @@ void SharedMemoryGarbageCollector::update()
}
// delete old shared memories
TimePoint now = TimePoint::now();
TimeStamp now = TimeStamp::now();
for (SharedMemory::Map<SharedMemory::String, SharedMemory::String>::iterator it = timeStamps->begin();
it != timeStamps->end();)
{
TimePoint timestamp = TimePoint(std::string(it->second.c_str()));
TimeStamp timestamp = TimeStamp(std::string(it->second.c_str()));
if (now.deltaS(timestamp) > s_deleteThresholdSeconds)
{
LOG_INFO_STREAM(<< "collect garbage: " << it->first.c_str());
@@ -10,7 +10,7 @@ TaskDecoratorDelay::TaskDecoratorDelay(size_t delayMS)
void TaskDecoratorDelay::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_start = TimePoint::now();
m_start = TimeStamp::now();
}
Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackboard)
@@ -23,7 +23,7 @@ Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackbo
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
m_delayComplete = (TimePoint::now().deltaMS(m_start) >= m_delayMS);
m_delayComplete = (TimeStamp::now().deltaMS(m_start) >= m_delayMS);
return Task::STATE_HOLD;
}
@@ -5,7 +5,7 @@
#include "utility/scheduling/TaskDecorator.h"
#include "utility/scheduling/TaskRunner.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class TaskDecoratorDelay
: public TaskDecorator
@@ -22,7 +22,7 @@ private:
const size_t m_delayMS;
TimePoint m_start;
TimeStamp m_start;
bool m_delayComplete;
};
+2 -2
View File
@@ -173,11 +173,11 @@ ScopedTrace::ScopedTrace(
m_event->functionName = functionName;
m_event->locationName = FilePath(fileName).fileName() + ":" + std::to_string(lineNumber);
m_timePoint = utility::durationStart();
m_TimeStamp = utility::durationStart();
}
ScopedTrace::~ScopedTrace()
{
m_event->time = utility::duration(m_timePoint);
m_event->time = utility::duration(m_TimeStamp);
Tracer::getInstance()->finishEvent(m_event);
}
+2 -2
View File
@@ -5,7 +5,7 @@
#include <stack>
#include <thread>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
struct TraceEvent
@@ -63,7 +63,7 @@ public:
private:
TraceEvent* m_event;
TimePoint m_timePoint;
TimeStamp m_TimeStamp;
};
+7 -7
View File
@@ -16,20 +16,20 @@ ApplicationArchitectureType utility::getApplicationArchitectureType()
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
TimePoint utility::durationStart()
TimeStamp utility::durationStart()
{
return TimePoint::now();
return TimeStamp::now();
}
float utility::duration(const TimePoint& start)
float utility::duration(const TimeStamp& start)
{
TimePoint now = durationStart();
return now - start;
TimeStamp now = durationStart();
return float(now.deltaMS(start)) / 1000.0f;
}
float utility::duration(std::function<void()> func)
{
const TimePoint start = durationStart();
const TimeStamp start = durationStart();
func();
@@ -45,7 +45,7 @@ std::string utility::timeToString(const time_t time)
std::string utility::timeToString(const boost::posix_time::ptime time)
{
return TimePoint(time).toString();
return TimeStamp(time).toString();
}
std::string utility::timeToString(float secondsTotal)
+3 -3
View File
@@ -15,12 +15,12 @@
#include "utility/ApplicationArchitectureType.h"
#include "utility/file/FilePath.h"
#include "utility/math/Vector2.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
namespace utility
{
TimePoint durationStart();
float duration(const TimePoint& start);
TimeStamp durationStart();
float duration(const TimeStamp& start);
float duration(std::function<void()> func);
std::string timeToString(const time_t time);