示例#1
0
        /// <summary>From a list of file creates a maping between a jsonvalue relative path and the actual file</summary>
        /// <param name="files">list of all files accesible</param>
        /// <param name="referencedRessources">Ressources referenced</param>
        public static Dictionary <JsonValue, string> FindFromFiles(IEnumerable <ISSGenericFile> files, IEnumerable <JsonValue> referencedRessources)
        {
            Dictionary <JsonValue, string> result = new Dictionary <JsonValue, string>();

            foreach (JsonValue reference in referencedRessources)
            {
                SSRelativeUrl  url      = new SSRelativeUrl(reference.ToString());
                ISSGenericFile matching = FindFromFiles(files, url);
                SSFullUrl      full     = matching.SourceMod.ModUrl + url;
                result.Add(reference, full.ToString());
            }
            return(result);
        }
示例#2
0
        static void Main()
        {
            SSBaseUrl SSUrl   = new SSBaseUrl("E:\\SS\\Starsector");
            SSLinkUrl CoreUrl = new SSLinkUrl("starsector-core");
            //SSLinkUrl TahlanUrl = new SSLinkUrl("mods\\tahlan");
            SSLinkUrl     SWPUrl      = new SSLinkUrl("mods\\Ship and Weapon Pack");
            SSRelativeUrl shipdataUrl = new SSRelativeUrl("data\\hulls\\ship_data.csv");

            SSFullUrl  dataurl = SSUrl + SWPUrl + shipdataUrl;
            CSVContent content;

            using (StreamReader sr = File.OpenText(dataurl.ToString()))
            {
                content = CSVContent.ExtractFromText(sr);
            }

            dataurl = SSUrl + CoreUrl + shipdataUrl;
            CSVContent content2;

            using (StreamReader sr = File.OpenText(dataurl.ToString()))
            {
                content2 = CSVContent.ExtractFromText(sr);
            }

            CSVContent content3 = CSVContent.Merge(new[] { content, content2 });
            var        b        = content3.GetLineByColumnValue("id", "swp_archon")["tags"];
            //SSBaseUrl ModFolderPath = SSUrl + "mods";
            //DirectoryInfo ModsDirectory = new DirectoryInfo(ModFolderPath.ToString());
            //IEnumerable<DirectoryInfo> ModsEnumerable = ModsDirectory.EnumerateDirectories();

            SSDirectory directory = new SSDirectory();

            directory.InstallationUrl = SSUrl;
            directory.ReadMods();
            directory.PopulateMergedCollections();
            VariantsRessources  variant     = new VariantsRessources(directory);
            ShipHullRessources  ship        = new ShipHullRessources(directory, variant);
            BPPackageRessources BPRessource = new BPPackageRessources(directory, ship);
            //SSDirectory test = new SSDirectory(SSUrl);
            //SSModWritable target = new SSModWritable();
            //target.ModUrl = SSUrl + new SSLinkUrl("mods\\lepg");
            //test.ReadMods("lepg");
            //test.PopulateMergedCollections();

            //FactionEditor factionEditor = new FactionEditor(test);
            //List<SSFactionGroup> factions = factionEditor.GetFaction();
            //
        }
示例#3
0
        public void CopyTo(SSBaseLinkUrl newPath)
        {
            SSBaseUrl InstallationUrl = new SSBaseUrl(newPath.Base);
            SSFullUrl SourceUrl       = InstallationUrl + this.SourceMod.ModUrl.GetLink() + this.RelativeUrl;

            SSFullUrl TargetUrl = newPath + this.RelativeUrl;

            FileInfo sourceInfo = new FileInfo(SourceUrl.ToString());
            FileInfo targetInfo = new FileInfo(TargetUrl.ToString());

            if (targetInfo.Exists)
            {
                targetInfo = new FileInfo(TargetUrl.ToString() + SourceMod.ModName);
            }
            DirectoryInfo targetDir = targetInfo.Directory;

            if (!targetDir.Exists)
            {
                targetDir.Create();
            }
            sourceInfo.CopyTo(targetInfo.FullName);
        }
示例#4
0
        public override void WriteTo(SSBaseLinkUrl newPath)
        {
            SSBaseUrl InstallationUrl = new SSBaseUrl(newPath.Base);
            SSFullUrl TargetUrl       = newPath + this.RelativeUrl;
            //we do not merge core csv on the patch, it would be pointless
            List <SSCsv> NonCoreFile = (from SSCsv file in this.CommonFiles
                                        where file.SourceMod.CurrentType != ModType.Core
                                        select file).ToList <SSCsv>();

            if (NonCoreFile.Count() == 0)
            {
                return;
            }

            //we need to make sure the directory exist
            FileInfo      targetInfo = new FileInfo(TargetUrl.ToString());
            DirectoryInfo targetDir  = targetInfo.Directory;

            if (!targetDir.Exists)
            {
                targetDir.Create();
            }
            Factory csvFactory = new Factory();

            //csv merge requires us to match column tutle
            using (StreamWriter sw = File.CreateText(TargetUrl.ToString()))
            {
                CsvWriter             csvWriter  = new CsvWriter(sw, CultureInfo.InvariantCulture);
                List <List <String> > allHeaders = new List <List <string> >();
                foreach (SSCsv file in NonCoreFile)
                {
                    SSFullUrl SourceUrl = InstallationUrl + file.SourceMod.ModUrl.GetLink() + file.RelativeUrl;

                    using (StreamReader sr = File.OpenText(SourceUrl.ToString()))
                    {
                        IParser parser = csvFactory.CreateParser(sr, CultureInfo.InvariantCulture);
                        allHeaders.Add(parser.Read().ToList <string>());
                    }
                }
                List <string> finalHeaders = allHeaders.SelectMany(c => c).Distinct().ToList <string>();
                //lets write column title once
                foreach (string head in finalHeaders)
                {
                    csvWriter.WriteField(head);
                }
                csvWriter.NextRecord();

                for (int fileIndex = 0; fileIndex < NonCoreFile.Count; fileIndex++)
                {
                    SSFullUrl     SourceUrl            = InstallationUrl + NonCoreFile[fileIndex].SourceMod.ModUrl.GetLink() + NonCoreFile[fileIndex].RelativeUrl;
                    List <string> localHeaders         = allHeaders[fileIndex];
                    int[]         finalSourceFromLocal = new int[finalHeaders.Count];
                    for (int finalIndex = 0; finalIndex < finalHeaders.Count; finalIndex++)
                    {
                        finalSourceFromLocal[finalIndex] = localHeaders.FindIndex(c => c == finalHeaders[finalIndex]);
                    }
                    using (StreamReader sr = File.OpenText(SourceUrl.ToString()))
                    {
                        IParser parser = csvFactory.CreateParser(sr, CultureInfo.InvariantCulture);
                        parser.Configuration.AllowComments = true;
                        parser.Configuration.BadDataFound  = null;

                        string[] line = parser.Read(); //skip first line that contain headers
                        line = parser.Read();
                        while (line != null)
                        {
                            if (line.Count() != localHeaders.Count)
                            {
                                line = parser.Read();
                                continue;
                            }
                            foreach (int source in finalSourceFromLocal)
                            {
                                if (source == -1)
                                {
                                    csvWriter.WriteField("");
                                }
                                else
                                {
                                    csvWriter.WriteField(line[source]);
                                }
                            }
                            csvWriter.NextRecord();
                            line = parser.Read();
                        }
                    }
                }
            }
        }