Пример #1
0
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int strategyCount = i;

            #region SSD
            //Configuration configuration = controller.GetConfigurationCopy();
            Configuration configuration = _GetConfigurationCurrent();
            #endregion
            foreach (var server in configuration.configs)
            {
                if (Configuration.ChecksServer(server))
                {
                    MenuItem item = new MenuItem(server.FriendlyName());
                    #region SSD
                    if (server.subscription_url != "")
                    {
                        continue;
                    }
                    item = _AdjustServerName(server);
                    #endregion
                    item.Tag    = i - strategyCount;
                    item.Click += AServerItem_Click;
                    items.Add(i, item);
                    i++;
                }
            }

            foreach (MenuItem item in items)
            {
                if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }
            #region SSD
            _UpdateAirportMenu(i - strategyCount);
            #endregion
        }
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int strategyCount = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(strategyCount, item);
                strategyCount++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(strategyCount++, new MenuItem("-"));

            int           serverCount   = 0;
            Configuration configuration = controller.GetCurrentConfiguration();

            foreach (var server in configuration.configs)
            {
                try
                {
                    Configuration.CheckServer(server);
                    MenuItem item = new MenuItem(server.ToString());
                    item.Tag    = configuration.configs.FindIndex(s => s == server);
                    item.Click += AServerItem_Click;
                    items.Add(strategyCount + serverCount, item);
                    serverCount++;
                }
                catch
                {
                }
            }

            foreach (MenuItem item in items)
            {
                if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }
        }
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int           strategyCount = i;
            Configuration configuration = controller.GetConfigurationCopy();

            foreach (var server in configuration.configs)
            {
                /*************************************<Start> Edit by Ian.May, Oct.18****************************************/
                //MenuItem item = new MenuItem(server.FriendlyName());
                MenuItem item = new MenuItem(server.FriendlyName(controller.isShadowFogMode));
                /*************************************<Ends> Edit by Ian.May, Oct.18*****************************************/
                item.Tag    = i - strategyCount;
                item.Click += AServerItem_Click;
                items.Add(i, item);
                i++;
            }

            foreach (MenuItem item in items)
            {
                if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }
        }
