예제 #1
0
        public static void Init(string path, ExIni.IniFile pref)
        {
            try
            {
                var v = pref["Debug"]["VerbosityLevel"];
                Verbosity = CoreUtil.ChangeType <int>(v.Value);
                var c = pref["Debug"]["ColorConsoleOutput"];
                ColorOutput = CoreUtil.ChangeType <bool>(c.Value);
            }
            catch (Exception)
            {
                // ignore exceptions
            }

            if (!File.Exists(path))
            {
                // assume sybaris
                Log("Data path does not exist, assume sybaris");
                path = Path.Combine(path, @"../../Sybaris/Plugins/UnityInjector/Config/");
            }
            _dataPath = path;
            try
            {
                if (!Directory.Exists(LogFolder))
                {
                    Directory.CreateDirectory(LogFolder);
                }
                if (File.Exists(LogFile))
                {
                    var bak = Path.Combine(LogFolder, _logBackupfileName);
                    if (File.Exists(bak))
                    {
                        File.Delete(bak);
                    }
                    File.Move(LogFile, bak);
                    Log($"Created Backup logfile", Level.Debug);
                }
            }
            catch (Exception e)
            {
                _logFileStream = null;
                LogError($"Failed initialization of Logfile {LogFile}", e);
            }
        }
        private void LoadConfig()
        {
            CoreUtil.StartLoadingConfig(Preferences);

            var general = CoreUtil.LoadSection("General");
            general.LoadValue("PluginActive", ref _pluginActive);
            general.LoadValue("ToggleTranslationKey", ref _toggleButton);
            general.LoadValue("TranslationMethod", ref _activeTranslator);
            general.LoadValue("IgnoreFileName", ref _IgnoreFileName);

            var cache = CoreUtil.LoadSection("Cache");
            cache.LoadValue("File", ref _translationFile);
            cache.LoadValue("Folder", ref _translationFolder);
            cache.LoadValue("WriteCacheToFile", ref _dumpCache);
            cache.LoadValue("Frequenzy", ref _cacheDumpFrequenzy);
            if(_cacheDumpFrequenzy == CacheDumpFrequenzy.Periodic) {
                cache.LoadValue("PeriodicIntervall", ref _cacheDumpPeriodicIntervall);
            }
        }
예제 #3
0
        public void LoadConfig()
        {
            var section = CoreUtil.LoadSection(Section);

            LoadConfig(section);
        }
        public void Awake()
        {
            Logger.Init(this.DataPath, Preferences);
            try
            {
                DontDestroyOnLoad(this);
                LoadConfig();
                Logger.Log($"Starting {CoreUtil.PLUGIN_NAME} v{CoreUtil.PLUGIN_VERSION}", Level.General);
                if (!_pluginActive)
                {
                    Logger.Log("Plugin is disabled.", Level.General);
                    if (CoreUtil.FinishLoadingConfig())
                    {
                        SaveConfig();
                    }
                    Destroy(this);
                    return;
                }

                var success = LoadTranslator();
                if (!success)
                {
                    Logger.LogError($"Failed to load Translation module '{_activeTranslator}'");
                    if (CoreUtil.FinishLoadingConfig())
                    {
                        SaveConfig();
                    }
                    Destroy(this);
                    return;
                }

                Translator.LoadConfig();
                _preprocessor.LoadConfig();
                if (CoreUtil.FinishLoadingConfig())
                {
                    SaveConfig();
                }

                LoadIgnores();

                var translatorPlugin = HookHelper.DetectTranslationPlugin();
                if (translatorPlugin == HookHelper.ParentTranslationPlugin.None)
                {
                    var bldr = new StringBuilder("Found none of the supported translation plugins!\n");
                    bldr.AppendLine("Make sure, that one of the following is installed:");
                    bldr.AppendLine(" - Yet Another Translator (recommended)");
                    bldr.AppendLine(" - Unified Translation loader (only for ReiPatcher)");
                    bldr.AppendLine(" - Translation Plus (only for Sybaris)");
                    Logger.LogError(bldr.ToString());
                    Destroy(this);
                    return;
                }

                Logger.Log($"Initializing Module {_activeTranslator}", Level.Info);
                success = Translator.Init();
                if (!success)
                {
                    Logger.LogError($"Failed to load Translation module {_activeTranslator}");
                    Destroy(this);
                    return;
                }

                StartCoroutine(HookTranslator());

                Logger.Log($"Using translation cache file @: {TranslationFilePath}", Level.Info);
                LoadCacheFromDisk();

                if (_dumpCache && _cacheDumpFrequenzy == CacheDumpFrequenzy.Periodic)
                {
                    StartCoroutine(PeriodicDumpCache());
                }

                if (_preprocessor.Init(DataPath))
                {
                    Logger.Log("Successfully loaded text preprocessor", Level.Info);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                Destroy(this);
            }
        }
        public void LoadConfig()
        {
            var section = CoreUtil.LoadSection("General");

            section.LoadValue("SubstitutionsFile", ref _replacementsFile);
        }