Example #1
0
        private static void LoadEnv()
        {
            string error_msg = null;
            ReloadStringResource();
            _channels = new ChannelProfileCollection();
            _options = new Options();
            ThemeUtil.Init();

            _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;
                TextReader reader = null;
                try {
                    if(File.Exists(configfile)) {
                        reader = new StreamReader(File.Open(configfile, FileMode.Open, FileAccess.Read), Encoding.Default);
                        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(reader!=null) reader.Close();
                    if(!options_loaded) _options.Init();
                }

                //�����܂ł����猾��ݒ��`�F�b�N���A�K�v�Ȃ�ǂݒ���
                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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
            }
        }