Ejemplo n.º 1
0
        public OptionsWindowViewModel(OptionsInfo options, DialogService dialogService)
        {
            _dialogService = dialogService;

            this.Options = options;

            this.Init();
        }
Ejemplo n.º 2
0
	void Awake(){
		optionsFileLocation = Application.dataPath + "/options.xml";
		if(!File.Exists(optionsFileLocation)){ //update as new options are added
			newOptions.resolution = Screen.currentResolution;
			saveCurrentOptions();
		}

		loadCurrentOptions();
		newOptions = currentOptions; // this is not a refrence pass it is a new copy
	}
Ejemplo n.º 3
0
	public void saveCurrentOptions(){
		FileStream stream = null;
		try{
			XmlSerializer serializer = new XmlSerializer(typeof(OptionsInfo));
			stream = new FileStream(optionsFileLocation, FileMode.OpenOrCreate);
			serializer.Serialize(stream, newOptions); // new options to disk here
			stream.Close();
		} catch(Exception ex){
			Debug.LogError(ex.ToString());
			if(stream != null)
				stream.Close();
		}
		currentOptions = newOptions;
	}
Ejemplo n.º 4
0
	/// <summary>
	/// Loads the currentOptions from disk.
	/// </summary>
	public void loadCurrentOptions(){
		FileStream stream = null;
		try{
			XmlSerializer serializer = new XmlSerializer(typeof(OptionsInfo));
			stream = new FileStream(optionsFileLocation, FileMode.Open);
			OptionsInfo container = (OptionsInfo)serializer.Deserialize(stream);
			currentOptions = container;
			stream.Close();
			//}catch(Exception ex){
		} catch{
			if(stream != null)
				stream.Close();
			//Debug.LogError(ex.ToString());
		}
	}
        private IHttpWebRequestOptions GetOptions(Uri endpoint)
        {
            lock (webRequestOptions) {
                OptionsInfo optionsInfo = webRequestOptions.Where(pair => endpoint.AbsoluteUri.StartsWith(pair.Key.AbsoluteUri))
                                          .OrderByDescending(pair => pair.Key.AbsoluteUri.Length)
                                          .Select(pair => pair.Value)
                                          .FirstOrDefault();

                if (optionsInfo is null)
                {
                    return(defaultWebRequestOptions);
                }

                return(HttpWebRequestOptions.Combine(defaultWebRequestOptions, optionsInfo.WebRequestOptions, optionsInfo.CopyIfNull));
            }
        }
Ejemplo n.º 6
0
	/// <summary>
	/// This will reload currentOptions if newOptions has
	/// </summary>
	public void revertToLastOptions(){
		newOptions = currentOptions;
		applyNewOptions();
	}
 public void Add(Uri endpoint, IHttpWebRequestOptions options, bool copyIfNull = true)
 {
     lock (webRequestOptions)
         webRequestOptions[endpoint] = new OptionsInfo(options, copyIfNull);
 }
Ejemplo n.º 8
0
 public MyMiddleware(RequestDelegate next, IOptions <OptionsInfo> options, ICodeGenerator codeGenerator)
 {
     _next                   = next;
     _codeGenerator          = codeGenerator;
     _environmentInfoOptions = options.Value;
 }
