Browse Source

Adding version check functionality

Josh Engebretson 10 years ago
parent
commit
e289749e87

+ 2 - 4
Source/AtomicEditor/Source/AEApplication.cpp

@@ -29,6 +29,7 @@
 #include "Subprocess/AESubprocessSystem.h"
 #include "Build/BuildSystem.h"
 #include "License/AELicenseSystem.h"
+#include "License/AEVersionCheck.h"
 #include "Net/CurlManager.h"
 
 // just for testing, remove me
@@ -89,10 +90,6 @@ void AEApplication::Start()
 
     // The mouse isn't showing up on OSX until I tab, this is a hack and temp workaround
     input->SetMouseVisible(true);
-    input->SetMouseVisible(false);
-    input->SetMouseVisible(true);
-    input->SetMouseVisible(false);
-    input->SetMouseVisible(true);
 
     context_->RegisterSubsystem(new ProjectUtils(context_));
     context_->RegisterSubsystem(new Javascript(context_));
@@ -103,6 +100,7 @@ void AEApplication::Start()
 
 // BEGIN LICENSE MANAGEMENT
     context_->RegisterSubsystem(new LicenseSystem(context_));
+    context_->RegisterSubsystem(new VersionCheck(context_));
 // END LICENSE MANAGEMENT
 
     Editor* editor = new Editor(context_);

+ 1 - 1
Source/AtomicEditor/Source/AEVersion.h

@@ -5,6 +5,6 @@
 #pragma once
 
 #define ATOMIC_EDITOR_VERSION_MAJOR 0
-#define ATOMIC_EDITOR_VERSION_MINOR 1
+#define ATOMIC_EDITOR_VERSION_MINOR 2
 #define ATOMIC_EDITOR_VERSION_PATCH 0
 

+ 134 - 0
Source/AtomicEditor/Source/License/AEVersionCheck.cpp

@@ -2,3 +2,137 @@
 // Please see LICENSE.md in repository root for license information
 // https://github.com/AtomicGameEngine/AtomicGameEngine
 
+#include <rapidjson/document.h>
+#include <rapidjson/filestream.h>
+#include <rapidjson/prettywriter.h>
+
+#include "AtomicEditor.h"
+#include <Atomic/IO/Log.h>
+#include "AEEditor.h"
+#include "AEEvents.h"
+#include "AEVersion.h"
+#include "AEVersionCheck.h"
+
+namespace AtomicEditor
+{
+
+VersionCheck::VersionCheck(Context* context) :
+    Object(context)
+
+{
+    progressModal_ = new ProgressModal(context_, "Checking for Updates", "Checking for updates, please wait...");
+}
+
+VersionCheck::~VersionCheck()
+{
+
+}
+
+void VersionCheck::DoVersionCheck()
+{
+    progressModal_->Show();
+
+    CurlManager* cm = GetSubsystem<CurlManager>();
+
+    versionRequest_ = cm->MakeRequest("https://store.atomicgameengine.com/versions/atomic_editor.html");
+
+    SubscribeToEvent(versionRequest_, E_CURLCOMPLETE, HANDLER(VersionCheck, HandleCurlComplete));
+
+}
+
+void VersionCheck::HandleCurlComplete(StringHash eventType, VariantMap& eventData)
+{
+    progressModal_->Hide();
+
+    Editor* editor = GetSubsystem<Editor>();
+
+    bool valid = true;
+    int major;
+    int minor;
+    int patch;
+
+    if (versionRequest_->GetError().Length())
+    {
+        valid = false;
+    }
+    else
+    {
+        rapidjson::Document document;
+        String json = versionRequest_->GetResponse();
+
+        if (document.Parse<0>(json.CString()).HasParseError())
+        {
+            valid = false;
+        }
+        else
+        {
+            const rapidjson::Value::Member* jmajor = document.FindMember("major");
+            if (jmajor && jmajor->value.IsInt())
+            {
+                major = jmajor->value.GetInt();
+            }
+            else
+                valid = false;
+
+            const rapidjson::Value::Member* jminor = document.FindMember("minor");
+            if (jminor && jminor->value.IsInt())
+            {
+                minor = jminor->value.GetInt();
+            }
+            else
+                valid = false;
+
+            const rapidjson::Value::Member* jpatch = document.FindMember("patch");
+            if (jpatch && jpatch->value.IsInt())
+            {
+                patch = jpatch->value.GetInt();
+            }
+            else
+                valid = false;
+
+        }
+
+    }
+
+    if (!valid)
+    {
+        String errorMessage;
+        errorMessage.AppendWithFormat("There was an error contacting the version server\n\n%s", versionRequest_->GetError().CString());
+        editor->PostModalError("Error Contacting Version Server", errorMessage);
+    }
+    else
+    {
+        bool newer = false;
+        if (ATOMIC_EDITOR_VERSION_MAJOR < major)
+            newer = true;
+        else if (ATOMIC_EDITOR_VERSION_MINOR < minor)
+            newer = true;
+        else if (ATOMIC_EDITOR_VERSION_PATCH < patch)
+            newer = true;
+
+        if (newer)
+        {
+            editor->PostModalInfo("New Version Available", "There is a newer version of the Atomic Editor available");
+        }
+        else
+        {
+            editor->PostModalInfo("Up to date", "The Atomic Editor is up to date");
+        }
+
+    }
+
+    versionRequest_ = 0;
+
+}
+
+/*
+{
+    "major" : 0,
+    "minor" : 2,
+    "patch" : 0
+}
+*/
+
+
+}
+

