public NewUserProfileViewModel(string directory) { this.WhenAnyValue(x => x.Password) .Select(x => !string.IsNullOrEmpty(x)) .ToPropertyEx(this, x => x.Encrypted); this.Login = ReactiveCommand.Create(() => { var filePath = Path.Combine(directory, this.Name + ".tox"); var tox = new Tox(ToxOptions.Default()); if (this.Encrypted) { var data = tox.GetData().Bytes; ToxEncryption.Encrypt(data, this.Password, out _); var toxdata = ToxData.FromBytes(data); tox.Dispose(); toxdata.Save(filePath); tox = new Tox(ToxOptions.Default(), toxdata, this.Password); } return(new ToxSession(tox, filePath)); }, this.WhenAnyValue(x => x.Name) .Select(fileName => { if (string.IsNullOrWhiteSpace(fileName)) { return(false); } var filePath = Path.Combine(directory, fileName + ".tox"); if (File.Exists(filePath)) { return(false); } if ((from i in Path.GetInvalidFileNameChars() from c in fileName select i == c).Any(x => x)) { return(false); } return(true); })); }
public ExistingUserProfileViewModel(string filePath, ToxData data) { this.FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath)); this.Data = data ?? throw new ArgumentNullException(nameof(data)); this.Login = ReactiveCommand.Create(() => { Tox tox = null; if (this.Encrypted) { tox = new Tox(ToxOptions.Default(), this.Data, this.Password); } else { tox = new Tox(ToxOptions.Default(), this.Data); } return(new ToxSession(tox, filePath)); }); }
static void Main(string[] args) { using (IToxOptions options = ToxOptions.Default()) using (ITox tox = options.Create()) { tox.OnFriendRequestReceived += OnFriendRequestReceived; tox.OnFriendMessageReceived += OnFriendMessageReceived; tox.OnConnectionStatusChanged += Tox_OnConnectionStatusChanged; foreach (ToxNode node in Nodes) { tox.Bootstrap(node, out _); } tox.Name = "SharpTox"; tox.StatusMessage = "Testing SharpTox"; using (ToxLoop.Start(tox)) { Console.WriteLine($"ID: {tox.Id}"); Console.ReadKey(); } void OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e) { //get the name associated with the friendnumber string name = tox.GetFriendName(e.FriendNumber, out _); //print the message to the console Console.WriteLine("<{0}> {1}", name, e.Message); } void OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e) { //automatically accept every friend request we receive tox.AddFriendNoRequest(e.PublicKey, out _); } } }