Example #1
0
        /// <summary>
        /// Makes a pretty output of the ScriptReturnData. Populates the InstallFiles list
        /// and does a lot of background sorting and matching for you. Will return null
        /// if CancelInstall is true
        /// </summary>
        /// <param name="copy">Wether or not to also do the CopyData/Plugins methods</param>
        /// <param name="omod">The OMOD file</param>
        /// <param name="dataPath">The dataPath with extracted data files</param>
        /// <param name="pluginsPath">The pluginsPath with extracted plugins files</param>
        /// <returns></returns>
        public ScriptReturnData Pretty(bool copy, ref OMOD omod, ref string pluginsPath, ref string dataPath)
        {
            if (CancelInstall)
            {
                return(null);
            }

            var filesPlugins = new List <string>();
            var filesData    = new List <string>();

            if (InstallAllPlugins)
            {
                foreach (var s in omod.GetPluginList())
                {
                    if (!s.Contains("\\"))
                    {
                        filesPlugins.Add(s);
                    }
                }
            }
            foreach (var s in InstallPlugins)
            {
                if (!Framework.strArrayContains(filesPlugins, s))
                {
                    filesPlugins.Add(s);
                }
            }
            foreach (var s in IgnorePlugins)
            {
                Framework.strArrayRemove(filesPlugins, s);
            }

            if (copy)
            {
                foreach (var scd in CopyPlugins)
                {
                    if (!File.Exists(Path.Combine(pluginsPath, scd.CopyFrom)))
                    {
                        break;
                    }
                    if (scd.CopyFrom != scd.CopyTo)
                    {
                        if (File.Exists(Path.Combine(pluginsPath, scd.CopyTo)))
                        {
                            File.Delete(Path.Combine(pluginsPath, scd.CopyTo));
                        }
                        File.Copy(Path.Combine(pluginsPath, scd.CopyFrom), Path.Combine(pluginsPath, scd.CopyTo));
                    }
                    if (!Framework.strArrayContains(filesPlugins, scd.CopyTo))
                    {
                        filesPlugins.Add(scd.CopyTo);
                    }
                }
            }

            if (InstallAllData)
            {
                foreach (var s in omod.GetDataFileList())
                {
                    filesData.Add(s);
                }
            }
            foreach (var s in InstallData)
            {
                if (!Framework.strArrayContains(filesData, s))
                {
                    filesData.Add(s);
                }
            }
            foreach (var s in IgnoreData)
            {
                Framework.strArrayRemove(filesData, s);
            }

            if (copy)
            {
                foreach (var scd in CopyDataFiles)
                {
                    if (!File.Exists(Path.Combine(dataPath, scd.CopyFrom)))
                    {
                        break;
                    }
                    if (scd.CopyFrom != scd.CopyTo)
                    {
                        var dirName = Path.GetDirectoryName(Path.Combine(dataPath, scd.CopyTo));
                        if (!Directory.Exists(dirName))
                        {
                            Directory.CreateDirectory(dirName);
                        }
                        if (File.Exists(Path.Combine(dataPath, scd.CopyTo)))
                        {
                            File.Delete(Path.Combine(dataPath, scd.CopyTo));
                        }
                        File.Copy(Path.Combine(dataPath, scd.CopyFrom), Path.Combine(dataPath, scd.CopyTo));
                    }
                    if (!Framework.strArrayContains(filesData, scd.CopyTo))
                    {
                        filesData.Add(scd.CopyTo);
                    }
                }
            }

            for (var i = 0; i < filesData.Count; i++)
            {
                if (filesData[i].StartsWith("\\"))
                {
                    filesData[i] = filesData[i].Substring(1);
                }
                var currentFile = Path.Combine(dataPath, filesData[i]);
                if (!File.Exists(currentFile))
                {
                    filesData.RemoveAt(i--);
                }
            }

            for (var i = 0; i < filesPlugins.Count; i++)
            {
                if (InstallPlugins[i].StartsWith("\\"))
                {
                    filesPlugins[i] = filesPlugins[i].Substring(1);
                }
                var currentFile = Path.Combine(pluginsPath, filesPlugins[i]);
                if (!File.Exists(currentFile))
                {
                    filesPlugins.RemoveAt(i--);
                }
            }

            foreach (var s in filesData)
            {
                InstallFiles.Add(new InstallFile(Path.Combine(dataPath, s), s));
            }
            foreach (var s in filesPlugins)
            {
                InstallFiles.Add(new InstallFile(Path.Combine(pluginsPath, s), s));
            }

            InstallAllData    = false;
            InstallAllPlugins = false;
            InstallData       = null;
            InstallPlugins    = null;
            IgnoreData        = null;
            IgnorePlugins     = null;
            if (copy)
            {
                CopyDataFiles = null;
                CopyPlugins   = null;
            }


            return(this);
        }
