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(); //この時点では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 OptionPreservePlace GetOptionPreservePlace() { const OptionPreservePlace DEFAULT_PLACE = OptionPreservePlace.AppData; RegistryKey g = Registry.CurrentUser.OpenSubKey(REGISTRY_PATH, false); if (g == null) { return(DEFAULT_PLACE); } string regVal = g.GetValue("option-place", null) as string; if (regVal == null) { return(DEFAULT_PLACE); } try { return((OptionPreservePlace)Enum.Parse(typeof(OptionPreservePlace), regVal)); } catch (Exception) { return(DEFAULT_PLACE); } }
private bool CommitGenericOptions() { string itemname = null; bool successful = false; try { _options.ShowInTaskBar = _showInTaskBarOption.Checked; _options.WarningOnExit = _warningOnExit.Checked; OptionPreservePlace optionPreservePlace = ((EnumListItem <OptionPreservePlace>)_optionPreservePlace.SelectedItem).Value; if (Env.Options.OptionPreservePlace != optionPreservePlace && !Env.IsRegistryWritable) { Util.Warning(this, Env.Strings.GetString("Message.OptionDialog.RegistryAuthRequired")); return(false); } _options.OptionPreservePlace = optionPreservePlace; _options.Language = ((EnumListItem <Language>)_languageBox.SelectedItem).Value; if (_options.Language == Language.Japanese && Env.Options.EnvLanguage == Language.English) { if (Util.AskUserYesNo(this, Env.Strings.GetString("Message.OptionDialog.AskJapaneseFont")) == DialogResult.No) { return(false); } } successful = true; } catch (FormatException) { Util.Warning(this, String.Format(Env.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname)); } return(successful); }
public static string GetOptionDirectory(OptionPreservePlace p) { if (p == OptionPreservePlace.InstalledDir) { string t = AppDomain.CurrentDomain.BaseDirectory; if (Environment.UserName.Length > 0) { t += Environment.UserName + "\\"; } return(t); } else { return(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\poderosa\\"); } }
public static string GetOptionDirectory(OptionPreservePlace p) { if(p==OptionPreservePlace.InstalledDir) { string t = AppDomain.CurrentDomain.BaseDirectory; if(Environment.UserName.Length>0) t += Environment.UserName + "\\"; return t; } else return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\poderosa\\"; }
private void AdjustOptionFileLocation(OptionPreservePlace p) { _optionPreservePlacePath.Text = Env.GetOptionDirectory(p); }
private static void LoadEnv() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState.ClientAndNonClientAreasEnabled; string error_msg = null; ReloadStringResource(); _channels = new ChannelProfileCollection(); _options = new Options(); _globalMutex = Win32.CreateMutex(IntPtr.Zero, 0, "PoderosaPFGlobalMutex"); bool already_exists = (Win32.GetLastError() == Win32.ERROR_ALREADY_EXISTS); if (_globalMutex == IntPtr.Zero) { throw new Exception("Global mutex could not open"); } if (Win32.WaitForSingleObject(_globalMutex, 10000) != Win32.WAIT_OBJECT_0) { throw new Exception("Global mutex lock error"); } try { OptionPreservePlace place = GetOptionPreservePlace(); _options.OptionPreservePlace = place; string dir = GetOptionDirectory(place); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string configfile = dir + "portforwarding.conf"; bool options_loaded = false; try { if (File.Exists(configfile)) { Encoding encoding = DetermineConfigFileEncoding(configfile); using (TextReader reader = new StreamReader(File.Open(configfile, FileMode.Open, FileAccess.Read), encoding)) { ConfigNode parent = new ConfigNode("root", reader).FindChildConfigNode("poderosa-portforwarding"); if (parent != null) { _channels.Load(parent); _options.Load(parent); options_loaded = true; } } } } catch (Exception ex) { error_msg = ex.Message; } finally { if (!options_loaded) { _options.Init(); } } //ここまできたら言語設定をチェックし、必要なら読み直し if (Util.CurrentLanguage != _options.Language) { System.Threading.Thread.CurrentThread.CurrentUICulture = _options.Language == Language.Japanese ? new CultureInfo("ja") : CultureInfo.InvariantCulture; } _log = new ConnectionLog(dir + "portforwarding.log"); } finally { Win32.ReleaseMutex(_globalMutex); } }