private void Setting_Init() { NativeMethods.SetThreadExecutionState(ExecutionState.SystemRequired | ExecutionState.Continuous); { bool initFlag = false; _outoposManager = new OutoposManager(Path.Combine(App.DirectoryPaths["Configuration"], "Cache.bitmap"), App.Cache.Path, _bufferManager); _outoposManager.Load(_configrationDirectoryPaths["OutoposManager"]); if (!File.Exists(Path.Combine(App.DirectoryPaths["Configuration"], "Outopos.version"))) { initFlag = true; // デフォルトのTrustSignaturesの設定。 { Settings.Instance.Global_TrustSignatures.Add("Lyrise@OTAhpWvmegu50LT-p5dZ16og7U6bdpO4z5TInZxGsCs"); } // デフォルトのChatタグを設定。 { var amoebaTag = OutoposConverter.FromChatString("Chat:AAAAAAAGQW1vZWJhAQAAACCrzcPHuDlkIdAKPyrMvdoRizFo3IOOSlWhQhPTKBIOiWRXEcU"); var outoposTag = OutoposConverter.FromChatString("Chat:AAAAAAAHT3V0b3BvcwEAAAAgr9B65c-3yJS95GHleeXi3TekYOtScR4VzJRpz7AoQ294gS26"); var testTag = OutoposConverter.FromChatString("Chat:AAAAAAAEVGVzdAEAAAAgye1mG24NVcdu5Vb2UZXwrnT_kwhXUNWONT0W0m5IAyplJHYb"); Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(amoebaTag)); Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(outoposTag)); Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(testTag)); } { byte[] buffer = new byte[32]; using (var random = RandomNumberGenerator.Create()) { random.GetBytes(buffer); } _outoposManager.SetBaseNode(new Node(buffer, null)); } _outoposManager.ListenUris.Clear(); _outoposManager.ListenUris.Add(string.Format("tcp:{0}:{1}", IPAddress.Any.ToString(), _random.Next(1024, ushort.MaxValue + 1))); _outoposManager.ListenUris.Add(string.Format("tcp:[{0}]:{1}", IPAddress.IPv6Any.ToString(), _random.Next(1024, ushort.MaxValue + 1))); var ipv4ConnectionFilter = new ConnectionFilter() { ConnectionType = ConnectionType.Tcp, UriCondition = new UriCondition() { Value = @"tcp:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}).*", }, }; var ipv6ConnectionFilter = new ConnectionFilter() { ConnectionType = ConnectionType.Tcp, UriCondition = new UriCondition() { Value = @"tcp:\[(\d|:)*\].*", }, }; var tcpConnectionFilter = new ConnectionFilter() { ConnectionType = ConnectionType.Tcp, UriCondition = new UriCondition() { Value = @"tcp:.*", }, }; var torConnectionFilter = new ConnectionFilter() { ConnectionType = ConnectionType.Socks5Proxy, ProxyUri = "tcp:127.0.0.1:29050", UriCondition = new UriCondition() { Value = @"tor:.*", }, }; var i2pConnectionFilter = new ConnectionFilter() { ConnectionType = ConnectionType.None, UriCondition = new UriCondition() { Value = @"i2p:.*", }, }; _outoposManager.Filters.Clear(); _outoposManager.Filters.Add(ipv4ConnectionFilter); _outoposManager.Filters.Add(ipv6ConnectionFilter); _outoposManager.Filters.Add(tcpConnectionFilter); _outoposManager.Filters.Add(torConnectionFilter); _outoposManager.Filters.Add(i2pConnectionFilter); if (CultureInfo.CurrentUICulture.Name == "ja-JP") { Settings.Instance.Global_UseLanguage = "Japanese"; } else { Settings.Instance.Global_UseLanguage = "English"; } // ProfileItem { var digitalSignature = new DigitalSignature("Anonymous", DigitalSignatureAlgorithm.Rsa2048_Sha256); Settings.Instance.Global_DigitalSignatureCollection.Add(digitalSignature); var profileItem = new ProfileItem(); Settings.Instance.Global_ProfileItem = profileItem; { profileItem.UploadSignature = digitalSignature.ToString(); profileItem.Exchange = new Exchange(ExchangeAlgorithm.Rsa2048); // Upload { _outoposManager.UploadProfile(profileItem.Cost, profileItem.Exchange.GetExchangePublicKey(), profileItem.TrustSignatures, profileItem.DeleteSignatures, profileItem.Wikis, profileItem.Chats, digitalSignature); } } } // Nodes.txtにあるノード情報を追加する。 if (File.Exists(Path.Combine(App.DirectoryPaths["Settings"], "Nodes.txt"))) { var list = new List<Node>(); using (StreamReader reader = new StreamReader(Path.Combine(App.DirectoryPaths["Settings"], "Nodes.txt"), new UTF8Encoding(false))) { string line; while ((line = reader.ReadLine()) != null) { list.Add(OutoposConverter.FromNodeString(line)); } } _outoposManager.SetOtherNodes(list); } } else { Version version; using (StreamReader reader = new StreamReader(Path.Combine(App.DirectoryPaths["Configuration"], "Outopos.version"), new UTF8Encoding(false))) { version = new Version(reader.ReadLine()); } if (version <= new Version(1, 0, 0)) { // デフォルトのTrustSignaturesの設定。 { Settings.Instance.Global_TrustSignatures.Add("Lyrise@OTAhpWvmegu50LT-p5dZ16og7U6bdpO4z5TInZxGsCs"); } } } using (StreamWriter writer = new StreamWriter(Path.Combine(App.DirectoryPaths["Configuration"], "Outopos.version"), false, new UTF8Encoding(false))) { writer.WriteLine(App.OutoposVersion.ToString()); } _autoBaseNodeSettingManager = new AutoBaseNodeSettingManager(_outoposManager); _autoBaseNodeSettingManager.Load(_configrationDirectoryPaths["AutoBaseNodeSettingManager"]); _overlayNetworkManager = new OverlayNetworkManager(_outoposManager, _bufferManager); _overlayNetworkManager.Load(_configrationDirectoryPaths["OverlayNetworkManager"]); _catharsisManager = new CatharsisManager(_outoposManager, _bufferManager); _catharsisManager.Load(_configrationDirectoryPaths["CatharsisManager"]); if (initFlag) { _catharsisManager.Save(_configrationDirectoryPaths["CatharsisManager"]); _overlayNetworkManager.Save(_configrationDirectoryPaths["OverlayNetworkManager"]); _autoBaseNodeSettingManager.Save(_configrationDirectoryPaths["AutoBaseNodeSettingManager"]); _outoposManager.Save(_configrationDirectoryPaths["OutoposManager"]); Settings.Instance.Save(_configrationDirectoryPaths["MainWindow"]); } { var outoposPath = Path.Combine(App.DirectoryPaths["Configuration"], "Outopos"); var libraryPath = Path.Combine(App.DirectoryPaths["Configuration"], "Library"); try { if (Directory.Exists(outoposPath)) { if (Directory.Exists(outoposPath + ".old")) Directory.Delete(outoposPath + ".old", true); MainWindow.CopyDirectory(outoposPath, outoposPath + ".old"); } if (Directory.Exists(libraryPath)) { if (Directory.Exists(libraryPath + ".old")) Directory.Delete(libraryPath + ".old", true); MainWindow.CopyDirectory(libraryPath, libraryPath + ".old"); } } catch (Exception e2) { Log.Warning(e2); } } } }
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"]); } } }