private Dictionary <string, AssetListItem> CreateAssetLookup(AirportList airportList) { Dictionary <string, AssetListItem> assetList = new Dictionary <string, AssetListItem>(); int i = 0; foreach (var airport in airportList.Airports) { log.InfoFormat("Reading assets for airport {0} of {1}", i + 1, airportList.Airports.Count); var airportXPFullDirectory = DirectoryHelper.GetAirportXPFullDirectory(airport.AirportCode, XP2AFSConverterManager.Settings); var airportZipFilename = airportXPFullDirectory + @"\" + airport.AirportCode + ".zip"; var airportAFSFullDirectory = DirectoryHelper.GetAirportAFSFullDirectory(airport.AirportCode, XP2AFSConverterManager.Settings); if (File.Exists(airportZipFilename)) { // Parse the DST and DAT files var dsfFileLoader = new DSFFileLoader(); var dsfFile = dsfFileLoader.GetDSFFileFromXPZip(airport.AirportCode, airportZipFilename); foreach (var obj in dsfFile.Objects) { if (!assetList.ContainsKey(obj.Reference)) { var item = new AssetListItem(); item.Name = obj.Reference; assetList.Add(obj.Reference, item); } assetList[obj.Reference].Count++; } foreach (var poly in dsfFile.Polygons) { if (!assetList.ContainsKey(poly.Reference)) { var item = new AssetListItem(); item.Name = poly.Reference; assetList.Add(poly.Reference, item); } assetList[poly.Reference].Count++; } } i++; //if(i == 1000) //{ // break; //} } return(assetList); }
private void ConvertAirport(string icaoCode) { log.InfoFormat("Converting {0}", icaoCode); var airportXPFullDirectory = DirectoryHelper.GetAirportXPFullDirectory(icaoCode, XP2AFSConverterManager.Settings); var airportZipFilename = airportXPFullDirectory + @"\" + icaoCode + ".zip"; var airportFilename = airportXPFullDirectory + @"\airport.xml"; var airportSceneryFilename = airportXPFullDirectory + @"\scenery.xml"; var airportAFSFullDirectory = DirectoryHelper.GetAirportAFSFullDirectory(icaoCode, XP2AFSConverterManager.Settings); // Make sure the 'input' folder exists if (!Directory.Exists(airportAFSFullDirectory + @"\Input")) { Directory.CreateDirectory(airportAFSFullDirectory + @"\Input"); } var tscFilename = airportAFSFullDirectory + @"\Input\" + icaoCode + ".tsc"; var tocFilename = airportAFSFullDirectory + @"\Input\" + icaoCode + ".toc"; var tmcFilename = airportAFSFullDirectory + @"\Input\" + icaoCode + ".tmc"; if (File.Exists(airportZipFilename)) { // Parse the DST and DAT files var datFileLoader = new DATFileLoader(); var dsfFileLoader = new DSFFileLoader(); var datFile = datFileLoader.GetDATFileFromXPZip(icaoCode, airportZipFilename); var dsfFile = dsfFileLoader.GetDSFFileFromXPZip(icaoCode, airportZipFilename); // Create empty AFS files var tscFile = new TSCFile(); var tocFile = new TOCFile(); var tmcFile = new TMCFile(); // Convert the X-Plane files this.datConverter.Convert(datFile, tscFile, tocFile); this.dsfConverter.Convert(dsfFile, tscFile, tocFile); // Update the TMC file this.UpdateTMCFile(tmcFile, airportAFSFullDirectory); // Get strings of the AFS files var tscFileString = tscFile.ToString(); var tocFileString = tocFile.ToString(); var tmcFileString = tmcFile.ToString(); if (!Directory.Exists(airportAFSFullDirectory)) { Directory.CreateDirectory(airportAFSFullDirectory); } // Write the AFS files File.WriteAllText(tscFilename, tscFileString); File.WriteAllText(tocFilename, tocFileString); File.WriteAllText(tmcFilename, tmcFileString); var maxScriptGenerator = new MaxScriptGenerator(); maxScriptGenerator.GenerateScripts(icaoCode, datFile, dsfFile, tscFile, airportAFSFullDirectory, DirectoryHelper.GetTexturesDirectory(XP2AFSConverterManager.Settings)); log.Info("Airport conversion done"); } else { log.ErrorFormat("Could not find the data for airport {0} make sure it is downloaded", icaoCode); } }