Ejemplo n.º 1
0
        static public FileTool LoadFile(UniFile file, FileTypePlugin plugin)
        {
            if (!AllowOpeningFilesTwice && s_openTools.ContainsKey(file.FilePath))
            {
                return(s_openTools[file.FilePath]);
            }
            FileTool tool;

            try
            {
                tool = plugin.LoadFile(file);
            }
            catch
            {
                UIHelper.ShowError("Can't open the selected file " + file.FileName + " using " + plugin.PluginName + ", version: " + plugin.Version + ".");
                return(null);
            }
            tool.OnSaved += FileTool_OnSaved;
            if (s_openTools.ContainsKey(file.FilePath))
            {
                s_openTools.Add(file.FilePath, tool);
            }
            if (FileLoaded != null)
            {
                FileLoaded(file, tool);
            }
            return(tool);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Launches an instance of the plugin associated with the extension of the specified file name.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="infile"></param>
        /// <exception cref="CopeException">Will throw an exception if there's no plugin for this file type.</exception>
        /// <returns></returns>
        static public FileTool LaunchFromExt(string fileName, UniFile infile)
        {
            string ext = fileName.SubstringAfterLast('.').ToLower();

            if (!s_fileTypes.ContainsKey(ext))
            {
                throw new CopeException("Unknown file extension: " + ext);
            }

            FileTypePlugin plugin = s_fileTypes[ext];

            try
            {
                return(plugin.LoadFile(infile));
            }
            catch (Exception e)
            {
                Type t = plugin.GetType();
                LoggingManager.SendMessage("FileTypeManager - Error launching plugin " + t.FullName);
                LoggingManager.HandleException(e);
                throw new CopeException(e, "Error launching plugin " + t.FullName + ": " + e.Message);
            }
        }