Browse Source

Adding license management

Josh Engebretson 10 years ago
parent
commit
f1fe255279

+ 1 - 1
Script/AtomicEditor/ui/EditorUI.ts

@@ -72,7 +72,7 @@ class EditorUI extends Atomic.ScriptObject {
   showModalError(windowText:string, message:string)
   {
       var window = new Atomic.UIMessageWindow(this.view, "modal_error");
-      window.show(windowText, message, 640, 360);
+      window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
   }
 
   view: Atomic.UIView;

+ 41 - 2
Script/AtomicEditor/ui/MainFrameMenu.ts

@@ -26,6 +26,14 @@ class MainFrameMenu extends Atomic.ScriptObject {
                 return true;
             }
 
+            if (refid == "manage license") {
+
+              EditorUI.getModelOps().showManageLicense();
+
+              return true;
+
+            }
+
             if (refid == "quit") {
 
                 this.sendEvent(EditorEvents.Quit);
@@ -41,8 +49,8 @@ class MainFrameMenu extends Atomic.ScriptObject {
             }
 
             if (refid == "edit format code") {
-              EditorUI.getShortcuts().invokeFormatCode();
-              return true;
+                EditorUI.getShortcuts().invokeFormatCode();
+                return true;
             }
 
             return false;
@@ -51,12 +59,43 @@ class MainFrameMenu extends Atomic.ScriptObject {
 
             if (refid == "file new project") {
 
+                if (ToolCore.toolSystem.project) {
+
+                    EditorUI.showModalError("Project Open",
+                        "Please close the current project before creating a new one");
+
+                    return true;
+                }
+
                 var mo = EditorUI.getModelOps();
                 mo.showNewProject();
 
                 return true;
 
             }
+            if (refid == "file open project") {
+
+                if (ToolCore.toolSystem.project) {
+
+                    EditorUI.showModalError("Project Open",
+                        "Please close the current project before opening new one");
+
+                    return true;
+                }
+
+                var utils = new Editor.FileUtils();
+                var path = utils.openProjectFileDialog();
+                if (path) {
+
+                    this.sendEvent(EditorEvents.LoadProject, { path: path });
+
+                }
+
+
+                return true;
+
+            }
+
             if (refid == "file close project") {
 
                 this.sendEvent(EditorEvents.CloseProject);

+ 84 - 0
Script/AtomicEditor/ui/license/ManageLicense.ts

@@ -0,0 +1,84 @@
+
+import EditorEvents = require("../../editor/EditorEvents");
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("../modal/ModalWindow");
+import ProgressModal = require("../modal/ProgressModal");
+
+class ManageLicense extends ModalWindow {
+
+    constructor() {
+
+        super();
+
+        this.init("Product Activation", "AtomicEditor/editor/ui/managelicense.tb.txt");
+
+        this.progressModal = new ProgressModal("License Management", "Returning license, please wait...");
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "ok") {
+
+                this.hide();
+                return true;
+            }
+
+            if (ev.target.id == "confirm_license_return") {
+
+                if (ev.refid == "TBMessageWindow.ok") {
+
+                    if (ToolCore.licenseSystem.deactivate()) {
+
+                        this.progressModal.show();
+
+                        this.subscribeToEvent("LicenseDeactivationSuccess", (ev) => {
+
+                            this.progressModal.hide();
+                            this.hide();
+
+                            EditorUI.getModelOps().showActivationWindow();
+
+                        });
+
+                        this.subscribeToEvent("LicenseDeactivationError", (ev: ToolCore.LicenseDeactivationErrorEvent) => {
+
+                            this.progressModal.hide();
+
+                            EditorUI.showModalError("Deactivation Error", ev.message);
+
+                        });
+
+                    }
+                }
+
+                return true;
+            }
+
+
+            if (id == "return_activation") {
+
+                if (ToolCore.toolSystem.project) {
+                    EditorUI.showModalError("Project Open",
+                        "Please close the current project before deactivating license");
+
+                }
+                else {
+                    var confirm = new Atomic.UIMessageWindow(this, "confirm_license_return");
+                    confirm.show("Return License", "Are you sure you want to return the installed license?", Atomic.UI_MESSAGEWINDOW_SETTINGS_OK_CANCEL, true, 300, 140);
+                }
+
+                return true;
+            }
+
+        }
+    }
+
+    progressModal: ProgressModal;
+}
+
+export = ManageLicense;

+ 1 - 1
Script/AtomicEditor/ui/modal/MessageModal.ts

@@ -9,7 +9,7 @@ export class MessageModal extends Atomic.ScriptObject
 
     var mainframe = EditorUI.getMainFrame();
 
-    new Atomic.UIMessageWindow(mainframe, "modal_error").show(title, message, 640, 360);
+    new Atomic.UIMessageWindow(mainframe, "modal_error").show(title, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
 
   }
 

+ 12 - 0
Script/AtomicEditor/ui/modal/ModalOps.ts

@@ -7,6 +7,7 @@ import CreateProject = require("./CreateProject");
 import EULAWindow = require("../license/EULAWindow");
 import ActivationWindow = require("../license/ActivationWindow");
 import ActivationSuccessWindow = require("../license/ActivationSuccessWindow");
+import ManageLicense = require("../license/ManageLicense");
 
 import ResourceSelection = require("./ResourceSelection");
 
@@ -132,6 +133,17 @@ class ModalOps extends Atomic.ScriptObject {
 
     }
 
+    showManageLicense() {
+
+        if (this.show()) {
+
+            this.opWindow = new ManageLicense();
+
+        }
+
+    }
+
+
     showAbout() {
 
         if (this.show()) {

+ 8 - 1
Script/TypeScript/Atomic.d.ts

@@ -620,6 +620,13 @@ declare module Atomic {
    export var UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM: UI_LAYOUT_DISTRIBUTION_POSITION;
 
 
+   // enum UI_MESSAGEWINDOW_SETTINGS
+   export type UI_MESSAGEWINDOW_SETTINGS = number;
+   export var UI_MESSAGEWINDOW_SETTINGS_OK: UI_MESSAGEWINDOW_SETTINGS;
+   export var UI_MESSAGEWINDOW_SETTINGS_OK_CANCEL: UI_MESSAGEWINDOW_SETTINGS;
+   export var UI_MESSAGEWINDOW_SETTINGS_YES_NO: UI_MESSAGEWINDOW_SETTINGS;
+
+
    // enum UI_SIZE_DEP
    export type UI_SIZE_DEP = number;
    export var UI_SIZE_DEP_NONE: UI_SIZE_DEP;
@@ -7181,7 +7188,7 @@ declare module Atomic {
 
       constructor(target: UIWidget, id: string, createWidget?: boolean);
 
-      show(title: string, message: string, width: number, height: number): void;
+      show(title: string, message: string, settings: UI_MESSAGEWINDOW_SETTINGS, dimmer: boolean, width: number, height: number): void;
 
    }
 

+ 7 - 0
Script/TypeScript/AtomicWork.d.ts

@@ -180,6 +180,13 @@ declare module ToolCore {
 
     }
 
+    export interface LicenseDeactivationErrorEvent {
+
+        message:string;
+
+    }
+
+
     export var toolEnvironment: ToolEnvironment;
     export var toolSystem: ToolSystem;
     export var assetDatabase: AssetDatabase;

+ 2 - 0
Script/TypeScript/ToolCore.d.ts

@@ -414,6 +414,8 @@ declare module ToolCore {
       licenseModule3D(): boolean;
       // Returns whether there are any platform licenses available
       isStandardLicense(): boolean;
+      // Returns true if request to deactivate is made
+      deactivate(): boolean;
       resetLicense(): void;
       loadLicense(): boolean;
       // Basic key validation

+ 7 - 6
Source/Atomic/UI/UIMessageWindow.cpp

@@ -1,7 +1,7 @@
 
 #include <TurboBadger/tb_widgets.h>
 #include <TurboBadger/tb_widgets_common.h>
-#include <TurboBadger/tb_message_window.h>
+
 
 #include "../IO/Log.h"
 
@@ -29,16 +29,17 @@ UIMessageWindow::~UIMessageWindow()
 
 }
 
-void UIMessageWindow::Show(const String &title, const String &message, int width, int height)
+void UIMessageWindow::Show(const String &title, const String &message, UI_MESSAGEWINDOW_SETTINGS settings, bool dimmer, int width, int height)
 {
     if (!widget_)
         return;
 
-    TBMessageWindowSettings settings;
-    settings.styling = true;
-    settings.dimmer = true;
+    TBMessageWindowSettings tbsettings;
+    tbsettings.msg = (TB_MSG) settings;
+    tbsettings.styling = true;
+    tbsettings.dimmer = dimmer;
 
-    ((TBMessageWindow*)widget_)->Show(title.CString(), message.CString(), &settings, width, height);
+    ((TBMessageWindow*)widget_)->Show(title.CString(), message.CString(), &tbsettings, width, height);
 
 }
 

+ 11 - 1
Source/Atomic/UI/UIMessageWindow.h

@@ -1,11 +1,21 @@
 
 #pragma once
 
+#include <TurboBadger/tb_message_window.h>
+
 #include "UIWindow.h"
 
 namespace Atomic
 {
 
+enum UI_MESSAGEWINDOW_SETTINGS
+{
+    UI_MESSAGEWINDOW_SETTINGS_OK = tb::TB_MSG_OK,
+    UI_MESSAGEWINDOW_SETTINGS_OK_CANCEL = tb::TB_MSG_OK_CANCEL,
+    UI_MESSAGEWINDOW_SETTINGS_YES_NO = tb::TB_MSG_YES_NO
+};
+
+
 class UIMessageWindow : public UIWindow
 {
     OBJECT(UIMessageWindow)
@@ -15,7 +25,7 @@ public:
     UIMessageWindow(Context* context, UIWidget* target, const String& id, bool createWidget = true);
     virtual ~UIMessageWindow();
 
-    void Show(const String& title, const String& message, int width, int height);
+    void Show(const String& title, const String& message, UI_MESSAGEWINDOW_SETTINGS settings, bool dimmer, int width, int height);
 
 protected:
 

+ 1 - 1
Source/Atomic/UI/UIWindow.h

@@ -31,7 +31,7 @@ class UIWindow : public UIWidget
 
     public:
 
-        UIWindow(Context* context, bool createWidget = true);
+    UIWindow(Context* context, bool createWidget = true);
     virtual ~UIWindow();
 
     UI_WINDOW_SETTINGS GetSettings();

+ 2 - 2
Source/AtomicTool/AtomicTool.cpp

@@ -176,12 +176,12 @@ void AtomicTool::DoDeactivation()
         return;
     }
 
-    SharedPtr<CurlRequest> request = licenseSystem->Deactivate();
-    if (request.Null())
+    if (!licenseSystem->Deactivate())
     {
         ErrorExit("\nNot activated\n");
         return;
     }
+
     SubscribeToEvent(E_LICENSE_DEACTIVATIONERROR, HANDLER(AtomicTool, HandleLicenseDeactivationError));
     SubscribeToEvent(E_LICENSE_DEACTIVATIONSUCCESS, HANDLER(AtomicTool, HandleLicenseDeactivationSuccess));
 }

+ 10 - 6
Source/ToolCore/License/LicenseSystem.cpp

@@ -337,18 +337,22 @@ void LicenseSystem::Activate(const String& key, const LicenseParse& parse)
     SaveLicense();
 }
 
-SharedPtr<CurlRequest>& LicenseSystem::Deactivate()
+bool LicenseSystem::Deactivate()
 {
     if (deactivate_.NotNull())
     {
-        LOGERROR("LicenseSystem::Deactivate - request already exists");
-        return deactivate_;
+        VariantMap eventData;
+        eventData[LicenseDeactivationError::P_MESSAGE] = "LicenseSystem::Deactivate - request already exists";
+        SendEvent(E_LICENSE_DEACTIVATIONERROR, eventData);
+        return false;
     }
 
     if (!key_.Length())
     {
-        LOGERROR("LicenseSystem::Deactivate - zero length key");
-        return deactivate_;
+        VariantMap eventData;
+        eventData[LicenseDeactivationError::P_MESSAGE] = "LicenseSystem::Deactivate - zero length key";
+        SendEvent(E_LICENSE_DEACTIVATIONERROR, eventData);
+        return false;
     }
 
     CurlManager* cm = GetSubsystem<CurlManager>();
@@ -360,7 +364,7 @@ SharedPtr<CurlRequest>& LicenseSystem::Deactivate()
 
     SubscribeToEvent(deactivate_, E_CURLCOMPLETE, HANDLER(LicenseSystem, HandleDeactivate));
 
-    return deactivate_;
+    return true;
 
 }
 

+ 3 - 1
Source/ToolCore/License/LicenseSystem.h

@@ -59,7 +59,9 @@ public:
     bool IsStandardLicense();
 
     void Activate(const String& key, const LicenseParse& parse);
-    SharedPtr<CurlRequest>& Deactivate();
+
+    /// Returns true if request to deactivate is made
+    bool Deactivate();
 
     void ResetLicense();
     bool LoadLicense();