Exemplo n.º 1
0
        /// <summary>
        /// Checks if specified provider is up to date (compares local version to server version).
        /// </summary>
        /// <param name="type">Translation provider type.</param>
        /// <returns>True if local version is greater than or equal to remote.</returns>
        public bool IsUpToDate(TranslationProviderType type)
        {
            if ((!versions.ContainsKey(type)) || (versions[type] == null) || !apiAvailable)
            {
                return(true);
            }

            switch (type)
            {
            case TranslationProviderType.App:
                Version remoteAppVersion, localAppVersion = Assembly.GetEntryAssembly().GetName().Version;

                if (!Version.TryParse(versions[type], out remoteAppVersion))
                {
                    return(true);
                }

                return(remoteAppVersion <= localAppVersion);

            default:
                int verRemote, verLocal;

                if (!int.TryParse(versions[type], out verRemote))
                {
                    return(true);
                }
                if (!int.TryParse(TranslationDataProvider.Version(type), out verLocal))
                {
                    return(false);
                }

                return(verRemote <= verLocal);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if any updates are needed, downloads and serialises them for local storage.
        /// </summary>
        private void UpdateAsNeeded()
        {
            Debug.WriteLine("API available: {0}, Updates enabled: {1}", apiAvailable, EnableUpdates);
            if (!apiAvailable || !EnableUpdates)
            {
                return;
            }

            foreach (var version in versions)
            {
                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) : 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);
                    }
                }
            }
        }