コード例 #1
0
        private static void InitServices()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!");
                Exit(1);
            }

            string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName);

            GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile);
            if (GlobalDatabase == null)
            {
                ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!");
                Exit(1);
            }

            ArchiWebHandler.Init();
            WebBrowser.Init();

            WebBrowser = new WebBrowser(ArchiLogger);
        }
コード例 #2
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            ushort      defaultResourceSetCount = 0;
            ResourceSet defaultResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet != null)
            {
                defaultResourceSetCount = (ushort)defaultResourceSet.Cast <object>().Count();
            }

            if (defaultResourceSetCount == 0)
            {
                return;
            }

            ushort      currentResourceSetCount = 0;
            ResourceSet currentResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false);

            if (currentResourceSet != null)
            {
                currentResourceSetCount = (ushort)currentResourceSet.Cast <object>().Count();
            }

            if (currentResourceSetCount < defaultResourceSetCount)
            {
                float translationCompleteness = currentResourceSetCount / (float)defaultResourceSetCount;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
            }
        }
コード例 #3
0
        private static void InitServices()
        {
            GlobalConfig = GlobalConfig.Load();
            if (GlobalConfig == null)
            {
                Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!");
                Thread.Sleep(5000);
                Exit(1);
            }

            GlobalDatabase = GlobalDatabase.Load();
            if (GlobalDatabase == null)
            {
                Logging.LogGenericError("Global database could not be loaded!");
                Thread.Sleep(5000);
                Exit(1);
            }

            ArchiWebHandler.Init();
            WebBrowser.Init();
            WCF.Init();
        }
コード例 #4
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            if (GlobalConfig.BackgroundGCPeriod > 0)
            {
                Hacks.EnableBackgroundGC(GlobalConfig.BackgroundGCPeriod);
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("en"))
            {
                return;
            }

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet));
                return;
            }

            HashSet <DictionaryEntry> defaultStringObjects = new HashSet <DictionaryEntry>(defaultResourceSet.Cast <DictionaryEntry>());

            if (defaultStringObjects.Count == 0)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects));
                return;
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);

            if (currentResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(currentResourceSet));
                return;
            }

            HashSet <DictionaryEntry> currentStringObjects = new HashSet <DictionaryEntry>(currentResourceSet.Cast <DictionaryEntry>());

            if (currentStringObjects.Count >= defaultStringObjects.Count)
            {
                // Either we have 100% finished translation, or we're missing it entirely and using en-US
                HashSet <DictionaryEntry> testStringObjects = new HashSet <DictionaryEntry>(currentStringObjects);
                testStringObjects.ExceptWith(defaultStringObjects);

                // If we got 0 as final result, this is the missing language
                // Otherwise it's just a small amount of strings that happen to be the same
                if (testStringObjects.Count == 0)
                {
                    currentStringObjects = testStringObjects;
                }
            }

            if (currentStringObjects.Count < defaultStringObjects.Count)
            {
                float translationCompleteness = currentStringObjects.Count / (float)defaultStringObjects.Count;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: secw/ArchiSteamFarm
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            ushort      defaultResourceSetCount = 0;
            ResourceSet defaultResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet != null)
            {
                defaultResourceSetCount = (ushort)defaultResourceSet.Cast <object>().Count();
            }

            if (defaultResourceSetCount == 0)
            {
                return;
            }

            ushort      currentResourceSetCount = 0;
            ResourceSet currentResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false);

            if (currentResourceSet != null)
            {
                currentResourceSetCount = (ushort)currentResourceSet.Cast <object>().Count();
            }

            if (currentResourceSetCount < defaultResourceSetCount)
            {
                // We don't want to report "en-AU" as 0.00% only because we don't have it as a dialect, if "en" is available and translated
                // This typically will work only for English, as e.g. "nl-BE" doesn't fallback to "nl-NL", but "nl", and "nl" will be empty
                ushort      neutralResourceSetCount = 0;
                ResourceSet neutralResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture.Parent, true, false);
                if (neutralResourceSet != null)
                {
                    neutralResourceSetCount = (ushort)neutralResourceSet.Cast <object>().Count();
                }

                if (neutralResourceSetCount < defaultResourceSetCount)
                {
                    float translationCompleteness = currentResourceSetCount / (float)defaultResourceSetCount;
                    ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
                }
            }
        }
