public OptionsWindow(AmoebaManager amoebaManager, ConnectionSettingManager connectionSettingManager, OverlayNetworkManager overlayNetworkManager, TransfarLimitManager transfarLimitManager, BufferManager bufferManager) { _bufferManager = bufferManager; _amoebaManager = amoebaManager; _connectionSettingManager = connectionSettingManager; _overlayNetworkManager = overlayNetworkManager; _transferLimitManager = transfarLimitManager; InitializeComponent(); _baseNodeTextBox.MaxLength = UriCollection.MaxUriLength; { var icon = new BitmapImage(); icon.BeginInit(); icon.StreamSource = new FileStream(Path.Combine(_serviceManager.Paths["Icons"], "Amoeba.ico"), FileMode.Open, FileAccess.Read, FileShare.Read); icon.EndInit(); if (icon.CanFreeze) icon.Freeze(); this.Icon = icon; } { foreach (var item in Enum.GetValues(typeof(ConnectionType)).Cast<ConnectionType>()) { _clientFiltersConnectionTypeComboBox.Items.Add(item); } foreach (var item in Enum.GetValues(typeof(TransferLimitType)).Cast<TransferLimitType>()) { _transferLimitTypeComboBox.Items.Add(item); } foreach (var u in new string[] { "Byte", "KB", "MB", "GB", "TB" }) { _dataCacheSizeComboBox.Items.Add(u); } _dataCacheSizeComboBox.SelectedItem = Settings.Instance.OptionsWindow_DataCacheSize_Unit; foreach (var u in new string[] { "Byte", "KB", "MB", "GB", }) { _bandwidthLimitComboBox.Items.Add(u); } _bandwidthLimitComboBox.SelectedItem = Settings.Instance.OptionsWindow_BandwidthLimit_Unit; foreach (var u in new string[] { "Byte", "KB", "MB", "GB", }) { _transferLimitSizeComboBox.Items.Add(u); } _transferLimitSizeComboBox.SelectedItem = Settings.Instance.OptionsWindow_TransferLimit_Unit; } { lock (_amoebaManager.ThisLock) { var baseNode = _amoebaManager.BaseNode; _baseNode_Id = baseNode.Id; _baseNode_Uris.AddRange(baseNode.Uris); _otherNodes.AddRange(_amoebaManager.OtherNodes); _clientFilters.AddRange(_amoebaManager.Filters); _serverListenUris.AddRange(_amoebaManager.ListenUris); try { _dataCacheSizeTextBox.Text = NetworkConverter.ToSizeString(_amoebaManager.Size, Settings.Instance.OptionsWindow_DataCacheSize_Unit); } catch (Exception) { _dataCacheSizeTextBox.Text = ""; } _dataDownloadDirectoryTextBox.Text = _amoebaManager.DownloadDirectory; _bandwidthConnectionCountTextBox.Text = _amoebaManager.ConnectionCountLimit.ToString(); try { _bandwidthLimitTextBox.Text = NetworkConverter.ToSizeString(_amoebaManager.BandwidthLimit, Settings.Instance.OptionsWindow_BandwidthLimit_Unit); } catch (Exception) { _bandwidthLimitTextBox.Text = ""; } } _baseNodeUrisListView.ItemsSource = _baseNode_Uris; _baseNodeUpdate(); _otherNodesListView.ItemsSource = _otherNodes; _otherNodesUpdate(); _clientFiltersListView.ItemsSource = _clientFilters; _clientFiltersListViewUpdate(); _serverListenUrisListView.ItemsSource = _serverListenUris; _serverListenUrisUpdate(); } { lock (_transferLimitManager.TransferLimit.ThisLock) { _transferLimitTypeComboBox.SelectedItem = _transferLimitManager.TransferLimit.Type; _transferLimitSpanTextBox.Text = _transferLimitManager.TransferLimit.Span.ToString(); try { _transferLimitSizeTextBox.Text = NetworkConverter.ToSizeString(_transferLimitManager.TransferLimit.Size, Settings.Instance.OptionsWindow_TransferLimit_Unit); } catch (Exception) { _transferLimitSizeTextBox.Text = ""; } } { var uploadSize = _transferLimitManager.TotalUploadSize; var downloadSize = _transferLimitManager.TotalDownloadSize; _transferInfoUploadedLabel.Content = NetworkConverter.ToSizeString(uploadSize); _transferInfoDownloadedLabel.Content = NetworkConverter.ToSizeString(downloadSize); _transferInfoTotalLabel.Content = NetworkConverter.ToSizeString(uploadSize + downloadSize); } } { _eventOpenPortAndGetIpAddressCheckBox.IsChecked = Settings.Instance.Global_ConnectionSetting_IsEnabled; _eventUseI2pCheckBox.IsChecked = Settings.Instance.Global_I2p_SamBridge_IsEnabled; { _eventSamBridgeUriTextBox.Text = _overlayNetworkManager.SamBridgeUri; } } { _updateUrlTextBox.Text = Settings.Instance.Global_Update_Url; _updateProxyUriTextBox.Text = Settings.Instance.Global_Update_ProxyUri; _updateSignatureTextBox.Text = Settings.Instance.Global_Update_Signature; if (Settings.Instance.Global_Update_Option == UpdateOption.None) { _updateOptionNoneRadioButton.IsChecked = true; } else if (Settings.Instance.Global_Update_Option == UpdateOption.Check) { _updateOptionAutoCheckRadioButton.IsChecked = true; } else if (Settings.Instance.Global_Update_Option == UpdateOption.Update) { _updateOptionAutoUpdateRadioButton.IsChecked = true; } } { _signatureListViewItemCollection.AddRange(Settings.Instance.Global_DigitalSignatures.Select(n => new SignatureListViewItem(n))); _signatureListView.ItemsSource = _signatureListViewItemCollection; _signatureListViewUpdate(); } { _keywordCollection.AddRange(Settings.Instance.Global_SearchKeywords); _keywordListView.ItemsSource = _keywordCollection; _keywordListViewUpdate(); } { try { string extension = ".box"; string commandline = "\"" + Path.GetFullPath(Path.Combine(_serviceManager.Paths["Core"], "Amoeba.exe")) + "\" \"%1\""; string fileType = "Amoeba"; string verb = "open"; using (var regkey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension)) { if (fileType != (string)regkey.GetValue("")) throw new Exception(); } using (var shellkey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fileType)) { using (var shellkey2 = shellkey.OpenSubKey("shell\\" + verb)) { using (var shellkey3 = shellkey2.OpenSubKey("command")) { if (commandline != (string)shellkey3.GetValue("")) throw new Exception(); } } } Settings.Instance.Global_RelateBoxFile_IsEnabled = true; _boxRelateFileCheckBox.IsChecked = true; } catch { Settings.Instance.Global_RelateBoxFile_IsEnabled = false; _boxRelateFileCheckBox.IsChecked = false; } _boxOpenCheckBox.IsChecked = Settings.Instance.Global_OpenBox_IsEnabled; _boxExtractToTextBox.Text = Settings.Instance.Global_BoxExtractTo_Path; } { _MiningTimeTextBox.Text = Settings.Instance.Global_MiningTime.TotalMinutes.ToString(); } { _fontMessageFontFamilyComboBoxItemCollection.AddRange(Fonts.SystemFontFamilies.Select(n => n.ToString())); _fontMessageFontFamilyComboBoxItemCollection.Sort(); _fontMessageFontFamilyComboBox.ItemsSource = _fontMessageFontFamilyComboBoxItemCollection; _fontMessageFontFamilyComboBox.SelectedItem = Settings.Instance.Global_Fonts_Message_FontFamily; _fontMessageFontSizeTextBox.Text = Settings.Instance.Global_Fonts_Message_FontSize.ToString(); } }
private void Setting_Init() { NativeMethods.SetThreadExecutionState(ExecutionState.SystemRequired | ExecutionState.Continuous); { bool initFlag = false; _amoebaManager = new AmoebaManager(_serviceManager.Config.Cache.Path, _bufferManager); _amoebaManager.Load(_configrationDirectoryPaths["AmoebaManager"]); if (!File.Exists(Path.Combine(_serviceManager.Paths["Configuration"], "Amoeba.version"))) { initFlag = true; { var p = new System.Diagnostics.ProcessStartInfo(); p.UseShellExecute = true; p.FileName = Path.GetFullPath(Path.Combine(_serviceManager.Paths["Core"], "Amoeba.exe")); p.Arguments = "Relate on"; OperatingSystem osInfo = Environment.OSVersion; // Windows Vista以上。 if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version >= new Version(6, 0)) { p.Verb = "runas"; } try { System.Diagnostics.Process.Start(p); } catch (System.ComponentModel.Win32Exception) { } } { // Amoeba Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(AmoebaConverter.FromTagString("Tag:AAAABkFtb2ViYQEgyeOUT6BPIlq8Nfe1kndaS0ETNlmJY90wt-Osb-l2mZqamJsU"))); // Test Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(AmoebaConverter.FromTagString("Tag:AAAABFRlc3QBIMEj2xDMP6_RAoVbePTEZwHz8Fcd29tqB9MY0JZyn6eS5iXI_A"))); } { Settings.Instance.Global_SearchKeywords.Clear(); Settings.Instance.Global_SearchKeywords.Add("Box"); Settings.Instance.Global_SearchKeywords.Add("Picture"); Settings.Instance.Global_SearchKeywords.Add("Movie"); Settings.Instance.Global_SearchKeywords.Add("Music"); Settings.Instance.Global_SearchKeywords.Add("Archive"); Settings.Instance.Global_SearchKeywords.Add("Document"); Settings.Instance.Global_SearchKeywords.Add("Executable"); Settings.Instance.Global_UploadKeywords.Clear(); Settings.Instance.Global_UploadKeywords.Add("Document"); var pictureSearchItem = new SearchItem() { Name = "Type - \"Picture\"" }; pictureSearchItem.SearchNameRegexCollection.Add(new SearchContains<SearchRegex>(true, new SearchRegex(@"\.(jpeg|jpg|jfif|gif|png|bmp)$", true))); var movieSearchItem = new SearchItem() { Name = "Type - \"Movie\"" }; movieSearchItem.SearchNameRegexCollection.Add(new SearchContains<SearchRegex>(true, new SearchRegex(@"\.(mpeg|mpg|avi|divx|asf|wmv|rm|ogm|mov|flv|vob)$", true))); var musicSearchItem = new SearchItem() { Name = "Type - \"Music\"" }; musicSearchItem.SearchNameRegexCollection.Add(new SearchContains<SearchRegex>(true, new SearchRegex(@"\.(mp3|wma|m4a|ogg|wav|mid|mod|flac|sid)$", true))); var archiveSearchItem = new SearchItem() { Name = "Type - \"Archive\"" }; archiveSearchItem.SearchNameRegexCollection.Add(new SearchContains<SearchRegex>(true, new SearchRegex(@"\.(zip|rar|7z|lzh|iso|gz|bz|xz|tar|tgz|tbz|txz)$", true))); var documentSearchItem = new SearchItem() { Name = "Type - \"Document\"" }; documentSearchItem.SearchNameRegexCollection.Add(new SearchContains<SearchRegex>(true, new SearchRegex(@"\.(doc|txt|pdf|odt|rtf)$", true))); var executableSearchItem = new SearchItem() { Name = "Type - \"Executable\"" }; executableSearchItem.SearchNameRegexCollection.Add(new SearchContains<SearchRegex>(true, new SearchRegex(@"\.(exe|jar|sh|bat)$", true))); Settings.Instance.SearchControl_SearchTreeItem.Children.Clear(); Settings.Instance.SearchControl_SearchTreeItem.Children.Add(new SearchTreeItem(pictureSearchItem)); Settings.Instance.SearchControl_SearchTreeItem.Children.Add(new SearchTreeItem(movieSearchItem)); Settings.Instance.SearchControl_SearchTreeItem.Children.Add(new SearchTreeItem(musicSearchItem)); Settings.Instance.SearchControl_SearchTreeItem.Children.Add(new SearchTreeItem(archiveSearchItem)); Settings.Instance.SearchControl_SearchTreeItem.Children.Add(new SearchTreeItem(documentSearchItem)); Settings.Instance.SearchControl_SearchTreeItem.Children.Add(new SearchTreeItem(executableSearchItem)); } { var tempBox = new Box(); tempBox.Name = "Temp"; var box = new Box(); box.Name = "Box"; box.Boxes.Add(tempBox); var route = new Route(); route.Add(box.Name); Settings.Instance.LibraryControl_Box = box; Settings.Instance.LibraryControl_ExpandedPaths.Add(route); } _amoebaManager.ConnectionCountLimit = 32; _amoebaManager.ListenUris.Clear(); _amoebaManager.ListenUris.Add(string.Format("tcp:{0}:{1}", IPAddress.Any.ToString(), _random.Next(1024, ushort.MaxValue + 1))); _amoebaManager.ListenUris.Add(string.Format("tcp:[{0}]:{1}", IPAddress.IPv6Any.ToString(), _random.Next(1024, ushort.MaxValue + 1))); var ipv4ConnectionFilter = new ConnectionFilter(ConnectionType.Tcp, null, new UriCondition(@"tcp:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}).*"), null); var ipv6ConnectionFilter = new ConnectionFilter(ConnectionType.Tcp, null, new UriCondition(@"tcp:\[(\d|:)*\].*"), null); var tcpConnectionFilter = new ConnectionFilter(ConnectionType.Tcp, null, new UriCondition(@"tcp:.*"), null); var torConnectionFilter = new ConnectionFilter(ConnectionType.Socks5Proxy, "tcp:127.0.0.1:19050", new UriCondition(@"tor:.*"), null); var i2pConnectionFilter = new ConnectionFilter(ConnectionType.None, null, new UriCondition(@"i2p:.*"), null); _amoebaManager.Filters.Clear(); _amoebaManager.Filters.Add(ipv4ConnectionFilter); _amoebaManager.Filters.Add(ipv6ConnectionFilter); _amoebaManager.Filters.Add(tcpConnectionFilter); _amoebaManager.Filters.Add(torConnectionFilter); _amoebaManager.Filters.Add(i2pConnectionFilter); Directory.CreateDirectory(@"../Download"); _amoebaManager.DownloadDirectory = @"../Download"; if (CultureInfo.CurrentUICulture.Name == "ja-JP") { Settings.Instance.Global_UseLanguage = "Japanese"; } else { Settings.Instance.Global_UseLanguage = "English"; } // Trust.txtにあるノード情報を追加する。 if (File.Exists(Path.Combine(_serviceManager.Paths["Settings"], "Trust.txt"))) { var list = new List<string>(); using (StreamReader reader = new StreamReader(Path.Combine(_serviceManager.Paths["Settings"], "Trust.txt"), new UTF8Encoding(false))) { string line; while ((line = reader.ReadLine()) != null) { list.Add(line); } } Settings.Instance.Global_TrustSignatures.AddRange(list); } // Nodes.txtにあるノード情報を追加する。 if (File.Exists(Path.Combine(_serviceManager.Paths["Settings"], "Nodes.txt"))) { var list = new List<Node>(); using (StreamReader reader = new StreamReader(Path.Combine(_serviceManager.Paths["Settings"], "Nodes.txt"), new UTF8Encoding(false))) { string line; while ((line = reader.ReadLine()) != null) { list.Add(AmoebaConverter.FromNodeString(line)); } } _amoebaManager.SetOtherNodes(list); } } else { Version version; using (StreamReader reader = new StreamReader(Path.Combine(_serviceManager.Paths["Configuration"], "Amoeba.version"), new UTF8Encoding(false))) { version = new Version(reader.ReadLine()); } if (version <= new Version(4, 0, 18)) { // Covenant Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(AmoebaConverter.FromTagString("Tag:AAAACENvdmVuYW50ASBJDZp3I-Ng-iWJwmq2Us-q45iWCQQpekfoZExA5Zom9EZtMqE"))); } } using (StreamWriter writer = new StreamWriter(Path.Combine(_serviceManager.Paths["Configuration"], "Amoeba.version"), false, new UTF8Encoding(false))) { writer.WriteLine(_serviceManager.AmoebaVersion.ToString()); } _connectionSettingManager = new ConnectionSettingManager(_amoebaManager); _connectionSettingManager.Load(_configrationDirectoryPaths["ConnectionSettingManager"]); _overlayNetworkManager = new OverlayNetworkManager(_amoebaManager, _bufferManager); _overlayNetworkManager.Load(_configrationDirectoryPaths["OverlayNetworkManager"]); _transferLimitManager = new TransfarLimitManager(_amoebaManager); _transferLimitManager.Load(_configrationDirectoryPaths["TransfarLimitManager"]); _transferLimitManager.Start(); _catharsisManager = new CatharsisManager(_amoebaManager, _bufferManager, _serviceManager); _catharsisManager.Load(_configrationDirectoryPaths["CatharsisManager"]); if (initFlag) { _catharsisManager.Save(_configrationDirectoryPaths["CatharsisManager"]); _transferLimitManager.Save(_configrationDirectoryPaths["TransfarLimitManager"]); _overlayNetworkManager.Save(_configrationDirectoryPaths["OverlayNetworkManager"]); _connectionSettingManager.Save(_configrationDirectoryPaths["ConnectionSettingManager"]); _amoebaManager.Save(_configrationDirectoryPaths["AmoebaManager"]); Settings.Instance.Save(_configrationDirectoryPaths["Settings"]); } } }