示例#1
0
        public ActionResult Create(PluginCreateOrEditViewModel vmObj)
        {
            var uf = FileUploadHandler.UploadedFiles;

            return(CreateUsingViewModel(vmObj, (parent) =>
            {
                //Convert the ViewModel to DB Object (Model)
                var dbObj = new Plugin()
                {
                    //Id = vmObj.Id,
                    Name = vmObj.Name,
                    Description = vmObj.Description
                };
                var files = AddFiles(vmObj.Files);
                foreach (var file in files)
                {
                    var pluginFile = new PluginFile()
                    {
                        Plugin = dbObj,
                        File = file
                    };
                    db.Files.Add(file);
                    db.PluginFiles.Add(pluginFile);
                    dbObj.Files.Add(pluginFile);
                }
                return dbObj;
            }));
        }
示例#2
0
        public void Constructor_InitializesProperties()
        {
            var pluginFile = new PluginFile(filePath: "a", state: new Lazy <PluginFileState>(() => PluginFileState.Valid));

            Assert.Equal("a", pluginFile.Path);
            Assert.Equal(PluginFileState.Valid, pluginFile.State.Value);
        }
示例#3
0
        private void UninstallButtonBase_Click(object sender, RoutedEventArgs e)
        {
            Button     button     = sender as Button;
            PluginFile pluginFile = button?.DataContext as PluginFile;

            pluginFile?.Uninstall();
        }
        /// <summary>
        /// Downloads the plugins for the given platform and the given plugin names.
        /// </summary>
        public List <PluginFile> DownloadPlugins(Platform platform, IEnumerable <string> pluginNames)
        {
            using (var dataContext = Database.DataContextFactory.CreateReadOnlyDataContext())
            {
                var    requestedFiles   = new List <PluginFile>();
                string lastPluginLoaded = "[plugin unkown]";

                foreach (string pluginName in pluginNames)
                {
                    //safe pluginname for logging
                    lastPluginLoaded = pluginName;

                    //load plugin
                    PluginFile plugin = Manager.PluginManager.Instance.DownloadPlugin(platform, pluginName);
                    if (plugin != null)
                    {
                        requestedFiles.Add(plugin);
                    }
                    else
                    {
                        // Log the exception
                        MISD.Core.Logger.Instance.WriteEntry("PluginManager_DownloadPlugins: Can't load the plugin file " + lastPluginLoaded + " for platform " + platform + ".", LogType.Exception);

                        // Return an empty list.
                        requestedFiles.Clear();
                        return(requestedFiles);
                    }
                }
                return(requestedFiles);
            }
        }
示例#5
0
        public void SetUp()
        {
            session = new Session(Games.SSE, new SessionOptions());
            var pluginPath = TestHelpers.FixturePath("AllRecords.esp");

            plugin = pluginManager.LoadPlugin(pluginPath);
        }