Example #2
0
        /// <summary>
        /// Makes the current ScriptReturnData "pretty" by clearing all Install*, Ignore* and Copy*
        /// HashSets and populating <see cref="InstallFiles"/>. That HashSet will contain <see cref="InstallFile"/>
        /// which tells you where what file goes.
        /// </summary>
        /// <param name="omod">The current OMOD</param>
        /// <param name="pluginsPath">Path to the extract plugins</param>
        /// <param name="dataPath">Path to the extract data files</param>
        public void Pretty(OMOD omod, string dataPath, string pluginsPath)
        {
            if (CancelInstall)
            {
                return;
            }

            InstallFiles = new HashSet <InstallFile>();

            var filesPlugins = new HashSet <string>();
            var filesData    = new HashSet <string>();

            if (pluginsPath != null)
            {
                if (InstallAllPlugins)
                {
                    omod.AllPlugins.Where(s => !s.Contains("\\")).Do(p => filesPlugins.Add(p));
                }
                InstallPlugins.Where(p => !filesPlugins.Contains(p)).Do(p => filesPlugins.Add(p));
                filesPlugins.RemoveWhere(p => IgnorePlugins.Contains(p));

                CopyPlugins.Where(p => File.Exists(Path.Combine(pluginsPath, p.CopyFrom)) && p.CopyTo != p.CopyFrom).Do(p =>
                {
                    var pathTo   = Path.Combine(pluginsPath, p.CopyTo);
                    var pathFrom = Path.Combine(pluginsPath, p.CopyFrom);
                    if (File.Exists(pathTo))
                    {
                        File.Delete(pathTo);
                    }
                    File.Copy(pathFrom, pathTo);
                    if (!filesPlugins.Contains(p.CopyTo))
                    {
                        filesPlugins.Add(p.CopyTo);
                    }
                });

                filesPlugins.Do(p =>
                {
                    if (p.StartsWith("\\"))
                    {
                        p = p.Substring(1);
                    }
                    var currentFile = Path.Combine(pluginsPath, p);
                    if (File.Exists(currentFile))
                    {
                        InstallFiles.Add(new InstallFile(currentFile, p));
                    }
                });
            }

            if (InstallAllData)
            {
                omod.AllPlugins.Do(d => filesData.Add(d));
            }
            InstallData.Where(d => !filesData.Contains(d)).Do(d => filesData.Add(d));
            filesData.RemoveWhere(d => IgnoreData.Contains(d));

            CopyDataFiles.Where(d => File.Exists(Path.Combine(dataPath, d.CopyFrom)) && d.CopyFrom != d.CopyTo).Do(d =>
            {
                var pathTo   = Path.Combine(dataPath, d.CopyTo);
                var pathFrom = Path.Combine(dataPath, d.CopyFrom);
                var dirName  = Path.GetDirectoryName(pathTo);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }
                if (File.Exists(pathTo))
                {
                    File.Delete(pathTo);
                }
                File.Copy(pathFrom, pathTo);
                if (!filesData.Contains(d.CopyTo))
                {
                    filesData.Add(d.CopyTo);
                }
            });

            filesData.Do(d =>
            {
                if (d.StartsWith("\\"))
                {
                    d = d.Substring(1);
                }
                var currentFile = Path.Combine(dataPath, d);
                if (File.Exists(currentFile))
                {
                    InstallFiles.Add(new InstallFile(currentFile, d));
                }
            });

            InstallAllData    = false;
            InstallAllPlugins = false;
            InstallData       = null;
            InstallPlugins    = null;
            IgnoreData        = null;
            IgnorePlugins     = null;
            CopyDataFiles     = null;
            CopyPlugins       = null;
        }