+ 33 - 0
Source/AtomicEditor/Source/License/AEVersionCheck.h

@@ -1,3 +1,36 @@
 // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
 // Please see LICENSE.md in repository root for license information
 // https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#include <Atomic/Core/Object.h>
+
+#include "AETypes.h"
+#include "Net/CurlManager.h"
+#include "UI/Modal/UIProgressModal.h"
+
+using namespace Atomic;
+
+namespace AtomicEditor
+{
+
+class VersionCheck : public Object
+{
+    OBJECT(VersionCheck);
+
+public:
+
+    /// Construct.
+    VersionCheck(Context* context);
+    /// Destruct.
+    virtual ~VersionCheck();
+
+    void DoVersionCheck();
+
+private:
+    void HandleCurlComplete(StringHash eventType, VariantMap& eventData);
+
+    SharedPtr<CurlRequest> versionRequest_;
+    SharedPtr<ProgressModal> progressModal_;
+};
+
+}

+ 1 - 0
Source/AtomicEditor/Source/UI/Modal/UIProgressModal.cpp

@@ -41,6 +41,7 @@ ProgressModal::ProgressModal(Context* context, const String &title, const String
     assert(message_);
 
     message_->SetText(message.CString());
+    window_->SetText(title.CString());
 
     Center();
 }

+ 8 - 0
Source/AtomicEditor/Source/UI/UIMainFrame.cpp

@@ -24,6 +24,8 @@
 #include "UI/Modal/UIModalOps.h"
 #include "UI/Modal/UIMessageModal.h"
 
+#include "License/AEVersionCheck.h"
+
 #include "UIFindTextWidget.h"
 #include "../AEEvents.h"
 #include "../AEEditor.h"
@@ -52,6 +54,7 @@ MainFrame::MainFrame(Context* context) :
     menuAtomicEditorSource.AddItem(new TBGenericStringItem("-"));
     menuAtomicEditorSource.AddItem(new TBGenericStringItem("Manage License", TBIDC("manage license")));
     menuAtomicEditorSource.AddItem(new TBGenericStringItem("-"));
+    menuAtomicEditorSource.AddItem(new TBGenericStringItem("Check for Updates", TBIDC("check update")));
     menuAtomicEditorSource.AddItem(new TBGenericStringItem("Quit", TBIDC("quit")));
 
     menuFileSource.AddItem(new TBGenericStringItem("New Project", TBIDC("new project")));
@@ -437,6 +440,11 @@ bool MainFrame::OnEvent(const TBWidgetEvent &ev)
                 uiModalOps_->ShowManageLicense();
                 return true;
             }
+            else if (ev.ref_id == TBIDC("check update"))
+            {
+                GetSubsystem<VersionCheck>()->DoVersionCheck();
+                return true;
+            }
             else if (ev.ref_id == TBIDC("quit"))
             {
                 // TODO: confirmation