示例#6
0
        /// <summary>
        /// Store a plugin to the assembly folder
        /// </summary>
        /// <param name="plugin">Plugin to store</param>
        /// /// <returns>Result of this method</returns>
        private Boolean StorePlugin(PluginFile plugin)
        {
            // Convert the Base64 UUEncoded input into binary output.
            byte[] binaryData;
            try
            {
                binaryData = System.Convert.FromBase64String(plugin.FileAsBase64);
            }
            catch (System.ArgumentNullException)
            {
                //Logging "Base 64 string is null."
                var messageEx1 = new StringBuilder();
                messageEx1.Append(ServerConnection.GetWorkstationName() + "_PluginManager_StorePlugin: ");
                messageEx1.Append("Can't store the plugin. " + "Base 64 string is null.");
                ServerConnection.WriteLog(messageEx1.ToString(), LogType.Exception);
                return(false);
            }
            catch (System.FormatException)
            {
                //Logging "Base 64 string length is not 4 or is not an even multiple of 4."
                var messageEx2 = new StringBuilder();
                messageEx2.Append(
                    ServerConnection.GetWorkstationName() +
                    "Base 64 string length is not 4 or is not an even multiple of 4.");
                messageEx2.Append("Can't store the plugin. " + "Base 64 string is null.");
                ServerConnection.WriteLog(messageEx2.ToString(), LogType.Exception);
                return(false);
            }

            // Write out the decoded data.
            System.IO.FileStream outFile;
            string outputFileName =
                pluginPath +
                Path.DirectorySeparatorChar +
                plugin.FileName;

            WorkstationLogger.WriteLog("Storing plugin into: " + outputFileName);

            try
            {
                outFile = new System.IO.FileStream(outputFileName,
                                                   System.IO.FileMode.Create,
                                                   System.IO.FileAccess.Write);
                outFile.Write(binaryData, 0, binaryData.Length);
                outFile.Close();
            }
            catch (System.Exception exp)
            {
                //Logging
                //Logging "Base 64 string is null."
                var messageEx3 = new StringBuilder();
                messageEx3.Append(ServerConnection.GetWorkstationName() + "_PluginManager_StorePlugin: ");
                messageEx3.Append("Can't store the plugin. " + exp.ToString());
                ServerConnection.WriteLog(messageEx3.ToString(), LogType.Exception);
                return(false);
            }

            return(true);
        }
示例#7
0
 public static byte FileToOrdinal(
     this IMasterManager m, PluginFile file, bool useCurrentMasters
     )
 {
     return(useCurrentMasters
         ? m.masters.FileToOrdinal(file)
         : m.originalMasters.FileToOrdinal(file));
 }
示例#8
0
        public void Constructor_InitializesProperties()
        {
            var pluginFile = new PluginFile(filePath: "a", state: new Lazy <PluginFileState>(() => PluginFileState.InvalidEmbeddedSignature));

            var result = new PluginDiscoveryResult(pluginFile);

            Assert.Same(pluginFile, result.PluginFile);
        }
 public static void Main(string[] args)
 {
     using (var input = File.OpenRead(@"Update.esm"))
     {
         var plugin = new PluginFile();
         plugin.Deserialize(input);
     }
 }
示例#10
0
        public void SetUp()
        {
            session = new Session(Games.TES5, new SessionOptions {
            });
            var pluginPath = TestHelpers.FixturePath("EmptyPlugin.esp");

            plugin = pluginManager.LoadPluginHeader(pluginPath);
            Assert.IsNotNull(plugin);
        }
示例#11
0
 public static void AddMaster(this IMasterManager m, PluginFile file)
 {
     if (m.HasMaster(file))
     {
         return;
     }
     m.mastersChanged = true;
     m.masters.Add(file);
 }
示例#12
0
        public void SetUp()
        {
            session = new Session(Games.SSE, new SessionOptions {
            });
            var pluginPath = TestHelpers.FixturePath("ARecords.esp");

            plugin = pluginManager.LoadPlugin(pluginPath);
            Assert.IsNotNull(plugin);
        }
        public void Constructor_InitializesProperties()
        {
            var pluginFile = new PluginFile(filePath: "a", state: PluginFileState.InvalidEmbeddedSignature);

            var result = new PluginDiscoveryResult(pluginFile, message: "b");

            Assert.Same(pluginFile, result.PluginFile);
            Assert.Equal("b", result.Message);
        }
示例#14
0
 public void SetUp()
 {
     session    = new Session(Games.TES5, new SessionOptions());
     pluginPath = TestHelpers.FixturePath("Skyrim.esm");
     Assert.IsTrue(File.Exists(pluginPath),
                   "Put Skyrim.esm in the fixtures directory to run these tests."
                   );
     watch.Start();
     plugin = pluginManager.LoadPlugin(pluginPath);
     watch.Stop();
 }
示例#15
0
        public PluginFile LoadPluginHeader(string filePath)
        {
            var options = new PluginFileOptions {
                temporary = true
            };
            var        filename = Path.GetFileName(filePath);
            PluginFile plugin   = new PluginFile(session, filename, options);

            new PluginFileSource(filePath, plugin);
            plugin.pluginDef.ReadFileHeader(plugin);
            return(plugin);
        }
