コード例 #1
0
        public static XDocument Load(string binPath)
        {
            FileInfo binInfo  = new FileInfo(binPath);
            string   baseName = Path.GetFileNameWithoutExtension(binInfo.Name);
            string   tempName = string.Format("{0}-{1}.bin", baseName, Utilities.StaticRandom.Instance.Next(10000, 99999));

            string tempBinPath;
            string tempXmlPath;

            if (!binPath.StartsWith(Utilities.GetTempDir()))
            {
                tempBinPath = Path.Combine(Utilities.GetTempDir(), tempName);
                tempXmlPath = Path.ChangeExtension(tempBinPath, "xml");
                Utilities.RemoveFile(tempBinPath);
                Utilities.RemoveFile(tempXmlPath);

                File.Copy(binPath, tempBinPath);
            }
            else
            {
                tempBinPath = binPath;
                tempXmlPath = Path.ChangeExtension(tempBinPath, "xml");
            }

            Process serz = InvokeSerz(tempBinPath);

            serz.WaitForExit();

            return(XmlDocumentLoader.Load(tempXmlPath));
        }
コード例 #2
0
        public static List <string> GetNumberingList(string location)
        {
            if (_numberingListCache.ContainsKey(location))
            {
                return(_numberingListCache[location]);
            }
            var dcsvPath = Path.Combine(Properties.Settings.Default.TsPath, "Assets", location) + ".dcsv";

            if (!File.Exists(dcsvPath))
            {
                var components = location.Split('\\');
                if (components.Length < 3)
                {
                    throw new Exception("Numbering list not found");
                }
                var  apDirectory = Path.Combine(Properties.Settings.Default.TsPath, "Assets", components[0], components[1]);
                var  apFiles     = Directory.GetFiles(apDirectory, "*.ap", SearchOption.TopDirectoryOnly);
                bool found       = false;
                foreach (var ap in apFiles)
                {
                    try
                    {
                        var zipFile   = ZipFile.Read(ap);
                        var dcsvEntry = zipFile.Where(entry => entry.FileName == string.Join("/", components.Skip(2)) + ".dcsv").FirstOrDefault();
                        if (dcsvEntry == null)
                        {
                            continue;
                        }
                        dcsvPath = Path.Combine(Utilities.GetTempDir(), Path.GetFileName(dcsvPath));
                        zipFile.FlattenFoldersOnExtract = true;
                        Utilities.RemoveFile(dcsvPath);
                        dcsvEntry.Extract(Utilities.GetTempDir());
                        found = true;
                        break;
                    }
                    catch (Exception)
                    {
                    }
                }
                if (!found)
                {
                    throw new Exception("Numbering list not found");
                }
            }
            List <string>          list      = new List <string>();
            XDocument              dcsv      = XmlDocumentLoader.Load(dcsvPath);
            IEnumerable <XElement> cCSVItems = dcsv.Descendants("cCSVItem");

            foreach (XElement cCSVItem in cCSVItems)
            {
                if (cCSVItem.Element("Name") == null)
                {
                    continue;
                }
                list.Add(cCSVItem.Element("Name").Value);
            }
            _numberingListCache[location] = list;
            return(_numberingListCache[location]);
        }
コード例 #3
0
ファイル: Scenario.cs プロジェクト: rw2-hub/LocoSwap
        public void Load(string routeId, string id)
        {
            RouteId = routeId;
            Id      = id;

            try
            {
                ScenarioProperties = XmlDocumentLoader.Load(Path.Combine(ScenarioDirectory, "ScenarioProperties.xml"));
                XElement displayName = ScenarioProperties.XPathSelectElement("/cScenarioProperties/DisplayName/Localisation-cUserLocalisedString");
                Name = Utilities.DetermineDisplayName(displayName);
            }
            catch (Exception e)
            {
                Log.Warning("Exception caught when trying to load ScenarioProperties.xml: {0}", e);
                throw new Exception("Malformed ScenarioProperties.xml file!");
            }
        }