Ejemplo n.º 9
0
            public static void SetOptions(OptionsInfo options, AmoebaInterfaceManager serviceManager, DialogService dialogService)
            {
                try
                {
                    bool uploadFlag = false;

                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        // AccountInfo
                        {
                            var info = SettingsManager.Instance.AccountSetting;

                            if (info.Agreement == null || info.DigitalSignature != options.Account.DigitalSignature)
                            {
                                info.Agreement = new Agreement(AgreementAlgorithm.EcDhP521_Sha256);

                                uploadFlag = true;
                            }
                            else if (info.Comment != options.Account.Comment ||
                                     !CollectionUtils.Equals(info.TrustSignatures, options.Account.TrustSignatures) ||
                                     !CollectionUtils.Equals(info.UntrustSignatures, options.Account.UntrustSignatures) ||
                                     !CollectionUtils.Equals(info.Tags, options.Account.Tags))
                            {
                                uploadFlag = true;
                            }

                            info.DigitalSignature = options.Account.DigitalSignature;
                            info.Comment          = options.Account.Comment;
                            info.TrustSignatures.Clear();
                            info.TrustSignatures.AddRange(options.Account.TrustSignatures);
                            info.UntrustSignatures.Clear();
                            info.UntrustSignatures.AddRange(options.Account.UntrustSignatures);
                            info.Tags.Clear();
                            info.Tags.AddRange(options.Account.Tags);
                        }

                        // UpdateInfo
                        {
                            var info       = SettingsManager.Instance.UpdateSetting;
                            info.IsEnabled = options.Update.IsEnabled;
                            info.Signature = options.Update.Signature;
                        }

                        // SubscribeSignatures
                        {
                            SettingsManager.Instance.SubscribeSignatures.Clear();
                            SettingsManager.Instance.SubscribeSignatures.UnionWith(options.View.SubscribeSignatures);
                        }
                    }));

                    if (uploadFlag)
                    {
                        var info = SettingsManager.Instance.AccountSetting;

                        ProgressCircleService.Instance.Increment();

                        var task = serviceManager.SetProfile(
                            new ProfileContent(info.Comment,
                                               null,
                                               info.TrustSignatures,
                                               info.UntrustSignatures,
                                               info.Tags,
                                               info.Agreement.GetAgreementPublicKey()),
                            info.DigitalSignature,
                            CancellationToken.None);

                        task.ContinueWith((_) =>
                        {
                            ProgressCircleService.Instance.Decrement();
                        });
                    }

                    // AmoebaInterfaceManager
                    {
                        ServiceConfig serviceConfig;
                        {
                            ConnectionConfig connectionConfig;
                            {
                                TcpConnectionConfig tcpConnectionConfig;
                                {
                                    var type = TcpConnectionType.None;
                                    if (options.Connection.Tcp.Ipv4IsEnabled)
                                    {
                                        type |= TcpConnectionType.Ipv4;
                                    }
                                    if (options.Connection.Tcp.Ipv6IsEnabled)
                                    {
                                        type |= TcpConnectionType.Ipv6;
                                    }

                                    tcpConnectionConfig = new TcpConnectionConfig(
                                        type,
                                        options.Connection.Tcp.Ipv4Port,
                                        options.Connection.Tcp.Ipv6Port,
                                        options.Connection.Tcp.ProxyUri);
                                }

                                I2pConnectionConfig i2PConnectionConfig;
                                {
                                    i2PConnectionConfig = new I2pConnectionConfig(
                                        options.Connection.I2p.IsEnabled,
                                        options.Connection.I2p.SamBridgeUri);
                                }

                                CustomConnectionConfig customConnectionConfig;
                                {
                                    customConnectionConfig = new CustomConnectionConfig(
                                        options.Connection.Custom.LocationUris,
                                        options.Connection.Custom.ConnectionFilters,
                                        options.Connection.Custom.ListenUris);
                                }

                                CatharsisConfig catharsisConfig;
                                {
                                    var catharsisIpv4Config = new CatharsisIpv4Config(Array.Empty <string>(), Array.Empty <string>());

                                    catharsisConfig = new CatharsisConfig(catharsisIpv4Config);
                                }

                                connectionConfig = new ConnectionConfig(
                                    tcpConnectionConfig,
                                    i2PConnectionConfig,
                                    customConnectionConfig,
                                    catharsisConfig);
                            }

                            CoreConfig coreConfig;
                            {
                                NetworkConfig networkConfig;
                                {
                                    networkConfig = new NetworkConfig(
                                        options.Connection.Bandwidth.ConnectionCountLimit,
                                        options.Connection.Bandwidth.BandwidthLimit);
                                }

                                DownloadConfig downloadConfig;
                                {
                                    downloadConfig = new DownloadConfig(
                                        options.Data.Download.DirectoryPath,
                                        options.Data.Download.ProtectedPercentage);
                                }

                                coreConfig = new CoreConfig(networkConfig, downloadConfig);
                            }

                            MessageConfig messageConfig;
                            {
                                messageConfig = new MessageConfig(options.View.SubscribeSignatures);
                            }

                            serviceConfig = new ServiceConfig(coreConfig, connectionConfig, messageConfig);
                        }

                        serviceManager.SetConfig(serviceConfig);
                    }

                    // AmoebaInterfaceManager (Resize)
                    {
                        long orginalCacheSize = serviceManager.Size;

                        if (options.Data.Cache.Size < orginalCacheSize)
                        {
                            App.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                if (dialogService.ShowDialog(LanguagesManager.Instance.DataOptionsControl_CacheResize_Message,
                                                             MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK)
                                {
                                    Task.Run(() =>
                                    {
                                        ProgressCircleService.Instance.Increment();

                                        serviceManager.Resize(options.Data.Cache.Size);

                                        ProgressCircleService.Instance.Decrement();
                                    });
                                }
                            }));
                        }
                        else if (options.Data.Cache.Size > orginalCacheSize)
                        {
                            ProgressCircleService.Instance.Increment();

                            serviceManager.Resize(options.Data.Cache.Size);

                            ProgressCircleService.Instance.Decrement();
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
Ejemplo n.º 10
0
            public static OptionsInfo GetOptions(AmoebaInterfaceManager serviceManager)
            {
                try
                {
                    var options = new OptionsInfo();

                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        // Account
                        {
                            var info = SettingsManager.Instance.AccountSetting;
                            options.Account.DigitalSignature = info.DigitalSignature;
                            options.Account.Comment          = info.Comment;
                            options.Account.TrustSignatures.AddRange(info.TrustSignatures);
                            options.Account.UntrustSignatures.AddRange(info.UntrustSignatures);
                            options.Account.Tags.AddRange(info.Tags);
                        }

                        // View
                        {
                            options.View.SubscribeSignatures.AddRange(SettingsManager.Instance.SubscribeSignatures);
                        }

                        // Update
                        {
                            var info = SettingsManager.Instance.UpdateSetting;
                            options.Update.IsEnabled = info.IsEnabled;
                            options.Update.Signature = info.Signature;
                        }
                    }));

                    {
                        var config    = serviceManager.Config;
                        var cacheSize = serviceManager.Size;

                        // Connection
                        {
                            // Tcp
                            {
                                options.Connection.Tcp.ProxyUri      = config.Connection.Tcp.ProxyUri;
                                options.Connection.Tcp.Ipv4IsEnabled = config.Connection.Tcp.Type.HasFlag(TcpConnectionType.Ipv4);
                                options.Connection.Tcp.Ipv4Port      = config.Connection.Tcp.Ipv4Port;
                                options.Connection.Tcp.Ipv6IsEnabled = config.Connection.Tcp.Type.HasFlag(TcpConnectionType.Ipv6);
                                options.Connection.Tcp.Ipv6Port      = config.Connection.Tcp.Ipv6Port;
                            }

                            // I2p
                            {
                                options.Connection.I2p.IsEnabled    = config.Connection.I2p.IsEnabled;
                                options.Connection.I2p.SamBridgeUri = config.Connection.I2p.SamBridgeUri;
                            }

                            // Custom
                            {
                                options.Connection.Custom.LocationUris.AddRange(config.Connection.Custom.LocationUris);
                                options.Connection.Custom.ConnectionFilters.AddRange(config.Connection.Custom.ConnectionFilters);
                                options.Connection.Custom.ListenUris.AddRange(config.Connection.Custom.ListenUris);
                            }

                            // Bandwidth
                            {
                                options.Connection.Bandwidth.ConnectionCountLimit = config.Core.Network.ConnectionCountLimit;
                                options.Connection.Bandwidth.BandwidthLimit       = config.Core.Network.BandwidthLimit;
                            }
                        }

                        // Data
                        {
                            // Cache
                            {
                                options.Data.Cache.Size = cacheSize;
                            }

                            // Download
                            {
                                options.Data.Download.DirectoryPath       = config.Core.Download.BasePath;
                                options.Data.Download.ProtectedPercentage = config.Core.Download.ProtectedPercentage;
                            }
                        }
                    }

                    return(options);
                }
                catch (Exception e)
                {
                    Log.Error(e);

                    throw e;
                }
            }