示例#16
0
            private static IEnumerable <PluginDiscoveryResult> GetPluginDiscoveryResults(List <KeyValuePair <string, PluginFileState> > plugins)
            {
                var results = new List <PluginDiscoveryResult>();

                foreach (var plugin in plugins)
                {
                    var file = new PluginFile(plugin.Key, new Lazy <PluginFileState>(() => plugin.Value));
                    results.Add(new PluginDiscoveryResult(file));
                }

                return(results);
            }
示例#17
0
        internal void ReadFileHeader(PluginFile plugin)
        {
            var source = plugin.source;

            if (plugin.header != null)
            {
                return;
            }
            plugin.header = MainRecord.Read(plugin, source, Signatures.TES4);
            plugin.InitMasters();
            plugin.InitRecordMaps();
        }
示例#18
0
        internal void ReadGroups(PluginFile plugin)
        {
            var source    = plugin.source;
            var endOffset = source.fileSize - 1;

            while (source.stream.Position < endOffset)
            {
                GroupRecord.Read(plugin, source);
            }
            plugin.internalElements.TrimExcess();
            plugin.SortRecords();
        }
示例#19
0
 public void AddFile(PluginFile plugin)
 {
     if (plugin.options.temporary)
     {
         return;
     }
     plugins.Add(plugin);
     if (!session.options.emulateGlobalLoadOrder)
     {
         return;
     }
     AssignLoadOrder(plugin);
 }
示例#20
0
 public T Map <T>(PluginFile plugin, string packageId, string packageVersion) where T : PluginRecord
 {
     return((T) new PluginRecord {
         Id = plugin.Id,
         Description = plugin.Description,
         Icon = plugin.Icon,
         Name = plugin.Name,
         Path = plugin.Path,
         PackageId = packageId,
         Type = plugin.Type,
         Format = plugin.Format,
         PackageVersion = packageVersion
     });
 }
示例#21
0
        public PluginFile LoadPlugin(string filePath)
        {
            var options  = new PluginFileOptions();
            var filename = Path.GetFileName(filePath);

            logger.Info($"Loading plugin {filename}");
            PluginFile plugin = new PluginFile(session, filename, options);

            new PluginFileSource(filePath, plugin);
            plugin.container = root;
            plugin.pluginDef.ReadFileHeader(plugin);
            plugin.pluginDef.ReadGroups(plugin);
            return(plugin);
        }
示例#22
0
 public void AssignLoadOrder(PluginFile plugin)
 {
     if (ShouldUseLightPluginSlot(plugin))
     {
         lightPluginSlots.Add(
             new LightPluginSlot(plugin, nextLightPluginIndex)
             );
     }
     else
     {
         fullPluginSlots.Add(
             new FullPluginSlot(plugin, nextFullPluginIndex)
             );
     }
 }
示例#23
0
 private static void ForEachFormIdElement(
     PluginFile file, Action <ValueElement> callback
     )
 {
     file.ForEachElement((Element element) => {
         if (element is Container)
         {
             return(element.def.canContainFormIds);
         }
         if (element is ValueElement v && v.def.canContainFormIds)
         {
             callback(v);
         }
         return(false);
     });
 }
            private static IEnumerable <PluginDiscoveryResult> GetPluginDiscoveryResults(string pluginPaths)
            {
                var results = new List <PluginDiscoveryResult>();

                if (string.IsNullOrEmpty(pluginPaths))
                {
                    return(results);
                }

                foreach (var path in pluginPaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var state = path == "a" ? PluginFileState.Valid : PluginFileState.InvalidEmbeddedSignature;
                    var file  = new PluginFile(path, new Lazy <PluginFileState>(() => state));
                    results.Add(new PluginDiscoveryResult(file));
                }

                return(results);
            }
