Skip to content

Commit

Permalink
pulled latest sw version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin710 committed Mar 26, 2024
2 parents 5fd4ae9 + 4d26c59 commit b00a16d
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 150 deletions.
2 changes: 2 additions & 0 deletions EmotiBitOscilloscope/EmotiBitOscilloscope.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<ClCompile Include="..\..\ofxLSL\src\ofxLSLResolver.cpp" />
<ClCompile Include="..\..\ofxOscilloscope\src\patchboard.cpp" />
<ClCompile Include="..\src\Signal\Periodizer.cpp" />
<ClCompile Include="..\src\SoftwareVersionChecker.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\ofApp.cpp" />
<ClCompile Include="..\..\..\addons\ofxBiquadFilter\src\ofxBiquadFilter.cpp" />
Expand Down Expand Up @@ -163,6 +164,7 @@
<ClInclude Include="..\..\ofxLSL\src\ofxLSLSender.h" />
<ClInclude Include="..\..\ofxOscilloscope\src\patchboard.h" />
<ClInclude Include="..\src\Signal\Periodizer.h" />
<ClInclude Include="..\src\SoftwareVersionChecker.h" />
<ClInclude Include="src\ofApp.h" />
<ClInclude Include="..\..\..\addons\ofxBiquadFilter\src\ofxBiquadFilter.h" />
<ClInclude Include="..\..\..\addons\ofxBiquadFilter\src\ofxBiquadFilterInstance.h" />
Expand Down
6 changes: 6 additions & 0 deletions EmotiBitOscilloscope/EmotiBitOscilloscope.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
<ClCompile Include="..\..\ofxLSL\src\ofxLSLResolver.cpp">
<Filter>addons\ofxLSL\src</Filter>
</ClCompile>
<ClCompile Include="..\src\SoftwareVersionChecker.cpp">
<Filter>addons\ofxEmotiBit\src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="src">
Expand Down Expand Up @@ -524,6 +527,9 @@
<ClInclude Include="..\..\ofxLSL\src\ofxLSLSender.h">
<Filter>addons\ofxLSL\src</Filter>
</ClInclude>
<ClInclude Include="..\src\SoftwareVersionChecker.h">
<Filter>addons\ofxEmotiBit\src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="icon.rc" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
8E016F802832CE28005D7C65 /* EmotiBitFactoryTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8E016F782832CE28005D7C65 /* EmotiBitFactoryTest.cpp */; };
8E016F842832CE82005D7C65 /* Periodizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8E016F832832CE82005D7C65 /* Periodizer.cpp */; };
8E016F862832D594005D7C65 /* emotibitCommSettings.json in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E016F852832D594005D7C65 /* emotibitCommSettings.json */; };
8E07BBAD2B1F824D00CDD443 /* SoftwareVersionChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8E07BBAB2B1F824D00CDD443 /* SoftwareVersionChecker.cpp */; };
8E6079EA27C978BE00959DDB /* inputSettings.xml in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E6079E827C978BE00959DDB /* inputSettings.xml */; };
8E6079EB27C978BE00959DDB /* ofxOscilloscopeSettings.xml in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E6079E927C978BE00959DDB /* ofxOscilloscopeSettings.xml */; };
8F5205AEF8861EF234F0651A /* ofxOscSender.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81967292BFC87A0144BD32C6 /* ofxOscSender.cpp */; };
Expand Down Expand Up @@ -207,6 +208,8 @@
8E016F822832CE82005D7C65 /* Periodizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Periodizer.h; path = ../src/Signal/Periodizer.h; sourceTree = "<group>"; };
8E016F832832CE82005D7C65 /* Periodizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Periodizer.cpp; path = ../src/Signal/Periodizer.cpp; sourceTree = "<group>"; };
8E016F852832D594005D7C65 /* emotibitCommSettings.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = emotibitCommSettings.json; path = bin/data/emotibitCommSettings.json; sourceTree = "<group>"; };
8E07BBAB2B1F824D00CDD443 /* SoftwareVersionChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SoftwareVersionChecker.cpp; path = ../src/SoftwareVersionChecker.cpp; sourceTree = "<group>"; };
8E07BBAC2B1F824D00CDD443 /* SoftwareVersionChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SoftwareVersionChecker.h; path = ../src/SoftwareVersionChecker.h; sourceTree = "<group>"; };
8E6079E827C978BE00959DDB /* inputSettings.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = inputSettings.xml; path = bin/data/inputSettings.xml; sourceTree = "<group>"; };
8E6079E927C978BE00959DDB /* ofxOscilloscopeSettings.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = ofxOscilloscopeSettings.xml; path = bin/data/ofxOscilloscopeSettings.xml; sourceTree = "<group>"; };
8F225C97B6ECA8B22FFB4B76 /* rc5.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; name = rc5.h; path = ../../../addons/ofxPoco/libs/openssl/include/openssl/rc5.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -713,6 +716,8 @@
4CD5C6EA1AEB082DFF01E7BE /* src */ = {
isa = PBXGroup;
children = (
8E07BBAB2B1F824D00CDD443 /* SoftwareVersionChecker.cpp */,
8E07BBAC2B1F824D00CDD443 /* SoftwareVersionChecker.h */,
8E016F812832CE65005D7C65 /* Signal */,
AFB59BF33EDC27D6AF2CC50B /* ArduinoString.h */,
B37D59256BC5BDEB408A0B4B /* DoubleBuffer.h */,
Expand Down Expand Up @@ -1565,6 +1570,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8E07BBAD2B1F824D00CDD443 /* SoftwareVersionChecker.cpp in Sources */,
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */,
E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */,
D820615CFDD5F497033D7C5A /* ofxBiquadFilter.cpp in Sources */,
Expand Down
151 changes: 3 additions & 148 deletions EmotiBitOscilloscope/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ofxBiquadFilter.h"
#include <algorithm>


//--------------------------------------------------------------
void ofApp::setup() {
ofLogToConsole();
Expand All @@ -11,9 +12,8 @@ void ofApp::setup() {
#endif
ofSetFrameRate(30);
ofBackground(255, 255, 255);
checkLatestSwVersion();
SoftwareVersionChecker::checkLatestVersion();
ofSetLogLevel(OF_LOG_NOTICE);
writeOfxEmotiBitVersionFile();
setTypeTagPlotAttributes();
//saveEmotiBitCommSettings();
loadEmotiBitCommSettings();
Expand Down Expand Up @@ -75,152 +75,7 @@ void ofApp::update() {
updateMenuButtons();
}

void ofApp::checkLatestSwVersion()
{
bool newVersionAvailable = false;
// system call to curl
std::string latestReleaseUrl = "https://github.com/EmotiBit/ofxEmotiBit/releases/latest";
std::string latestReleaseApiRequest = "https://api.github.com/repos/EmotiBit/ofxEmotiBit/releases/latest";
std::string command = "curl " + latestReleaseApiRequest;
std::string response = "";
char buffer[200];
bool exceptionOccured = false;
try
{
#if defined (TARGET_OSX) || defined (TARGET_LINUX)
FILE* pipe = popen(command.c_str(), "r"); // returns NULL on fail. refer: https://man7.org/linux/man-pages/man3/popen.3.html#RETURN_VALUE
#else
FILE* pipe = _popen(command.c_str(), "r"); // returns NULL on fail. refer: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/popen-wpopen?view=msvc-170#return-value
#endif
if (pipe != NULL)
{
try
{
while (fgets(buffer, sizeof buffer, pipe) != NULL)
{
response += buffer;
}
}
catch (...) {
try
{
#if defined (TARGET_OSX) || defined (TARGET_LINUX)
pclose(pipe);
#else
_pclose(pipe);
#endif
}
catch (...)
{
ofLogError("Failed to close pipe");
}
ofLog(OF_LOG_ERROR, "An exception occured while executing curl");
exceptionOccured = true;
}
try
{
#if defined (TARGET_OSX) || defined (TARGET_LINUX)
pclose(pipe);
#else
_pclose(pipe);
#endif
}
catch (...)
{
ofLogError("Failed to close pipe");
}
}
else
{
ofLog(OF_LOG_ERROR, "Failed to check for latest version. Failed to open pipe");
exceptionOccured = true;
}
}
catch (...)
{
ofLogError("Failed to open pipe");
exceptionOccured = true;
}
try
{
if (!exceptionOccured & response != "")
{
ofxJSONElement jsonResponse;
if (jsonResponse.parse(response))
{
//ofLog(OF_LOG_NOTICE, jsonResponse.getRawString(true)); // uncomment to print curl output
std::string latestAvailableVersion = jsonResponse["tag_name"].asString();
ofLogNotice("Latest version") << latestAvailableVersion;
int swVerPrefixLoc = latestAvailableVersion.find(SOFTWARE_VERSION_PREFIX);
if (swVerPrefixLoc != std::string::npos)
{
latestAvailableVersion.erase(swVerPrefixLoc, 1); // remove leading version char "v"
}
// compare with ofxEmotiBitVersion
std::vector<std::string> latestVersionSplit = ofSplitString(latestAvailableVersion, ".");
std::vector<std::string> currentVersionSplit = ofSplitString(ofxEmotiBitVersion, ".");
int versionLength = latestVersionSplit.size() < currentVersionSplit.size() ? latestVersionSplit.size() : currentVersionSplit.size();
if (versionLength)
{
for (int i = 0; i < versionLength; i++)
{
int latest = ofToInt(latestVersionSplit.at(i));
int current = ofToInt(currentVersionSplit.at(i));
if (latest == current)
{
// need to check minor version
continue;
}
else if (latest < current)
{
// current version higher than latest available
break;
}
else // latest > current
{
// new version available
newVersionAvailable = true;
break;
}
}
}
else
{
ofLogError("Failed to parse version string");
}
}
else
{
ofLog(OF_LOG_ERROR, "unexpected curl response");
}
// If newer version available, display alert message
if (newVersionAvailable)
{
// create alert dialog box
ofSystemAlertDialog("A new version of EmotiBit Software is available!");
// open browser to latest version
try
{
#ifdef TARGET_WIN32
std::string command = "start " + latestReleaseUrl;
system(command.c_str());
#else
std::string command = "open " + latestReleaseUrl;
system(command.c_str());
#endif
}
catch (...)
{
ofLogError("Failed to open browser");
}
}
}
}
catch (...)
{
ofLogError("An exception occured while checking latest version of EmotiBit software");
}
}


// ToDo: This function should be removed once we complete our move to xmlFileSettings
void ofApp::setTypeTagPlotAttributes()
Expand Down
2 changes: 1 addition & 1 deletion EmotiBitOscilloscope/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "patchboard.h"
#include "Periodizer.h"
#include "ofxJSON.h"
#include "SoftwareVersionChecker.h"

class ofApp : public ofBaseApp {
public:
Expand Down Expand Up @@ -83,7 +84,6 @@ class ofApp : public ofBaseApp {
void updatePlotAttributeLists(std::string settingsFile = "ofxOscilloscopeSettings.xml");
// ToDo: This function is marked to be removed when we complete our move to xmlFileSettings.
void updateTypeTagList();
void checkLatestSwVersion();
void loadEmotiBitCommSettings(string settingsFilePath = "emotibitCommSettings.json", bool absolutePath = false);
void saveEmotiBitCommSettings(string settingsFilePath = "emotibitCommSettings.json", bool absolutePath = false, bool pretty = true);

Expand Down
Loading

0 comments on commit b00a16d

Please sign in to comment.