Пример #4
0
        private void UpdateServersMenu()
        {
            var items = _serversItem.MenuItems;

            while (items[0] != _seperatorItem)
            {
                items.RemoveAt(0);
            }

            var i = 0;

            foreach (var strategy in _shadowsocksController.GetStrategies())
            {
                var item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);

                i++;
            }

            var strategyCount = i;
            var configuration = _shadowsocksController.GetConfigurationCopy();

            foreach (var server in configuration.configs)
            {
                var item = new MenuItem(server.FriendlyName());
                item.Tag    = i - strategyCount;
                item.Click += AServerItem_Click;
                items.Add(i, item);

                i++;
            }

            foreach (MenuItem item in items)
            {
                if (item.Tag != null &&
                    (item.Tag.ToString() == configuration.index.ToString() ||
                     item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }
        }
Пример #5
0
        private void UpdateServersMenu(bool reload = true)
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int           strategyCount = i;
            Configuration configuration = reload ? controller.GetConfigurationCopy() : controller.GetCurrentConfiguration();

            foreach (var server in configuration.configs)
            {
                MenuItem item = new MenuItem(server.FriendlyName());
                item.Tag    = i - strategyCount;
                item.Click += AServerItem_Click;
                items.Add(i, item);
                i++;
            }

            foreach (MenuItem item in items)
            {
                if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }
        }
        private void LoadMenu()
        {
            this.StrategyModeItem = CreateMenuGroup("Server Selection Mode", new MenuItem[] { });
            var strategyItems = new MenuItem[] {};

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                this.StrategyModeItem.MenuItems.Add(item);
            }
            this.contextMenu1 = new ContextMenu(new MenuItem[] {
                this.enableItem = CreateMenuItem("Enable System Proxy", new EventHandler(this.EnableItem_Click)),
                this.modeItem   = CreateMenuGroup("Mode", new MenuItem[] {
                    this.PACModeItem    = CreateMenuItem("Smart Mode", new EventHandler(this.PACModeItem_Click)),
                    this.globalModeItem = CreateMenuItem("Global Mode", new EventHandler(this.GlobalModeItem_Click))
                }),
                this.ServersItem = CreateMenuGroup("Servers", new MenuItem[] {
                    //this.ConfigItem = CreateMenuItem("Edit Servers...", new EventHandler(this.Config_Click)),
                    //CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)),
                    //CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click))
                }),
                CreateMenuGroup("More Settings And Info", new MenuItem[] {
                    this.AutoStartupItem  = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)),
                    this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)),
                    this.StrategyModeItem,
                    CreateMenuItem("Statistics Config...", StatisticsConfigItem_Click),
                    this.hotKeyItem = CreateMenuItem("Edit Hotkeys...", new EventHandler(this.hotKeyItem_Click)),
                    CreateMenuGroup("PAC ", new MenuItem[] {
                        this.localPACItem  = CreateMenuItem("Local PAC", new EventHandler(this.LocalPACItem_Click)),
                        this.onlinePACItem = CreateMenuItem("Online PAC", new EventHandler(this.OnlinePACItem_Click)),
                        new MenuItem("-"),
                        this.editLocalPACItem      = CreateMenuItem("Edit Local PAC File...", new EventHandler(this.EditPACFileItem_Click)),
                        this.updateFromGFWListItem = CreateMenuItem("Update Local PAC from Rallets", new EventHandler(this.UpdatePACFromGFWListItem_Click)),
                        this.editGFWUserRuleItem   = CreateMenuItem("Edit User Rule for Rallets...", new EventHandler(this.EditUserRuleFileForGFWListItem_Click)),
                        this.editOnlinePACItem     = CreateMenuItem("Edit Online PAC URL...", new EventHandler(this.UpdateOnlinePACURLItem_Click)),
                    }),
                    this.proxyItem = CreateMenuItem("Forward Proxy...", new EventHandler(this.proxyItem_Click)),
                    CreateMenuGroup("Logs", new MenuItem[] {
                        CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
                        this.VerboseLoggingToggleItem = CreateMenuItem("Verbose Logging", new EventHandler(this.VerboseLoggingToggleItem_Click))
                    }),
                    CreateMenuGroup("Updates Rallets", new MenuItem[] {
                        CreateMenuItem("Check for Updates...", new EventHandler(this.checkUpdatesItem_Click)),
                        new MenuItem("-"),
                        this.autoCheckUpdatesToggleItem = CreateMenuItem("Check for Updates at Startup", new EventHandler(this.autoCheckUpdatesToggleItem_Click)),
                    }),
                    new MenuItem(I18N.GetString("About Rallets") + " " + Util.Utils.getCurrentVersion(), this.AboutItem_Click)
                }),
                new MenuItem("-"),
                CreateMenuGroup("Account", new MenuItem[] {
                    CreateMenuItem("Buy Service", (e, t) => Url.GotoPayment()),
                    //CreateMenuItem("Buy Service", new EventHandler(this.PaymentItem_Click)),
                    CreateMenuItem("My Profile", (e, t) => Url.GotoMyProfile()),
                    this.TrafficItem = CreateMenuItem("Traffic Info Loading...", null),
                    this.LoginItem   = CreateMenuItem("Login", new EventHandler(this.LoginItem_Click)),
                }),
                new MenuItem("-"),
                CreateMenuItem("Quit", new EventHandler(this.Quit_Click))
            });
        }
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int             strategyCount               = i;
            Configuration   configuration               = controller.GetConfigurationCopy();
            List <MenuItem> moreServersPages            = new List <MenuItem>();
            const int       MAX_DISPLAY_SERVER_PER_PAGE = 20;

            for (int serverIndex = 0; serverIndex < configuration.configs.Count; serverIndex++)
            {
                var server = configuration.configs[serverIndex];
                if (Configuration.ChecksServer(server))
                {
                    MenuItem item = new MenuItem(server.FriendlyName());
                    item.Tag    = serverIndex;
                    item.Click += AServerItem_Click;
                    if (serverIndex >= MAX_DISPLAY_SERVER_PER_PAGE)
                    {
                        if (moreServersPages.Count != 0 && moreServersPages.Last().MenuItems.Count < MAX_DISPLAY_SERVER_PER_PAGE)
                        {
                            moreServersPages.Last().MenuItems.Add(item);
                        }
                        else
                        {
                            var newPage = new MenuItem(I18N.GetString("Next Page"), new MenuItem[] { item });
                            moreServersPages.LastOrDefault()?.MenuItems?.Add(newPage);
                            moreServersPages.Add(newPage);
                        }
                    }
                    else
                    {
                        items.Add(i, item);
                        i++;
                    }
                }
            }

            foreach (MenuItem item in items)
            {
                if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }

            if (moreServersPages.Count != 0)
            {
                items.Add(i++, moreServersPages[0]);
                if (configuration.index >= MAX_DISPLAY_SERVER_PER_PAGE)
                {
                    int selectedPage = configuration.index / MAX_DISPLAY_SERVER_PER_PAGE - 1;
                    moreServersPages[selectedPage].MenuItems[configuration.index % MAX_DISPLAY_SERVER_PER_PAGE].Checked = true;
                    for (int pageIndex = 0; pageIndex <= selectedPage; pageIndex++)
                    {
                        moreServersPages[pageIndex].Text = I18N.GetString("✔Next Page");
                    }
                }
            }
        }