示例#25
0
        public SimplePluginExample() : base()
        {
            Plugin Root = new Plugin(ContentType.Movies);
            //
            PluginFolder MyFirstDirectory  = Root.CreateDirectory("My First Directory");
            PluginFolder MySecondDirectory = Root.CreateDirectory("My Second Directory");
            PluginFile   MyFirstFile       = Root.CreateFile("My File");
            //
            PluginFile MyFirstDirectory_MyFile = MyFirstDirectory.CreateFile("My File");

            //
            MyFirstDirectory.OnSelect        += OnSelect;
            MySecondDirectory.OnSelect       += OnSelect;
            MyFirstFile.OnSelect             += OnSelect;
            MyFirstDirectory_MyFile.OnSelect += OnSelect;
            //
            Root.Tread();
        }
示例#26
0
        private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "插件文件|*.dll|插件配置文件|*.addin";
            if (open.ShowDialog() == DialogResult.OK)
            {
                PluginFile file = new PluginFile();
                file.FileName = open.SafeFileName;
                file.FilePath = open.FileName;
                if (open.FilterIndex == 2)
                {
                    file.IsAddInFile = true;
                }
                FileInfos.Add(file);
            }
            Bind();
        }
示例#27
0
        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TreeListNode node = treeList1.FocusedNode;

            if (node != null)
            {
                string fileName = node.GetValue("FileName").ToString();
                if (!string.IsNullOrEmpty(fileName))
                {
                    PluginFile file = FileInfos.FirstOrDefault(o => o.FileName == fileName);
                    if (file != null)
                    {
                        FileInfos.Remove(file);
                    }
                    Bind();
                }
            }
        }
示例#28
0
        internal static PluginFile GetOrAddPluginFile(this ScriptReturnData srd, string file, OMOD omod, bool byInput = true)
        {
            var filePath   = file.MakePath();
            var pluginFile = srd.PluginFiles.FirstOrDefault(x => byInput
                ? x.Input.Name.Equals(filePath, StringComparison.OrdinalIgnoreCase)
                : x.Output.Equals(filePath, StringComparison.OrdinalIgnoreCase));

            if (pluginFile != null)
            {
                return(pluginFile);
            }

            var compressedFile = GetPluginFile(omod, filePath);

            pluginFile = new PluginFile(compressedFile);
            srd.PluginFiles.Add(pluginFile);

            return(pluginFile);
        }
