public static void LoadEnvironment(InitialAction act) { ThemeUtil.Init(); OptionPreservePlace place = GetOptionPreservePlace(); _options = new ContainerOptions(); _history = new ConnectionHistory(); _macroManager = new MacroManager(); _container = new PoderosaContainer(); _globalCommandTarget = new ContainerGlobalCommandTarget(); _interThreadUIService = new ContainerInterThreadUIService(); _sshKnownHosts = new SSHKnownHosts(); _options.Init(); //この時点ではOSの言語設定に合ったリソースをロードする。起動直前で必要に応じてリロード ReloadStringResource(); GEnv.Init(_container); GEnv.Options = _options; GEnv.GlobalCommandTarget = _globalCommandTarget; GEnv.InterThreadUIService = _interThreadUIService; GEnv.SSHKnownHosts = _sshKnownHosts; string dir = GetOptionDirectory(place); LoadConfigFiles(dir, act); _options.OptionPreservePlace = place; //ここまできたら言語設定をチェックし、必要なら読み直し if (GUtil.CurrentLanguage != _options.Language) { System.Threading.Thread.CurrentThread.CurrentUICulture = _options.Language == Language.Japanese? new CultureInfo("ja") : CultureInfo.InvariantCulture; ReloadStringResource(); } }
private static void LoadConfigFiles(string dir, InitialAction act) { if (Win32.WaitForSingleObject(_globalMutex, 10000) != Win32.WAIT_OBJECT_0) { throw new Exception("Global mutex lock error"); } try { string optionfile = dir + "options.conf"; bool config_loaded = false; bool macro_loaded = false; TextReader reader = null; try { if (File.Exists(optionfile)) { reader = new StreamReader(File.Open(optionfile, FileMode.Open, FileAccess.Read), Encoding.Default); if (VerifyConfigHeader(reader)) { ConfigNode root = new ConfigNode("root", reader).FindChildConfigNode("poderosa"); if (root != null) { _options.Load(root); config_loaded = true; _history.Load(root); _macroManager.Load(root); macro_loaded = true; } } } } catch (Exception ex) { //_errorOccurredOnBoot = true; Debug.WriteLine(ex.StackTrace); GUtil.WriteDebugLog(ex.StackTrace); act.AddMessage("Failed to read the configuration file.\n" + ex.Message); } finally { if (!config_loaded) { _options.Init(); } if (!macro_loaded) { _macroManager.SetDefault(); } if (reader != null) { reader.Close(); } } GEnv.Options = _options; //これでDefaultRenderProfileが初期化される string kh = dir + "ssh_known_hosts"; if (File.Exists(kh)) { try { _sshKnownHosts.Load(kh); } catch (Exception ex) { _sshKnownHosts.Clear(); act.AddMessage("Failed to read the 'ssh_known_hosts' file.\n" + ex.Message); } } } finally { Win32.ReleaseMutex(_globalMutex); } }