Example #1
0
        public void initialize(StandaloneController standaloneController)
        {
            if (resources.Count > 0)
            {
                var resourceManager = standaloneController.AtlasPluginManager.ResourceManager;
                foreach (var subsystemResources in resourceManager.getSubsystemEnumerator())
                {
                    var resourceGroup = subsystemResources.addResourceGroup(PluginNamespace);
                    foreach (var resource in resources)
                    {
                        var engineResource = resourceGroup.addResource(Path.Combine(RootFolder, resource.Path), "EngineArchive", resource.Recursive);
                    }
                }

                resourceManager.initializeResources();
            }

            if (PropDefinitionDirectory != null)
            {
                String fullPropPath = Path.Combine(RootFolder, PropDefinitionDirectory);
                if (VirtualFileSystem.Instance.exists(fullPropPath))
                {
                    foreach (var propPath in VirtualFileSystem.Instance.listFiles(fullPropPath, "*.prop", false))
                    {
                        using (var stream = VirtualFileSystem.Instance.openStream(propPath, Engine.Resources.FileMode.Open, Engine.Resources.FileAccess.Read))
                        {
                            var propDefinition = SharedXmlSaver.Load <PropDefinition>(stream);
                            propDefinition.DependencyPluginId = PluginId;
                            standaloneController.PropFactory.addDefinition(propDefinition);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Restore the instructions in a given directory.
        /// </summary>
        /// <param name="targetDirectory"></param>
        /// <returns></returns>
        public static ManagePluginInstructions restore(String targetDirectory)
        {
            String file = Path.Combine(targetDirectory, "ManagePlugins.xml");

            if (File.Exists(file))
            {
                using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    var loadedInstructions = SharedXmlSaver.Load <ManagePluginInstructions>(stream);
                    loadedInstructions.targetDirectory = Path.GetFullPath(targetDirectory);
                    return(loadedInstructions);
                }
            }
            return(null);
        }
        /// <summary>
        /// Save the instructions to a file.
        /// </summary>
        public void savePersistantFile()
        {
            String file = Path.Combine(targetDirectory, "ManagePlugins.xml");

            try
            {
                using (Stream stream = File.Open(file, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, FileShare.None))
                {
                    SharedXmlSaver.Save(this, stream);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Could not write dependency management instructions to '{0}' because {1}.", file, ex.Message);
            }
        }
Example #4
0
 public override void clicked(TaskPositioner taskPositioner)
 {
     if (Plugin.AtlasPluginManager.allDependenciesLoadedFor(this.Plugin))
     {
         VirtualFilesystemResourceProvider resourceProvider = new VirtualFilesystemResourceProvider(Plugin.PluginRootFolder);
         try
         {
             Slideshow slideshow;
             using (Stream stream = resourceProvider.openFile(SlideshowFile))
             {
                 slideshow = SharedXmlSaver.Load <Slideshow>(stream);
             }
             if (slideshow.Version == Slideshow.CurrentVersion)
             {
                 AnomalousMvcContext context = slideshow.createContext(resourceProvider, Plugin.GuiManager);
                 context.RuntimeName = UniqueName;
                 context.setResourceProvider(resourceProvider);
                 Plugin.TimelineController.setResourceProvider(resourceProvider);
                 Plugin.MvcCore.startRunningContext(context);
             }
             else
             {
                 MessageBox.show(String.Format("Cannot run slideshow \"{0}.\" It was created in a different version of Anomalous Medical.\nYou will need to download an updated version.", Name), "Error", MessageBoxStyle.IconError | MessageBoxStyle.Ok);
                 InlineRmlUpgradeCache.removeSlideshowPanels(slideshow);
             }
         }
         catch (Exception ex)
         {
             Log.Error("Cannot load context '{0}'\nReason: {1}", SlideshowFile, ex.Message);
         }
     }
     else
     {
         MessageBox.show("Additional files needed to run this task. Would you like to download them now?", "Files Needed", MessageBoxStyle.IconQuest | MessageBoxStyle.Yes | MessageBoxStyle.No, result =>
         {
             if (result == MessageBoxStyle.Yes)
             {
                 Plugin.AtlasPluginManager.requestDependencyDownloadFor(this.Plugin);
             }
         });
     }
 }
        private void findDependencies()
        {
            CleanupInfo resourceInfo = new CleanupInfo();

            resourceInfo.defineObjectClass(ShowPropAction.PropClass);
            foreach (String file in editorController.ResourceProvider.listFiles("*.tl", "", true))
            {
                Timeline timeline;
                using (Stream fileStream = editorController.ResourceProvider.openFile(file))
                {
                    timeline = SharedXmlSaver.Load <Timeline>(fileStream);
                }
                timeline.cleanup(resourceInfo);
            }

            plugin.setDependencyIds(resourceInfo.getObjects <String>(ShowPropAction.PropClass)
                                    .Select(n => standaloneController.PropFactory.getDependencyIdForProp(n))
                                    .Where(id => id.HasValue)
                                    .Select(id => id.Value));
        }
Example #6
0
        public virtual void cleanup(CleanupInfo info, ResourceProvider resourceProvider)
        {
            String timelinePath = Path.Combine(UniqueName, "Timeline.tl");

            info.claimFile(timelinePath);
            if (resourceProvider.exists(timelinePath))
            {
                using (Stream stream = resourceProvider.openFile(timelinePath))
                {
                    Timeline timeline = SharedXmlSaver.Load <Timeline>(stream);
                    timeline.cleanup(info);
                }
            }
            info.claimFile(Path.Combine(UniqueName, "Thumb.png"));
            info.claimFile(Path.Combine(UniqueName, StyleSheetName));
            info.claimFile(SceneThumbName);
            info.claimFile(SceneThumbInfoName);
            layoutStrategy.claimFiles(info, resourceProvider, this);

            //Clean up actions
            List <String> removeActions = new List <String>(triggerActions.Keys);

            foreach (String action in info.getObjects <String>(Slide.SlideActionClass))
            {
                removeActions.Remove(action);
            }
            foreach (String action in removeActions)
            {
                triggerActions.Remove(action);
            }
            info.clearObjects(Slide.SlideActionClass);

            foreach (var action in triggerActions.Values)
            {
                action.cleanup(this, info, resourceProvider);
            }
        }
Example #7
0
        private bool addDataDrivenPlugin(String path)
        {
            bool   loadedPlugin    = false;
            String pluginDirectory = null;
            String fullPath;

            //Try to load from virtual file system first
            if (VirtualFileSystem.Instance.directoryExists(path))
            {
                fullPath = path;
                String directoryName = Path.GetFileName(Path.GetDirectoryName(path));
                if (!loadedPluginNames.Contains(directoryName))
                {
                    loadedPluginNames.Add(directoryName);

                    pluginDirectory = String.Format("Plugins/{0}/", directoryName);
                }
                else
                {
                    Log.Error("Cannot plugin file '{0}' from virtual file system because a plugin named '{1}' is already loaded.", path, directoryName);
                }
            }
            else
            {
                fullPath = Path.GetFullPath(path);
                if (!Directory.Exists(fullPath) && !File.Exists(fullPath))
                {
                    fullPath = Path.Combine(additionalSearchPath, path);
                }

                if (File.Exists(fullPath))
                {
                    String dataFileName = Path.GetFileNameWithoutExtension(fullPath);
                    try
                    {
                        if (!loadedPluginNames.Contains(dataFileName))
                        {
                            //Add the archive to the VirtualFileSystem if needed
                            if (!VirtualFileSystem.Instance.containsRealAbsolutePath(fullPath))
                            {
                                VirtualFileSystem.Instance.addArchive(fullPath);
                            }
                            pluginDirectory = String.Format("Plugins/{0}/", Path.GetFileNameWithoutExtension(path));

                            loadedPluginNames.Add(dataFileName);
                        }
                        else
                        {
                            Log.Error("Cannot load data file '{0}' from '{1}' because a plugin named '{2}' is already loaded.", path, fullPath, dataFileName);
                        }
                    }
                    catch (ZipAccess.ZipIOException e)
                    {
                        firePluginLoadError(String.Format("There was an error loading the plugin '{0}'.", dataFileName));
                        Log.Error("Cannot load data file '{0}' from '{1}' because of a zip read error: {2}. Deleting corrupted plugin.", path, fullPath, e.Message);
                        try
                        {
                            File.Delete(fullPath);
                        }
                        catch (Exception deleteEx)
                        {
                            Log.Error("Error deleting data file '{0}' from '{1}' because: {2}.", path, fullPath, deleteEx.Message);
                        }
                    }
                }
                else if (Directory.Exists(fullPath))
                {
                    String directoryName = Path.GetFileName(Path.GetDirectoryName(fullPath));
                    if (!loadedPluginNames.Contains(directoryName))
                    {
                        loadedPluginNames.Add(directoryName);

                        pluginDirectory = String.Format("Plugins/{0}/", directoryName);
                        String rootPluginPath = fullPath.Replace("\\", "/");
                        if (!rootPluginPath.EndsWith("/"))
                        {
                            rootPluginPath += "/";
                        }
                        rootPluginPath = rootPluginPath.Replace(pluginDirectory, "");

                        //Add the archive to the VirtualFileSystem if needed
                        if (!VirtualFileSystem.Instance.containsRealAbsolutePath(rootPluginPath))
                        {
                            VirtualFileSystem.Instance.addArchive(rootPluginPath);
                        }
                    }
                    else
                    {
                        Log.Error("Cannot load data file '{0}' from '{1}' because a plugin named '{2}' is already loaded.", path, fullPath, directoryName);
                    }
                }
                else
                {
                    Log.Error("Cannot load data file '{0}' from '{0}' or '{1}' because it was not found.", path, fullPath, Path.GetFullPath(path));
                }
            }

            if (pluginDirectory != null)
            {
                String pluginDefinitionFile = pluginDirectory + "Plugin.ddp";

                if (VirtualFileSystem.Instance.exists(pluginDefinitionFile))
                {
                    using (Stream pluginStream = VirtualFileSystem.Instance.openStream(pluginDefinitionFile, Engine.Resources.FileMode.Open, Engine.Resources.FileAccess.Read))
                    {
                        try
                        {
                            DDAtlasPlugin plugin = SharedXmlSaver.Load <DDAtlasPlugin>(pluginStream);
                            if (plugin != null)
                            {
                                plugin.Location         = fullPath;
                                plugin.PluginRootFolder = pluginDirectory;
                                addPlugin(plugin, false);
                                loadedPlugin = true;
                            }
                            else
                            {
                                throw new Exception(String.Format("Error loading '{0}' in path '{1}' from '{2}' because it was null.", pluginDefinitionFile, path, fullPath));
                            }
                        }
                        catch (Exception ex)
                        {
                            firePluginLoadError(String.Format("There was an error loading the plugin '{0}'.", Path.GetFileName(fullPath)));
                            Log.Error(ex.Message);
                            try
                            {
                                File.Delete(fullPath);
                            }
                            catch (Exception deleteEx)
                            {
                                Log.Error("Error deleting data file '{0}' from '{1}' because: {2}.", path, fullPath, deleteEx.Message);
                                managePluginInstructions.addFileToDelete(fullPath);
                                managePluginInstructions.savePersistantFile();
                            }
                        }
                    }
                }

                if (!loadedPlugin)
                {
                    String dependencyDefinitionFile = pluginDirectory + "Dependency.ddd";
                    if (VirtualFileSystem.Instance.fileExists(dependencyDefinitionFile))
                    {
                        using (Stream stream = VirtualFileSystem.Instance.openStream(dependencyDefinitionFile, Engine.Resources.FileMode.Open, Engine.Resources.FileAccess.Read))
                        {
                            try
                            {
                                DDAtlasDependency dependency = SharedXmlSaver.Load <DDAtlasDependency>(stream);
                                if (dependency != null)
                                {
                                    dependency.Location   = fullPath;
                                    dependency.RootFolder = pluginDirectory;
                                    addDependency(dependency);
                                    loadedPlugin = true;
                                }
                                else
                                {
                                    throw new Exception(String.Format("Error loading '{0}' in path '{1}' from '{2}' because it was null.", dependencyDefinitionFile, path, fullPath));
                                }
                            }
                            catch (Exception ex)
                            {
                                firePluginLoadError(String.Format("There was an error loading the plugin '{0}'.", Path.GetFileName(fullPath)));
                                Log.Error(ex.Message);
                                try
                                {
                                    File.Delete(fullPath);
                                }
                                catch (Exception deleteEx)
                                {
                                    Log.Error("Error deleting data file '{0}' from '{1}' because: {2}.", path, fullPath, deleteEx.Message);
                                    managePluginInstructions.addFileToDelete(fullPath);
                                    managePluginInstructions.savePersistantFile();
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Error("Error loading '{0}' or '{1}' in path '{2}' from '{3}' because it does not exist.", pluginDefinitionFile, dependencyDefinitionFile, path, fullPath);
                    }
                }
            }

            return(loadedPlugin);
        }
        public SlideshowRuntime(Slideshow slideshow, ResourceProvider resourceProvider, GUIManager guiManager, int startIndex, TaskController additionalTasks)
        {
            this.guiManager = guiManager;

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (Stream resourceStream = assembly.GetManifestResourceStream(SlideshowProps.BaseContextProperties.File))
            {
                mvcContext = SharedXmlSaver.Load <AnomalousMvcContext>(resourceStream);
            }
            navModel       = (NavigationModel)mvcContext.Models[SlideshowProps.BaseContextProperties.NavigationModel];
            displayManager = new SlideDisplayManager(slideshow.VectorMode);
            foreach (Slide slide in slideshow.Slides)
            {
                String slideName = slide.UniqueName;
                slide.setupContext(mvcContext, slideName, resourceProvider, displayManager);

                NavigationLink link = new NavigationLink(slideName, null, slideName + "/Show");
                navModel.addNavigationLink(link);
            }

            RunCommandsAction runCommands = (RunCommandsAction)mvcContext.Controllers["Common"].Actions["Start"];

            runCommands.addCommand(new NavigateToIndexCommand()
            {
                Index = startIndex
            });

            taskbar        = new ClosingTaskbar();
            taskbarLink    = new SingleChildChainLink(SlideTaskbarName, taskbar);
            taskbar.Close += close;
            previousTask   = new CallbackTask("Slideshow.Back", "Back", PreviousTaskName, "None", arg =>
            {
                back();
            });
            nextTask = new CallbackTask("Slideshow.Forward", "Forward", NextTaskName, "None", arg =>
            {
                next();
            });
            taskbar.addItem(new TaskTaskbarItem(previousTask));
            taskbar.addItem(new TaskTaskbarItem(nextTask));
            taskbar.addItem(new TaskTaskbarItem(new CallbackTask("Slideshow.Reload", "Reload", ReloadTaskName, "None", arg =>
            {
                reload();
            })));
            //taskbar.addItem(new TaskTaskbarItem(new CallbackTask("Slideshow.ToggleMode", "Toggle Display Mode", "SlideshowIcons/NormalVectorToggle", "None", arg =>
            //{
            //    displayManager.VectorMode = !displayManager.VectorMode;
            //    guiManager.layout();
            //})));
            taskbar.addItem(new TaskTaskbarItem(new CallbackTask("Slideshow.ZoomIn", "Zoom In", "SlideshowIcons/ZoomIn", "None", arg =>
            {
                zoomIn();
            })));
            taskbar.addItem(new TaskTaskbarItem(new CallbackTask("Slideshow.ResetZoom", "Reset Zoom", "SlideshowIcons/ResetZoom", "None", arg =>
            {
                if (displayManager.AdditionalZoomMultiple != 1.0f)
                {
                    displayManager.AdditionalZoomMultiple = 1.0f;
                    guiManager.layout();
                }
            })));
            taskbar.addItem(new TaskTaskbarItem(new CallbackTask("Slideshow.ZoomOut", "Zoom Out", "SlideshowIcons/ZoomOut", "None", arg =>
            {
                zoomOut();
            })));

            eventContext = new EventContext();
            ButtonEvent nextEvent = new ButtonEvent(EventLayers.Gui);

            nextEvent.addButton(KeyboardButtonCode.KC_RIGHT);
            nextEvent.FirstFrameUpEvent += eventManager =>
            {
                next();
            };
            eventContext.addEvent(nextEvent);

            ButtonEvent backEvent = new ButtonEvent(EventLayers.Gui);

            backEvent.addButton(KeyboardButtonCode.KC_LEFT);
            backEvent.FirstFrameUpEvent += eventManager =>
            {
                back();
            };
            eventContext.addEvent(backEvent);

            ButtonEvent zoomInEvent = new ButtonEvent(EventLayers.Gui);

            zoomInEvent.addButton(KeyboardButtonCode.KC_EQUALS);
            zoomInEvent.FirstFrameUpEvent += eventManager =>
            {
                zoomIn();
            };
            eventContext.addEvent(zoomInEvent);

            ButtonEvent zoomOutEvent = new ButtonEvent(EventLayers.Gui);

            zoomOutEvent.addButton(KeyboardButtonCode.KC_MINUS);
            zoomOutEvent.FirstFrameUpEvent += eventManager =>
            {
                zoomOut();
            };
            eventContext.addEvent(zoomOutEvent);

            ButtonEvent closeEvent = new ButtonEvent(EventLayers.Gui);

            closeEvent.addButton(KeyboardButtonCode.KC_ESCAPE);
            closeEvent.FirstFrameUpEvent += eventManager =>
            {
                ThreadManager.invoke(close); //Delay so we do not modify the input collection
            };
            eventContext.addEvent(closeEvent);

            foreach (Task task in additionalTasks.Tasks)
            {
                taskbar.addItem(new TaskTaskbarItem(task));
            }

            mvcContext.Blurred += (ctx) =>
            {
                guiManager.deactivateLink(SlideTaskbarName);
                guiManager.removeLinkFromChain(taskbarLink);
                GlobalContextEventHandler.disableEventContext(eventContext);
            };
            mvcContext.Focused += (ctx) =>
            {
                guiManager.addLinkToChain(taskbarLink);
                guiManager.pushRootContainer(SlideTaskbarName);
                setNavigationIcons();
                GlobalContextEventHandler.setEventContext(eventContext);
            };
            mvcContext.RemovedFromStack += (ctx) =>
            {
                taskbar.Dispose();
            };
        }