示例#29
0
 //[ValidateAntiForgeryToken]
 public ActionResult AddFileToObject(PluginFileViewModel pluginFile)
 {
     if (pluginFile != null)
     {
         var dbObj = db.Set <Plugin>().Where(x => x.Id == pluginFile.PluginId).FirstOrDefault();
         if (dbObj != null)
         {
             var files = AddFiles(pluginFile.Files);
             //var file = files.Where(x => !string.IsNullOrEmpty(x.Name)).FirstOrDefault();
             //if (file != null)
             //{
             SimpleCMS.Models.File retFile = null;
             foreach (var file in files)
             {
                 var PluginFile = new PluginFile()
                 {
                     Plugin = dbObj,
                     File   = file,
                 };
                 db.Files.Add(file);
                 db.Set <PluginFile>().Add(PluginFile);
                 dbObj.Files.Add(PluginFile);
                 retFile = file;
                 //}
                 try
                 {
                     db.SaveChanges();
                     //return new HttpStatusCodeResult(HttpStatusCode.OK);
                     //Response.ContentType = file.ContentType;
                     //Response.Headers.Add("ContentType", file.ContentType);
                     //Response.Headers.Add("ContentLength", "" + file.Length);
                     //return base.File(file.Data, file.ContentType);
                 }
                 catch (Exception)
                 {
                 }
             }
             return(Json(retFile));
         }
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }
        /// <summary>
        /// Store a plugin to the assembly folder
        /// </summary>
        /// <param name="plugin">Plugin to store</param>
        /// /// <returns>Result of this method</returns>
        private Boolean StorePlugin(PluginFile plugin)
        {
            // Convert the Base64 UUEncoded input into binary output.
            byte[] binaryData;
            try
            {
                binaryData = System.Convert.FromBase64String(plugin.FileAsBase64);
            }
            catch (System.ArgumentNullException e)
            {
                WorkstationLogger.Instance.WriteLog(ServerConnection.Instance.GetWorkstationName() + "_PluginManager_StorePlugin: " + e.Message, LogType.Exception, true);
                return(false);
            }
            catch (System.FormatException e)
            {
                WorkstationLogger.Instance.WriteLog(ServerConnection.Instance.GetWorkstationName() + "_PluginManager_StorePlugin: " + e.Message, LogType.Exception, true);
                return(false);
            }

            // Write out the decoded data.
            System.IO.FileStream outFile;
            string outputFileName =
                Properties.Settings.Default.pluginPath + Path.DirectorySeparatorChar +
                plugin.FileName;

            try
            {
                outFile = new System.IO.FileStream(outputFileName,
                                                   System.IO.FileMode.Create,
                                                   System.IO.FileAccess.Write);
                outFile.Write(binaryData, 0, binaryData.Length);
                outFile.Close();
            }
            catch (System.Exception e)
            {
                WorkstationLogger.Instance.WriteLog(ServerConnection.Instance.GetWorkstationName() + "_PluginManager_StorePlugin: " + e.Message, LogType.Exception, true);
                return(false);
            }

            return(true);
        }
示例#31
0
        /// <summary>
        /// Installs the given <see cref="OptionsForm.PluginFile"/>, and activates any
        /// esm/esp files it encompasses as requested.
        /// </summary>
        /// <param name="plfFile">The file to install.</param>
        /// <param name="booActivate">Whether or not to activate any esp/esm files.</param>
        /// <returns><lang cref="false"/> if the user cancelled the install;
        /// <lang cref="true"/> otherwise.</returns>
        protected bool InstallPluginFile(PluginFile plfFile, bool booActivate)
        {
            string strSource = plfFile.Source;
            string strDest = plfFile.Destination;
            m_bwdProgress.ItemMessage = "Installing " + (String.IsNullOrEmpty(strDest) ? strSource : strDest);
            if (plfFile.IsFolder)
            {
                CopyDataFolder(strSource, strDest);

                if (m_bwdProgress.Cancelled())
                    return false;

                //if the destination length is greater than 0, then nothing in
                // this folder is directly in the Data folder as so cannot be
                // activated
                if (strDest.Length == 0)
                {
                    List<string> lstFiles = GetFomodFolderFileList(strSource);
                    m_bwdProgress.ItemMessage = "Activating " + (String.IsNullOrEmpty(strDest) ? strSource : strDest);
                    m_bwdProgress.ItemProgress = 0;
                    m_bwdProgress.ItemProgressMaximum = lstFiles.Count;

                    if (!strSource.EndsWith("/"))
                        strSource += "/";
                    foreach (string strFile in lstFiles)
                    {
                        if (strFile.ToLowerInvariant().EndsWith(".esm") || strFile.ToLowerInvariant().EndsWith(".esp"))
                        {
                            string strNewFileName = strFile.Substring(strSource.Length, strFile.Length - strSource.Length);
                            m_misInstallScript.SetPluginActivation(strNewFileName, booActivate);
                        }
                        if (m_bwdProgress.Cancelled())
                            return false;
                        m_bwdProgress.StepItemProgress();
                    }
                }
            }
            else
            {
                m_bwdProgress.ItemProgress = 0;
                m_bwdProgress.ItemProgressMaximum = 2;

                m_misInstallScript.CopyDataFile(strSource, strDest);

                m_bwdProgress.StepItemProgress();

                if (String.IsNullOrEmpty(strDest))
                {
                    if (strSource.ToLowerInvariant().EndsWith(".esm") || strSource.ToLowerInvariant().EndsWith(".esp"))
                        m_misInstallScript.SetPluginActivation(strSource, booActivate);
                }
                else if (strDest.ToLowerInvariant().EndsWith(".esm") || strDest.ToLowerInvariant().EndsWith(".esp"))
                    m_misInstallScript.SetPluginActivation(strDest, booActivate);

                m_bwdProgress.StepItemProgress();
            }
            return true;
        }