diff --git a/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs b/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs index 2b08ef3be..5e4b51527 100644 --- a/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs +++ b/source/Grabacr07.KanColleWrapper/TranslationDataProvider.cs @@ -4,15 +4,10 @@ using System.Globalization; using System.IO; using System.Linq; -using System.Reflection; using System.Runtime.Serialization.Json; -using System.Web.Configuration; -using System.Xml.Linq; using System.Xml.Serialization; -using Grabacr07.KanColleWrapper.Models; using Grabacr07.KanColleWrapper.Models.Raw; using Grabacr07.KanColleWrapper.Models.Translations; -using Livet; namespace Grabacr07.KanColleWrapper { @@ -34,7 +29,7 @@ private set currentCulture = value ?? CultureInfo.CurrentCulture.Name; currentCulture = (currentCulture.StartsWith("en")) ? "en" : currentCulture; currentCulture = (currentCulture.StartsWith("ja")) ? "ja" : currentCulture; - // If culture is set to "(auto)", check if we support the translations for current the system-wide culture. + // If culture is set to "(auto)", check if we support the translations for the current system-wide culture. if ((value == null) && !IsCultureSupported(CultureInfo.CurrentCulture.Name)) currentCulture = "en"; } } @@ -53,12 +48,12 @@ static TranslationDataProvider() CurrentCulture = KanColleClient.Current?.Settings?.Culture; } - //private static string FilePath(TranslationProviderType type, string culture) - // => Path.Combine(translationsPath, culture, type.ToString() + ".xml"); - private static string SerialisationPath(TranslationProviderType type, string culture) => Path.Combine(translationsPath, culture, type.ToString() + ".xml"); + private static string SerialisationPath(TranslationProviderType type) + => SerialisationPath(type, CurrentCulture); + /// /// Changes culture and loads or re-loads translation files. /// @@ -74,7 +69,7 @@ public static void ChangeCulture(string culture) Debug.WriteLine("TranslationDataProvider: got <" + culture + "> in a culture change request."); CurrentCulture = culture; - LoadLocalTranslations(culture); + LoadLocalTranslations(); KanColleClient.Current.Translations.ChangeCulture(); KanColleClient.Current.Updater.ChangeCulture(); } @@ -86,7 +81,7 @@ public static void ChangeCulture(string culture) /// Culture /// JSON data /// - public static bool LoadJson(TranslationProviderType type, string culture, byte[] jsonBytes) + private static bool LoadJson(TranslationProviderType type, string culture, byte[] jsonBytes) { Debug.WriteLine("TranslationDataProvider: Provider {0}: JSON parsing was requested for culture <{1}>.", type, culture); @@ -121,7 +116,10 @@ public static bool LoadJson(TranslationProviderType type, string culture, byte[] return false; } - public static string Lookup(TranslationType type, string culture, object rawData) + public static bool LoadJson(TranslationProviderType type, byte[] jsonBytes) + => LoadJson(type, CurrentCulture, jsonBytes); + + private static string Lookup(TranslationType type, string culture, object rawData) { string lookupData; @@ -152,7 +150,7 @@ public static string Lookup(TranslationType type, string culture, object rawData return null; } - var result = LookupInsideProvider(type, culture, lookupData); + var result = LookupInsideProvider(type, lookupData); if ((result == null) && EnableSubmission) { ProcessUnknown?.Invoke(null, new ProcessUnknownEventArgs(TypeToProviderType(type), culture, rawData)); @@ -160,7 +158,10 @@ public static string Lookup(TranslationType type, string culture, object rawData return result; } - public static string LookupInsideProvider(TranslationType type, string culture, string key) + public static string Lookup(TranslationType type, object rawData) + => Lookup(type, CurrentCulture, rawData); + + private static string LookupInsideProvider(TranslationType type, string culture, string key) { var accessor = Tuple.Create(TypeToProviderType(type), culture); @@ -201,19 +202,25 @@ public static string LookupInsideProvider(TranslationType type, string culture, return !string.IsNullOrEmpty(result) ? result: null; } - public static string Version(TranslationProviderType type, string culture) + public static string LookupInsideProvider(TranslationType type, string key) + => LookupInsideProvider(type, CurrentCulture, key); + + private static string Version(TranslationProviderType type, string culture) { var accessor = Tuple.Create(type, culture); if (!translationSets.ContainsKey(accessor)) return null; return translationSets[accessor]?.version; } + public static string Version(TranslationProviderType type) + => Version(type, CurrentCulture); + /// /// Serialise data to local storage /// /// /// - public static void SaveXml(TranslationProviderType type, string culture) + private static void SaveXml(TranslationProviderType type, string culture) { if (culture.StartsWith("ja")) return; @@ -252,7 +259,10 @@ public static void SaveXml(TranslationProviderType type, string culture) } } - public static bool LoadXml(TranslationProviderType type, string culture) + public static void SaveXml(TranslationProviderType type) + => SaveXml(type, CurrentCulture); + + private static bool LoadXml(TranslationProviderType type, string culture) { if (!File.Exists(SerialisationPath(type, culture)) || culture.StartsWith("ja")) return false; @@ -288,10 +298,13 @@ public static bool LoadXml(TranslationProviderType type, string culture) } } + public static bool LoadXml(TranslationProviderType type) + => LoadXml(type, CurrentCulture); + /// /// Deserialises translations from local storage. Should only be called during culture change requests. /// - public static void LoadLocalTranslations(string culture) + private static void LoadLocalTranslations(string culture) { if (culture.StartsWith("ja")) return; @@ -303,6 +316,9 @@ public static void LoadLocalTranslations(string culture) } } + public static void LoadLocalTranslations() + => LoadLocalTranslations(CurrentCulture); + /// /// Are translations for the given culture supported? /// Currently a stub. diff --git a/source/Grabacr07.KanColleWrapper/Translations.cs b/source/Grabacr07.KanColleWrapper/Translations.cs index 01435b550..9ab87510f 100644 --- a/source/Grabacr07.KanColleWrapper/Translations.cs +++ b/source/Grabacr07.KanColleWrapper/Translations.cs @@ -72,7 +72,7 @@ public string Lookup(TranslationType type, object rawData) return null; } - return TranslationDataProvider.Lookup(type, CurrentCulture, rawData); + return TranslationDataProvider.Lookup(type, rawData); } } } diff --git a/source/Grabacr07.KanColleWrapper/Updater.cs b/source/Grabacr07.KanColleWrapper/Updater.cs index 4070978ec..7710f1981 100644 --- a/source/Grabacr07.KanColleWrapper/Updater.cs +++ b/source/Grabacr07.KanColleWrapper/Updater.cs @@ -37,6 +37,14 @@ public class Updater : NotificationObject /// private const string apiVersion = "1"; + private readonly TimeSpan updateCheckFrequency = new TimeSpan(0, 120, 0); + +#if !DEBUG + private readonly TimeSpan submissionFrequency = new TimeSpan(0, 15, 0); +#else + private readonly TimeSpan submissionFrequency = new TimeSpan(0, 1, 0); +#endif + /// /// URL for version checks. /// @@ -87,10 +95,10 @@ public Updater(string apiurl, string culture) TranslationDataProvider.ProcessUnknown += ProcessUnknown; this.updateCheckTimer.Tick += this.dispatcherTimerHandler; - this.updateCheckTimer.Interval = new TimeSpan(0, 120, 0); + this.updateCheckTimer.Interval = updateCheckFrequency; this.autosubmitTimer.Tick += this.autosubmitTimerHandler; - this.autosubmitTimer.Interval = new TimeSpan(0, 15, 0); + this.autosubmitTimer.Interval = submissionFrequency; this.apiVersionCheckUrl = apiurl; this.ChangeCulture(); @@ -204,8 +212,8 @@ private void UpdateAsNeeded() { if (!this.IsUpToDate(version.Key)) { - Debug.WriteLine("Updater: {0} needs update; local version: {1}, remote: {2}.", version.Key, (version.Key != TranslationProviderType.App) ? TranslationDataProvider.Version(version.Key, CurrentCulture) : Assembly.GetEntryAssembly().GetName().Version.ToString(), string.IsNullOrEmpty(version.Value) ? "N/A" : version.Value); - if ((version.Key != TranslationProviderType.App) && this.FetchTranslations(version.Key)) TranslationDataProvider.SaveXml(version.Key, CurrentCulture); + Debug.WriteLine("Updater: {0} needs update; local version: {1}, remote: {2}.", version.Key, (version.Key != TranslationProviderType.App) ? TranslationDataProvider.Version(version.Key) : Assembly.GetEntryAssembly().GetName().Version.ToString(), string.IsNullOrEmpty(version.Value) ? "N/A" : version.Value); + if ((version.Key != TranslationProviderType.App) && this.FetchTranslations(version.Key)) TranslationDataProvider.SaveXml(version.Key); } } } @@ -232,7 +240,7 @@ public bool IsUpToDate(TranslationProviderType type) int verRemote, verLocal; if (!int.TryParse(versions[type], out verRemote)) return true; - if (!int.TryParse(TranslationDataProvider.Version(type, CurrentCulture), out verLocal)) return false; + if (!int.TryParse(TranslationDataProvider.Version(type), out verLocal)) return false; return (verRemote <= verLocal); } @@ -267,7 +275,7 @@ private bool FetchTranslations(TranslationProviderType type) return false; } - return TranslationDataProvider.LoadJson(type, CurrentCulture, responseBytes); + return TranslationDataProvider.LoadJson(type, responseBytes); } }