コード例 #6
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = ASF.GetFilePath(ASF.EFileType.Config);

            if (string.IsNullOrEmpty(globalConfigFile))
            {
                ASF.ArchiLogger.LogNullError(nameof(globalConfigFile));

                return;
            }

            GlobalConfig globalConfig;

            if (File.Exists(globalConfigFile))
            {
                globalConfig = await GlobalConfig.Load(globalConfigFile).ConfigureAwait(false);

                if (globalConfig == null)
                {
                    ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                    await Task.Delay(5 * 1000).ConfigureAwait(false);
                    await Exit(1).ConfigureAwait(false);

                    return;
                }
            }
            else
            {
                globalConfig = GlobalConfig.Create();
            }

            ASF.InitGlobalConfig(globalConfig);

            if (Debugging.IsUserDebugging)
            {
                ASF.ArchiLogger.LogGenericDebug(globalConfigFile + ": " + JsonConvert.SerializeObject(ASF.GlobalConfig, Formatting.Indented));
            }

            if (!string.IsNullOrEmpty(ASF.GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(ASF.GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (Exception) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en"))
            {
                return;
            }

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet));

                return;
            }

            HashSet <DictionaryEntry> defaultStringObjects = defaultResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (defaultStringObjects.Count == 0)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects));

                return;
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            if (currentResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(currentResourceSet));

                return;
            }

            HashSet <DictionaryEntry> currentStringObjects = currentResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (currentStringObjects.Count >= defaultStringObjects.Count)
            {
                // Either we have 100% finished translation, or we're missing it entirely and using en-US
                HashSet <DictionaryEntry> testStringObjects = currentStringObjects.ToHashSet();
                testStringObjects.ExceptWith(defaultStringObjects);

                // If we got 0 as final result, this is the missing language
                // Otherwise it's just a small amount of strings that happen to be the same
                if (testStringObjects.Count == 0)
                {
                    currentStringObjects = testStringObjects;
                }
            }

            if (currentStringObjects.Count < defaultStringObjects.Count)
            {
                float translationCompleteness = currentStringObjects.Count / (float)defaultStringObjects.Count;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentUICulture.Name, translationCompleteness.ToString("P1")));
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: xiaomi00/ArchiSteamFarm
        private static async Task InitServices()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);

                Exit(1);
                return;
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            int defaultResourceSetCount = 0;
            int currentResourceSetCount = 0;

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CreateSpecificCulture("en-US"), true, true);

            if (defaultResourceSet != null)
            {
                defaultResourceSetCount = defaultResourceSet.Cast <object>().Count();
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false);

            if (currentResourceSet != null)
            {
                currentResourceSetCount = currentResourceSet.Cast <object>().Count();
            }

            if (currentResourceSetCount < defaultResourceSetCount)
            {
                float translationCompleteness = currentResourceSetCount / (float)defaultResourceSetCount;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
            }

            string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName);

            if (!File.Exists(globalDatabaseFile))
            {
                ASF.ArchiLogger.LogGenericInfo(Strings.Welcome);
                ASF.ArchiLogger.LogGenericWarning(Strings.WarningPrivacyPolicy);
                await Task.Delay(15 * 1000).ConfigureAwait(false);
            }

            GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile);
            if (GlobalDatabase == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorDatabaseInvalid, globalDatabaseFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);

                Exit(1);
                return;
            }

            ArchiWebHandler.Init();
            WebBrowser.Init();
            WCF.Init();

            WebBrowser = new WebBrowser(ASF.ArchiLogger);
        }
コード例 #8
0
        private static async Task <bool> InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = ASF.GetFilePath(ASF.EFileType.Config);

            if (string.IsNullOrEmpty(globalConfigFile))
            {
                throw new ArgumentNullException(nameof(globalConfigFile));
            }

            GlobalConfig?globalConfig;

            if (File.Exists(globalConfigFile))
            {
                globalConfig = await GlobalConfig.Load(globalConfigFile).ConfigureAwait(false);

                if (globalConfig == null)
                {
                    ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                    await Task.Delay(5 * 1000).ConfigureAwait(false);
                    await Exit(1).ConfigureAwait(false);

                    return(false);
                }
            }
            else
            {
                globalConfig = new GlobalConfig();
            }

            ASF.InitGlobalConfig(globalConfig);

            if (Debugging.IsDebugConfigured)
            {
                ASF.ArchiLogger.LogGenericDebug(globalConfigFile + ": " + JsonConvert.SerializeObject(ASF.GlobalConfig, Formatting.Indented));
            }

            if (!string.IsNullOrEmpty(ASF.GlobalConfig?.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(ASF.GlobalConfig !.CurrentCulture !);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (Exception e) {
                    ASF.ArchiLogger.LogGenericWarningException(e);

                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            // Skip translation progress for English and invariant (such as "C") cultures
            switch (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)
            {
            case "en":
            case "iv":
                return(true);
            }

            // We can't dispose this resource set, as we can't be sure if it isn't used somewhere else, rely on GC in this case
            ResourceSet?defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet));

                return(true);
            }

            HashSet <DictionaryEntry> defaultStringObjects = defaultResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (defaultStringObjects.Count == 0)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects));

                return(true);
            }

            // We can't dispose this resource set, as we can't be sure if it isn't used somewhere else, rely on GC in this case
            ResourceSet?currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            if (currentResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(currentResourceSet));

                return(true);
            }

            HashSet <DictionaryEntry> currentStringObjects = currentResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (currentStringObjects.Count >= defaultStringObjects.Count)
            {
                // Either we have 100% finished translation, or we're missing it entirely and using en-US
                HashSet <DictionaryEntry> testStringObjects = currentStringObjects.ToHashSet();
                testStringObjects.ExceptWith(defaultStringObjects);

                // If we got 0 as final result, this is the missing language
                // Otherwise it's just a small amount of strings that happen to be the same
                if (testStringObjects.Count == 0)
                {
                    currentStringObjects = testStringObjects;
                }
            }

            if (currentStringObjects.Count < defaultStringObjects.Count)
            {
                float translationCompleteness = currentStringObjects.Count / (float)defaultStringObjects.Count;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentUICulture.Name, translationCompleteness.ToString("P1")));
            }

            return(true);
        }