Пример #8
0
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int           strategyCount = i;
            Configuration configuration = controller.GetConfigurationCopy();



            //foreach (var server in configuration.configs)
            //{
            //    if (Configuration.ChecksServer(server))
            //    {
            //        MenuItem item = new MenuItem(server.FriendlyName());
            //        item.Tag = i - strategyCount;
            //        item.Click += AServerItem_Click;
            //        items.Add(i, item);
            //        i++;
            //    }
            //}
            var allServers = configuration.configs.Where(Configuration.ChecksServer).ToList();

            for (var ii = 0; ii < allServers.Count; ii++)
            {
                allServers[ii].tag = ii;
            }

            var serverGroups = allServers.GroupBy(x => x.serverGroup).ToList();
            var m            = serverGroups.Where(x => x.Count() > 1);
            var s            = serverGroups.Where(x => x.Count() == 1);

            serverGroups = m.Concat(s).ToList();
            foreach (var grp in serverGroups)
            {
                //分组只有一个服务器
                if (grp.Count() == 1)
                {
                    var singleGrpMenu = new MenuItem(grp.First().FriendlyName())
                    {
                        Tag = grp.First().tag
                    };
                    singleGrpMenu.Click += AServerItem_Click;
                    if (singleGrpMenu.Tag.ToString() == configuration.index.ToString())
                    {
                        singleGrpMenu.Checked = true;
                    }
                    items.Add(i, singleGrpMenu);
                    i++;
                    continue;
                }
                //分组多个服务器  合并为一组
                var t = new List <MenuItem>();
                foreach (var server in grp)
                {
                    var item = new MenuItem(server.FriendlyName())
                    {
                        Tag = server.tag
                    };
                    item.Click += AServerItem_Click;
                    if (item.Tag.ToString() == configuration.index.ToString())
                    {
                        item.Checked = true;
                    }
                    t.Add(item);
                }
                var grpMenu = new MenuItem(grp.Key + " (" + grp.Count() + ")", t.ToArray())
                {
                    Tag = grp.Key
                };
                if (t.Any(x => x.Checked))
                {
                    grpMenu.Text = "√ " + grpMenu.Text;
                }
                items.Add(i, grpMenu);
                i++;
            }


            foreach (MenuItem item in items)
            {
                if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                {
                    item.Checked = true;
                }
            }
        }
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int           strategyCount = i;
            Configuration configuration = controller.GetConfigurationCopy();
            var           grp           = configuration.configs.GroupBy(c => c.@group).ToArray();
            var           defaultGroup  = grp.Single(c => string.IsNullOrEmpty(c.Key)).ToArray();
            var           otherGroup    = grp.Where(c => !string.IsNullOrEmpty(c.Key)).ToArray();

            foreach (var server in defaultGroup)
            {
                MenuItem item = new MenuItem(server.FriendlyName());
                item.Tag    = i - strategyCount;
                item.Click += AServerItem_Click;
                items.Add(i, item);
                i++;
            }

            if (otherGroup.Any())
            {
                items.Add(i++, new MenuItem("-"));
                int defaultSvcCount = i;
                foreach (var group in otherGroup)
                {
                    var grpItem = new MenuItem(group.Key);
                    items.Add(defaultSvcCount++, grpItem);
                    foreach (var server in group)
                    {
                        MenuItem item = new MenuItem(server.FriendlyName());
                        item.Tag    = i - strategyCount - 1;//remove seperator
                        item.Click += AServerItem_Click;
                        grpItem.MenuItems.Add(item);
                        i++;
                    }
                }
            }

            foreach (MenuItem item in items)
            {
                if (item.MenuItems.Count > 0)
                {
                    foreach (MenuItem itemMenuItem in item.MenuItems)
                    {
                        if (itemMenuItem.Tag != null && (itemMenuItem.Tag.ToString() == configuration.index.ToString() || itemMenuItem.Tag.ToString() == configuration.strategy))
                        {
                            itemMenuItem.Checked = true;
                        }
                    }
                }
                else
                {
                    if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                    {
                        item.Checked = true;
                    }
                }
            }
        }
        private void UpdateServersMenu()
        {
            var items = ServersItem.MenuItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int i = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                MenuItem item = new MenuItem(strategy.Name);
                item.Tag    = strategy.ID;
                item.Click += AStrategyItem_Click;
                items.Add(i, item);
                i++;
            }

            // user wants a seperator item between strategy and servers menugroup
            items.Add(i++, new MenuItem("-"));

            int strategyCount = i;
            List <ServerGroup> serverGroupList = new List <ServerGroup>();
            Configuration      configuration   = controller.GetConfigurationCopy();

            foreach (var server in configuration.configs)
            {
                var isMatch = false;
                foreach (var groups in serverGroupList)
                {
                    if (groups.name == server.groups)
                    {
                        var index = serverGroupList.IndexOf(groups);
                        serverGroupList[index].serverList.Add(server);
                        isMatch = true;
                        break;
                    }
                }
                if (!isMatch)
                {
                    var bufServerGroup = new ServerGroup();
                    bufServerGroup.name = server.groups;
                    bufServerGroup.serverList.Add(server);
                    serverGroupList.Add(bufServerGroup);
                }
            }

            //create server group menus.
            var groupIndex = i;

            foreach (var serverGroup in serverGroupList)
            {
                List <MenuItem> bufItems = new List <MenuItem>();

                foreach (var server in serverGroup.serverList)
                {
                    MenuItem item = new MenuItem(server.FriendlyName());
                    item.Tag    = i - strategyCount;
                    item.Click += AServerItem_Click;
                    i++;
                    bufItems.Add(item);
                }

                var bufMenuGroup = CreateMenuGroup(serverGroup.name, bufItems.ToArray());
                items.Add(groupIndex, bufMenuGroup);
            }

            //setting current active server
            foreach (MenuItem bufItems in items)
            {
                foreach (MenuItem item in bufItems.MenuItems)
                {
                    if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
                    {
                        item.Checked = true;
                    }
                }

                MenuItem bufItem = bufItems;
                if (bufItem.Tag != null && (bufItem.Tag.ToString() == configuration.index.ToString() || bufItem.Tag.ToString() == configuration.strategy))
                {
                    bufItem.Checked = true;
                }
            }

            //foreach (var server in configuration.configs)
            //{
            //    MenuItem item = new MenuItem(server.FriendlyName());
            //    item.Tag = i - strategyCount;
            //    item.Click += AServerItem_Click;
            //    items.Add(i, item);
            //    i++;
            //}

            //foreach (MenuItem item in items)
            //{
            //    if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
            //    {
            //        item.Checked = true;
            //    }
            //}
        }
        private void UpdateServersMenu()
        {
            var items = ServersItem.DropDownItems;

            while (items[0] != SeperatorItem)
            {
                items.RemoveAt(0);
            }
            int strategyCount = 0;

            foreach (var strategy in controller.GetStrategies())
            {
                if (!items.OfType <ToolStripItem>().Any(ts => ts.Text == strategy.Name))
                {
                    ToolStripMenuItem item = new ToolStripMenuItem(strategy.Name);
                    item.Tag    = strategy.ID;
                    item.Click += AStrategyItem_Click;
                    items.Add(item);
                    strategyCount++;
                }
            }
            if (!items.OfType <ToolStripSeparator>().Any(ts => ts.Tag?.ToString() == "-server-"))
            {
                // user wants a seperator item between strategy and servers menugroup
                items.Add(new ToolStripSeparator()
                {
                    Tag = "-server-"
                });
            }
            int           serverCount   = 0;
            Configuration configuration = controller.GetCurrentConfiguration();

            foreach (var server in configuration.configs)
            {
                try
                {
                    Configuration.CheckServer(server);
                    var name = server.ToString();
                    if (!items.OfType <ToolStripMenuItem>().Any(ts => ts.Text == name))
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem(name);
                        item.Tag    = configuration.configs.FindIndex(s => s == server);
                        item.Click += AServerItem_Click;
                        items.Add(item);
                        serverCount++;
                    }
                }
                catch
                {
                }
            }

            foreach (var item in items)
            {
                var menuItem = item as ToolStripMenuItem;
                if (menuItem == null || menuItem.Tag == null)
                {
                    continue;
                }

                if (
                    menuItem.Tag.ToString() == configuration.index.ToString() ||
                    menuItem.Tag.ToString() == configuration.strategy
                    )
                {
                    menuItem.Checked = true;
                }
                else
                {
                    menuItem.Checked = false;
                }
            }
        }