@@ -29,12 +29,13 @@ namespace Chromatics.Helpers
2929 public static class FileOperationsHelper
3030 {
3131 private static bool weatherDataLoaded ;
32+ private static WeatherData weatherData ;
3233
3334 public static void SaveLayerMappings ( ConcurrentDictionary < int , Layer > mappings )
3435 {
3536 var enviroment = new FileInfo ( Assembly . GetExecutingAssembly ( ) . Location ) . DirectoryName ;
3637 var path = $ "{ enviroment } /layers.chromatics3";
37-
38+
3839 try
3940 {
4041 using ( var sw = new StreamWriter ( path , false ) )
@@ -328,9 +329,9 @@ public static PaletteColorModel ImportColorMappings()
328329
329330 try
330331 {
331- #if DEBUG
332- Debug . WriteLine ( "Legacy file detected" ) ;
333- #endif
332+ #if DEBUG
333+ Debug . WriteLine ( "Legacy file detected" ) ;
334+ #endif
334335
335336 var result = new PaletteColorModel ( ) ;
336337
@@ -345,7 +346,7 @@ public static PaletteColorModel ImportColorMappings()
345346 var _sr = new MemoryStream ( bytes ) ;
346347
347348 var colorMappings = ( LegacyColorMappings ) reader . Deserialize ( _sr ) ;
348-
349+
349350 _sr . Close ( ) ;
350351
351352 foreach ( var p in colorMappings . GetType ( ) . GetProperties ( BindingFlags . Public | BindingFlags . Instance ) )
@@ -358,7 +359,7 @@ public static PaletteColorModel ImportColorMappings()
358359
359360 var mapping = ( ColorMapping ) f . GetValue ( result ) ;
360361 var new_mapping = new ColorMapping ( mapping . Name , mapping . Type , color ) ;
361- f . SetValue ( result , new_mapping ) ;
362+ f . SetValue ( result , new_mapping ) ;
362363 }
363364 }
364365 }
@@ -378,7 +379,7 @@ public static PaletteColorModel ImportColorMappings()
378379
379380 Logger . WriteConsole ( Enums . LoggerTypes . Error , @"Error importing legacy Color Palette." ) ;
380381 return null ;
381-
382+
382383 }
383384 else
384385 {
@@ -572,14 +573,21 @@ public static bool CheckWeatherDataLoaded()
572573 return weatherDataLoaded ;
573574 }
574575
576+ public static WeatherData GetWeatherDataLoaded ( )
577+ {
578+ if ( ! weatherDataLoaded ) return null ;
579+
580+ return weatherData ;
581+ }
582+
575583 public static string GetCsvData ( string url , string csvPath )
576584 {
577585 var http = new HttpClient ( ) ;
578586 var enviroment = new FileInfo ( Assembly . GetExecutingAssembly ( ) . Location ) . DirectoryName ;
579587 var path = enviroment + @"/" + csvPath ;
580588
581589 var dataStoreResult = http . GetAsync ( new Uri ( url ) ) . GetAwaiter ( ) . GetResult ( ) ;
582-
590+
583591 if ( File . Exists ( path ) )
584592 {
585593 var fileInfo = new FileInfo ( path ) ;
@@ -599,26 +607,25 @@ public static string GetCsvData(string url, string csvPath)
599607 return path ;
600608 }
601609
602- #if DEBUG
603- Debug . WriteLine ( @"An error occurred downloading the file " + csvPath + @" from URI: " + url ) ;
604- #endif
610+ #if DEBUG
611+ Debug . WriteLine ( @"An error occurred downloading the file " + csvPath + @" from URI: " + url ) ;
612+ #endif
605613
606614 return string . Empty ;
607615 }
608616
609- public static void GetUpdatedWeatherData ( )
617+ public static WeatherData GetUpdatedWeatherData ( )
610618 {
611619 var directory = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
612620 var WeatherKindsOutputPath = directory + @"/weatherKinds.json" ;
613621 var WeatherRateIndicesOutputPath = directory + @"/weatherRateIndices.json" ;
614622 var TerriTypesOutputPath = directory + @"/terriTypes.json" ;
615623
616624 var http = new HttpClient ( ) ;
617-
618625
619626 // GarlandTools
620627 var dataStoreResult = http . GetAsync ( new Uri ( @"https://www.garlandtools.org/db/doc/core/en/3/data.json" ) ) . GetAwaiter ( ) . GetResult ( ) ;
621-
628+
622629 if ( File . Exists ( WeatherRateIndicesOutputPath ) )
623630 {
624631 var fileInfo = new FileInfo ( WeatherRateIndicesOutputPath ) ;
@@ -627,13 +634,24 @@ public static void GetUpdatedWeatherData()
627634 if ( fileInfo . LastWriteTimeUtc >= lastModified )
628635 {
629636 weatherDataLoaded = true ;
630- return ;
637+ var _weatherRateIndices = JsonConvert . DeserializeObject < List < WeatherRateIndex > > ( File . ReadAllText ( WeatherRateIndicesOutputPath ) ) ;
638+ var _terriTypes = JsonConvert . DeserializeObject < List < TerriType > > ( File . ReadAllText ( TerriTypesOutputPath ) ) ;
639+ var _weatherKinds = JsonConvert . DeserializeObject < List < Weather > > ( File . ReadAllText ( WeatherKindsOutputPath ) ) ;
640+
641+ weatherData = new WeatherData
642+ {
643+ WeatherRateIndices = _weatherRateIndices ,
644+ TerriTypes = _terriTypes ,
645+ WeatherKinds = _weatherKinds
646+ } ;
647+
648+ return weatherData ;
631649 }
632650 }
633-
651+
634652 Logger . WriteConsole ( Enums . LoggerTypes . System , @"Updated FFXIV data is available" ) ;
635653 Logger . WriteConsole ( Enums . LoggerTypes . System , $ "Requesting data from Garland Tools..") ;
636-
654+
637655 var dataStoreRaw = http . GetStringAsync ( new Uri ( "https://www.garlandtools.org/db/doc/core/en/3/data.json" ) ) . GetAwaiter ( ) . GetResult ( ) ;
638656 var dataStore = JObject . Parse ( dataStoreRaw ) ;
639657
@@ -665,11 +683,10 @@ public static void GetUpdatedWeatherData()
665683 }
666684
667685 File . WriteAllText ( WeatherRateIndicesOutputPath , JsonConvert . SerializeObject ( weatherRateIndices ) ) ;
668-
669686
670687 // XIVAPI
671688 #if DEBUG
672- Debug . WriteLine ( @"Requesting data from XIVAPI and FFCafe..." ) ;
689+ Debug . WriteLine ( @"Requesting data from XIVAPI and FFCafe..." ) ;
673690 #endif
674691
675692 var terriTypes = new List < TerriType > ( ) ;
@@ -701,7 +718,7 @@ public static void GetUpdatedWeatherData()
701718 page ++ ;
702719 }
703720
704- var cafeCsvRaw = http . GetStreamAsync ( new Uri ( @"https://raw.githubusercontent.com/thewakingsands /ffxiv-datamining-cn /master/PlaceName.csv" ) ) . GetAwaiter ( ) . GetResult ( ) ;
721+ var cafeCsvRaw = http . GetStreamAsync ( new Uri ( @"https://raw.githubusercontent.com/xivapi /ffxiv-datamining/master/csv /PlaceName.csv" ) ) . GetAwaiter ( ) . GetResult ( ) ;
705722 using var cafeSr = new StreamReader ( cafeCsvRaw ) ;
706723 using var cafeCsv = new CsvReader ( cafeSr , CultureInfo . InvariantCulture ) ;
707724 for ( var i = 0 ; i < 3 ; i ++ ) cafeCsv . Read ( ) ;
@@ -723,7 +740,7 @@ public static void GetUpdatedWeatherData()
723740 Logger . WriteConsole ( Enums . LoggerTypes . Error , $ "XIVAPI: Data is not continuous and/or sorted in ascending order.") ;
724741 ttLastN = terriType . Id ;
725742 }
726-
743+
727744 File . WriteAllText ( TerriTypesOutputPath , JsonConvert . SerializeObject ( terriTypes ) ) ;
728745
729746 var weatherKinds = new List < Weather > ( ) ;
@@ -741,7 +758,7 @@ public static void GetUpdatedWeatherData()
741758 foreach ( var child in dataStore2 [ "Results" ] . Children ( ) )
742759 {
743760 var id = child [ "ID" ] . ToObject < int > ( ) ;
744-
761+
745762 weatherKinds . Add ( new Weather
746763 {
747764 Id = id ,
@@ -755,7 +772,7 @@ public static void GetUpdatedWeatherData()
755772 page ++ ;
756773 }
757774
758- var cafeCsvRaw = http . GetStreamAsync ( new Uri ( @"https://raw.githubusercontent.com/thewakingsands /ffxiv-datamining-cn /master/Weather.csv" ) ) . GetAwaiter ( ) . GetResult ( ) ;
775+ var cafeCsvRaw = http . GetStreamAsync ( new Uri ( @"https://raw.githubusercontent.com/xivapi /ffxiv-datamining/master/csv /Weather.csv" ) ) . GetAwaiter ( ) . GetResult ( ) ;
759776 using var cafeSr = new StreamReader ( cafeCsvRaw ) ;
760777 using var cafeCsv = new CsvReader ( cafeSr , CultureInfo . InvariantCulture ) ;
761778 for ( var i = 0 ; i < 3 ; i ++ ) cafeCsv . Read ( ) ;
@@ -782,6 +799,15 @@ public static void GetUpdatedWeatherData()
782799
783800 Logger . WriteConsole ( Enums . LoggerTypes . System , $ "Successfully updated internal database from Garland Tools") ;
784801 weatherDataLoaded = true ;
802+
803+ weatherData = new WeatherData
804+ {
805+ WeatherRateIndices = weatherRateIndices ,
806+ TerriTypes = terriTypes ,
807+ WeatherKinds = weatherKinds
808+ } ;
809+
810+ return weatherData ;
785811 }
786812 }
787813}
0 commit comments