Represents an instance of tox.
Inheritance: IDisposable
Exemplo n.º 1
0
        public static FileTransferControl AddNewFileTransfer(this FlowDocument doc, Tox tox, FileTransfer transfer)
        {
            var fileTableCell = new TableCell();
            var fileTransferControl = new FileTransferControl(transfer, fileTableCell);

            var usernameParagraph = new Section();
            var newTableRow = new TableRow();
            newTableRow.Tag = transfer;

            var fileTransferContainer = new BlockUIContainer();
            fileTransferControl.HorizontalAlignment = HorizontalAlignment.Stretch;
            fileTransferControl.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            fileTransferContainer.Child = fileTransferControl;

            usernameParagraph.Blocks.Add(fileTransferContainer);
            usernameParagraph.Padding = new Thickness(0);

            fileTableCell.ColumnSpan = 3;
            fileTableCell.Blocks.Add(usernameParagraph);
            newTableRow.Cells.Add(fileTableCell);
            fileTableCell.Padding = new Thickness(0, 10, 0, 10);

            var MessageRows = (TableRowGroup)doc.FindName("MessageRows");
            MessageRows.Rows.Add(newTableRow);

            return fileTransferControl;
        }
Exemplo n.º 2
0
        public IncomingFileTransfer(ToxEventArgs.FileSendRequestEventArgs e, Tox tox, string savepath)
        {
            Tox = tox;

            ViewModel.SavePath = savepath;
            ViewModel.ID = e.FileNumber;
            ViewModel.Sender = e.FriendNumber;
            ViewModel.TotalBytes = e.FileSize;

            try
            {
                FileStream = new FileStream(ViewModel.SavePath, FileMode.Create);
            }
            catch
            {
                Dispose();
            }

            Tox.FileControl(ViewModel.Sender, ViewModel.ID, ToxFileControl.Resume);

            Tox.OnFileChunkReceived += Tox_OnFileChunkReceived;
            Tox.OnFileControlReceived += Tox_OnFileControlReceived;

            OnComplete += (v) => { Dispose(); };
        }
Exemplo n.º 3
0
        public static FileTransfer AddNewFileTransfer(this FlowDocument doc, Tox tox, int friendnumber, int filenumber, string filename, ulong filesize, bool is_sender)
        {
            FileTransferControl fileTransferControl = new FileTransferControl(tox.GetName(friendnumber), friendnumber, filenumber, filename, filesize);
            FileTransfer transfer = new FileTransfer() { FriendNumber = friendnumber, FileNumber = filenumber, FileName = filename, FileSize = filesize, IsSender = is_sender, Control = fileTransferControl };

            Section usernameParagraph = new Section();
            TableRow newTableRow = new TableRow();

            BlockUIContainer fileTransferContainer = new BlockUIContainer();
            fileTransferControl.HorizontalAlignment = HorizontalAlignment.Stretch;
            fileTransferControl.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            fileTransferContainer.Child = fileTransferControl;

            usernameParagraph.Blocks.Add(fileTransferContainer);
            usernameParagraph.Padding = new Thickness(0);

            TableCell fileTableCell = new TableCell();
            fileTableCell.ColumnSpan = 2;
            fileTableCell.Blocks.Add(usernameParagraph);
            newTableRow.Cells.Add(fileTableCell);
            fileTableCell.Padding = new Thickness(0, 10, 0, 10);

            TableRowGroup MessageRows = (TableRowGroup)doc.FindName("MessageRows");
            MessageRows.Rows.Add(newTableRow);

            return transfer;
        }
Exemplo n.º 4
0
        public void TestToxEncryptionLoad()
        {
            var tox1 = new Tox(ToxOptions.Default);
            tox1.Name = "Test";
            tox1.StatusMessage = "Hey";

            var key = new ToxEncryptionKey("heythisisatest");
            var data = tox1.GetData(key);

            Assert.IsNotNull(data, "Failed to encrypt the Tox data");
            Assert.IsTrue(data.IsEncrypted, "We encrypted the data, but toxencryptsave thinks we didn't");

            var tox2 = new Tox(ToxOptions.Default, ToxData.FromBytes(data.Bytes), key);

            if (tox2.Id != tox1.Id)
                Assert.Fail("Failed to load tox data correctly, tox id's don't match");

            if (tox2.Name != tox1.Name)
                Assert.Fail("Failed to load tox data correctly, names don't match");

            if (tox2.StatusMessage != tox1.StatusMessage)
                Assert.Fail("Failed to load tox data correctly, status messages don't match");

            tox1.Dispose();
            tox2.Dispose();
        }
Exemplo n.º 5
0
        public ToxCall(Tox tox, ToxAv toxav, int callindex, int friendnumber)
        {
            this.tox = tox;
            this.toxav = toxav;
            this.FriendNumber = friendnumber;

            CallIndex = callindex;
        }
Exemplo n.º 6
0
 public FileTransfer(Tox tox, int fileNumber, int friendNumber, ToxFileKind kind, long fileSize, string fileName, string path)
 {
     Tox = tox;
     FileNumber = fileNumber;
     FriendNumber = friendNumber;
     Kind = kind;
     FileSize = fileSize;
     FileName = fileName;
     Path = path;
 }
Exemplo n.º 7
0
        public static void AddNewMessageRow(this FlowDocument document, Tox tox, MessageData data, bool sameUser)
        {
            document.IsEnabled = true;

            //Make a new row
            TableRow newTableRow = new TableRow();
            newTableRow.Tag = data;

            //Make a new cell and create a paragraph in it
            TableCell usernameTableCell = new TableCell();
            usernameTableCell.Name = "usernameTableCell";
            usernameTableCell.Padding = new Thickness(10, 0, 0, 0);

            Paragraph usernameParagraph = new Paragraph();
            usernameParagraph.TextAlignment = data.IsAction ? TextAlignment.Right : TextAlignment.Left;
            usernameParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));

            if (data.Username != tox.Name.Replace("\n", "").Replace("\r", ""))
                usernameParagraph.SetResourceReference(Paragraph.ForegroundProperty, "AccentColorBrush");

            if(!sameUser)
                usernameParagraph.Inlines.Add(data.Username);

            usernameTableCell.Blocks.Add(usernameParagraph);

            //Make a new cell and create a paragraph in it
            TableCell messageTableCell = new TableCell();
            Paragraph messageParagraph = new Paragraph();
            messageParagraph.TextAlignment = TextAlignment.Left;

            if (!data.IsGroupMsg && data.IsSelf)
                messageParagraph.Foreground = Brushes.LightGray;

            bool isHighlight = data.IsGroupMsg && !data.IsSelf && data.Message.ToLower().Contains(tox.Name.ToLower());
            ProcessMessage(data, messageParagraph, false, isHighlight);

            messageTableCell.Blocks.Add(messageParagraph);

            TableCell timestampTableCell = new TableCell();
            Paragraph timestampParagraph = new Paragraph();
            timestampParagraph.Foreground = Brushes.LightGray;
            timestampTableCell.TextAlignment = TextAlignment.Right;
            timestampParagraph.Inlines.Add(data.Timestamp.ToShortTimeString());
            timestampTableCell.Blocks.Add(timestampParagraph);

            //Add the two cells to the row we made before
            newTableRow.Cells.Add(usernameTableCell);
            newTableRow.Cells.Add(messageTableCell);
            newTableRow.Cells.Add(timestampTableCell);

            //Adds row to the Table > TableRowGroup
            TableRowGroup MessageRows = (TableRowGroup)document.FindName("MessageRows");
            MessageRows.Rows.Add(newTableRow);
        }
Exemplo n.º 8
0
        public void Init()
        {
            var options = new ToxOptions(true, true);
            _tox1 = new Tox(options);
            _tox2 = new Tox(options);

            _tox1.AddFriend(_tox2.Id, "hey");
            _tox2.AddFriend(_tox1.Id, "hey");

            while (_tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None)
            {
                DoIterate();
            }
        }
Exemplo n.º 9
0
        public static void AddNewMessageRow(this FlowDocument document, Tox tox, MessageData data, EmojiProvider emojiProvider)
        {
            document.IsEnabled = true;

            //Make a new row
            TableRow newTableRow = new TableRow();

            //Make a new cell and create a paragraph in it
            TableCell usernameTableCell = new TableCell();
            usernameTableCell.Name = "usernameTableCell";
            usernameTableCell.Padding = new Thickness(10, 0, 0, 0);

            Paragraph usernameParagraph = new Paragraph();
            usernameParagraph.TextAlignment = data.IsAction ? TextAlignment.Right : TextAlignment.Left;
            usernameParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));

            if (data.Username != tox.GetSelfName())
                usernameParagraph.SetResourceReference(Paragraph.ForegroundProperty, "AccentColorBrush");

            usernameParagraph.Inlines.Add(data.Username);
            usernameTableCell.Blocks.Add(usernameParagraph);

            //Make a new cell and create a paragraph in it
            TableCell messageTableCell = new TableCell();
            Paragraph messageParagraph = new Paragraph();
            messageParagraph.TextAlignment = TextAlignment.Left;

            ProcessMessage(data, messageParagraph, false, emojiProvider);

            //messageParagraph.Inlines.Add(fakeHyperlink);
            messageTableCell.Blocks.Add(messageParagraph);

            TableCell timestampTableCell = new TableCell();
            Paragraph timestamParagraph = new Paragraph();
            timestampTableCell.TextAlignment = TextAlignment.Right;
            timestamParagraph.Inlines.Add(DateTime.Now.ToShortTimeString());
            timestampTableCell.Blocks.Add(timestamParagraph);
            timestamParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));
            //Add the two cells to the row we made before
            newTableRow.Cells.Add(usernameTableCell);
            newTableRow.Cells.Add(messageTableCell);
            newTableRow.Cells.Add(timestampTableCell);

            //Adds row to the Table > TableRowGroup
            TableRowGroup MessageRows = (TableRowGroup)document.FindName("MessageRows");
            MessageRows.Rows.Add(newTableRow);
        }
Exemplo n.º 10
0
        public void TestToxDataParsing()
        {
            var tox = new Tox(ToxOptions.Default);
            tox.Name = "Test";
            tox.StatusMessage = "Status";
            tox.Status = ToxUserStatus.Away;

            var data = tox.GetData();
            ToxDataInfo info = null;

            if (data == null || !data.TryParse(out info))
                Assert.Fail("Parsing the data file failed");

            if (info.Id != tox.Id || info.Name != tox.Name || info.SecretKey != tox.GetPrivateKey() || info.Status != tox.Status || info.StatusMessage != tox.StatusMessage)
                Assert.Fail("Parsing the data file failed");

            tox.Dispose();
        }
Exemplo n.º 11
0
        public void TestToxBootstrapAndConnectTcp()
        {
            var tox = new Tox(new ToxOptions(true, false));
            var error = ToxErrorBootstrap.Ok;

            foreach (var node in Globals.TcpRelays)
            {
                bool result = tox.AddTcpRelay(node, out error);
                if (!result || error != ToxErrorBootstrap.Ok)
                    Assert.Fail("Failed to bootstrap error: {0}, result: {1}", error, result);
            }

            tox.Start();
            while (!tox.IsConnected) { Thread.Sleep(10); }

            Console.WriteLine("Tox connected!");
            tox.Dispose();
        }
Exemplo n.º 12
0
        public void TestToxFriendRequest()
        {
            var options = new ToxOptions(true, true);
            var tox1 = new Tox(options);
            var tox2 = new Tox(options);
            var error = ToxErrorFriendAdd.Ok;
            string message = "Hey, this is a test friend request.";
            bool testFinished = false;

            tox1.AddFriend(tox2.Id, message, out error);
            if (error != ToxErrorFriendAdd.Ok)
                Assert.Fail("Failed to add friend: {0}", error);

            tox2.OnFriendRequestReceived += (sender, args) =>
            {
                if (args.Message != message)
                    Assert.Fail("Message received in the friend request is not the same as the one that was sent");

                tox2.AddFriendNoRequest(args.PublicKey, out error);
                if (error != ToxErrorFriendAdd.Ok)
                    Assert.Fail("Failed to add friend (no request): {0}", error);

                if (!tox2.FriendExists(0))
                    Assert.Fail("Friend doesn't exist according to core");

                testFinished = true;
            };

            while (!testFinished && tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None)
            {
                int time1 = tox1.Iterate();
                int time2 = tox2.Iterate();

                Thread.Sleep(Math.Min(time1, time2));
            }

            tox1.Dispose();
            tox2.Dispose();
        }
Exemplo n.º 13
0
        public void Init()
        {
            if (!File.Exists(DataPath))
            {
                Tox = new Tox(ToxOptions.Default);

                Tox.GetData().Save(DataPath);
            }
            else
            {
                Tox = new Tox(ToxOptions.Default, ToxData.FromDisk(DataPath));
            }

            foreach (var node in Nodes)
                Tox.Bootstrap(node);

            BindEvents();
            PopulateList();

            Tox.Start();

            Tox.StatusMessage = "Toxing on Detox";
        }
Exemplo n.º 14
0
        public void TestToxPortBind()
        {
            var tox1 = new Tox(new ToxOptions(true, false));
            var tox2 = new Tox(new ToxOptions(true, true));

            var error = ToxErrorGetPort.Ok;
            int port = tox1.GetUdpPort(out error);
            if (error != ToxErrorGetPort.NotBound)
                Assert.Fail("Tox bound to an udp port while it's not supposed to, port: {0}", port);

            port = tox2.GetUdpPort(out error);
            if (error != ToxErrorGetPort.Ok)
                Assert.Fail("Failed to bind to an udp port");

            tox1.Dispose();
            tox2.Dispose();
        }
Exemplo n.º 15
0
 public FileSender(Tox tox, int fileNumber, int friendNumber, ToxFileKind kind, long fileSize, string fileName, string path)
     : base(tox, fileNumber, friendNumber, kind, fileSize, fileName, path)
 {
 }
Exemplo n.º 16
0
        private bool CreateNewProfile(string profileName)
        {
            string path = Path.Combine(toxDataDir, profileName + ".tox");
            if (File.Exists(path))
                return false;

            Tox t = new Tox(ToxOptions.Default);
            t.Name = profileName;

            if (!t.GetData().Save(path))
            {
                t.Dispose();
                return false;
            }

            t.Dispose();
            return LoadProfile(profileName, false);
        }
Exemplo n.º 17
0
        public void TestToxSelfStatus()
        {
            var tox = new Tox(ToxOptions.Default);
            var status = ToxUserStatus.Away;
            tox.Status = status;

            if (tox.Status != status)
                Assert.Fail("Failed to set/retrieve status");

            tox.Dispose();
        }
Exemplo n.º 18
0
        public void TestToxSelfStatusMessage()
        {
            var tox = new Tox(ToxOptions.Default);
            string statusMessage = "Test status message";
            tox.StatusMessage = statusMessage;

            if (tox.StatusMessage != statusMessage)
                Assert.Fail("Failed to set/retrieve status message");

            tox.Dispose();
        }
Exemplo n.º 19
0
        public void TestToxProxySocks5()
        {
            var options = new ToxOptions(true, ToxProxyType.Socks5, "127.0.0.1", 9050);
            var tox = new Tox(options);
            var error = ToxErrorBootstrap.Ok;

            foreach (var node in Globals.TcpRelays)
            {
                bool result = tox.AddTcpRelay(node, out error);
                if (!result || error != ToxErrorBootstrap.Ok)
                    Assert.Fail("Failed to bootstrap, error: {0}, result: {1}", error, result);
            }

            tox.Start();
            while (!tox.IsConnected) { Thread.Sleep(10); }

            Console.WriteLine("Tox connected!");
            tox.Dispose();
        }
Exemplo n.º 20
0
        public void TestToxSelfName()
        {
            var tox = new Tox(ToxOptions.Default);
            string name = "Test name";
            tox.Name = name;

            if (tox.Name != name)
                Assert.Fail("Failed to set/retrieve name");

            tox.Dispose();
        }
Exemplo n.º 21
0
        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = new MainWindowViewModel();
            tox = new Tox(false);
            tox.Invoker = Dispatcher.BeginInvoke;
            tox.OnNameChange += tox_OnNameChange;
            tox.OnFriendMessage += tox_OnFriendMessage;
            tox.OnFriendAction += tox_OnFriendAction;
            tox.OnFriendRequest += tox_OnFriendRequest;
            tox.OnUserStatus += tox_OnUserStatus;
            tox.OnStatusMessage += tox_OnStatusMessage;
            tox.OnTypingChange += tox_OnTypingChange;
            tox.OnConnectionStatusChanged += tox_OnConnectionStatusChanged;
            tox.OnFileSendRequest += tox_OnFileSendRequest;
            tox.OnFileData += tox_OnFileData;
            tox.OnFileControl += tox_OnFileControl;

            tox.OnGroupInvite += tox_OnGroupInvite;
            tox.OnGroupMessage += tox_OnGroupMessage;
            tox.OnGroupAction += tox_OnGroupAction;
            tox.OnGroupNamelistChange += tox_OnGroupNamelistChange;

            toxav = new ToxAv(tox.GetPointer(), ToxAv.DefaultCodecSettings, 1);
            toxav.Invoker = Dispatcher.BeginInvoke;
            toxav.OnInvite += toxav_OnInvite;
            toxav.OnStart += toxav_OnStart;
            toxav.OnStarting += toxav_OnStart;
            toxav.OnEnd += toxav_OnEnd;
            toxav.OnEnding += toxav_OnEnd;
            toxav.OnPeerTimeout += toxav_OnEnd;
            toxav.OnRequestTimeout += toxav_OnEnd;
            toxav.OnReject += toxav_OnEnd;
            toxav.OnCancel += toxav_OnEnd;
            toxav.OnReceivedAudio += toxav_OnReceivedAudio;
            toxav.OnMediaChange += toxav_OnMediaChange;

            bool bootstrap_success = false;
            foreach (ToxNode node in nodes)
            {
                if (tox.BootstrapFromNode(node))
                    bootstrap_success = true;
            }

            if (File.Exists("data"))
            {
                if (!tox.Load("data"))
                {
                    MessageBox.Show("Could not load tox data, this program will now exit.", "Error");
                    Close();
                }
            }

            tox.Start();

            if (string.IsNullOrEmpty(tox.GetSelfName()))
                tox.SetName("Toxy User");

            this.ViewModel.MainToxyUser.Name = tox.GetSelfName();
            this.ViewModel.MainToxyUser.StatusMessage = tox.GetSelfStatusMessage();

            InitializeNotifyIcon();

            SetStatus(null);
            InitFriends();

            if (tox.GetFriendlistCount() > 0)
                this.ViewModel.SelectedChatObject = this.ViewModel.ChatCollection.OfType<IFriendObject>().FirstOrDefault();
        }
Exemplo n.º 22
0
 /// <summary>
 /// Initialises a new instance of toxav.
 /// </summary>
 /// <param name="tox"></param>
 /// <param name="maxCalls"></param>
 public ToxAv(Tox tox, int maxCalls)
     : this(tox.Handle, maxCalls)
 {
 }
Exemplo n.º 23
0
        public void TestToxNospam()
        {
            var tox = new Tox(ToxOptions.Default);
            byte[] randomBytes = new byte[sizeof(uint)];
            new Random().NextBytes(randomBytes);

            uint nospam = BitConverter.ToUInt32(randomBytes, 0);
            tox.SetNospam(nospam);

            if (nospam != tox.GetNospam())
                Assert.Fail("Failed to set/get nospam correctly, values don't match");

            tox.Dispose();
        }
Exemplo n.º 24
0
        public void TestToxLoadSecretKey()
        {
            var tox1 = new Tox(ToxOptions.Default);
            var key1 = tox1.GetPrivateKey();

            var tox2 = new Tox(ToxOptions.Default, key1);
            var key2 = tox2.GetPrivateKey();

            if (key1 != key2)
                Assert.Fail("Private keys do not match");
        }
Exemplo n.º 25
0
        public void TestToxLoadData()
        {
            var tox1 = new Tox(ToxOptions.Default);
            tox1.Name = "Test";
            tox1.StatusMessage = "Hey";

            var data = tox1.GetData();
            var tox2 = new Tox(ToxOptions.Default, ToxData.FromBytes(data.Bytes));

            if (tox2.Id != tox1.Id)
                Assert.Fail("Failed to load tox data correctly, tox id's don't match");

            if (tox2.Name != tox1.Name)
                Assert.Fail("Failed to load tox data correctly, names don't match");

            if (tox2.StatusMessage != tox1.StatusMessage)
                Assert.Fail("Failed to load tox data correctly, status messages don't match");

            tox1.Dispose();
            tox2.Dispose();
        }
Exemplo n.º 26
0
        private async void SwitchProfileButton_Click(object sender, RoutedEventArgs e)
        {
            string[] profiles = GetProfileNames(toxDataDir);
            if (profiles == null && profiles.Length < 1)
                return;

            var dialog = new SwitchProfileDialog(profiles, this);
            await this.ShowMetroDialogAsync(dialog);
            var result = await dialog.WaitForButtonPressAsync();
            await this.HideMetroDialogAsync(dialog);

            if (result == null)
                return;

            if (result.Result == SwitchProfileDialogResult.OK)
            {
                if (string.IsNullOrEmpty(result.Input))
                    return;

                if (!LoadProfile(result.Input, false))
                    await this.ShowMessageAsync("Error", "Could not load profile, make sure it exists/is accessible.");
            }
            else if (result.Result == SwitchProfileDialogResult.New)
            {
                string profile = await this.ShowInputAsync("New Profile", "Enter a name for your new profile.");
                if (string.IsNullOrEmpty(profile))
                    await this.ShowMessageAsync("Error", "Could not create profile, you must enter a name for your profile.");
                else
                {
                    if (!CreateNewProfile(profile))
                        await this.ShowMessageAsync("Error", "Could not create profile, did you enter a valid name?");
                }
            }
            else if (result.Result == SwitchProfileDialogResult.Import)
            {
                ToxData data = ToxData.FromDisk(result.Input);
                Tox t = new Tox(ToxOptions.Default, data);

                if (data == null)
                {
                    await this.ShowInputAsync("Error", "Could not load tox profile.");
                }
                else
                {
                    string profile = await this.ShowInputAsync("New Profile", "Enter a name for your new profile.");
                    if (string.IsNullOrEmpty(profile))
                        await this.ShowMessageAsync("Error", "Could not create profile, you must enter a name for your profile.");
                    else
                    {
                        string path = Path.Combine(toxDataDir, profile + ".tox");
                        if (!File.Exists(path))
                        {
                            t.Name = profile;

                            if (t.GetData().Save(path))
                                if (!LoadProfile(profile, false))
                                    await this.ShowMessageAsync("Error", "Could not load profile, make sure it exists/is accessible.");
                        }
                        else
                        {
                            await this.ShowMessageAsync("Error", "Could not create profile, a profile with the same name already exists.");
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
 public FileSender(Tox tox, int fileNumber, int friendNumber, ToxFileKind kind, long fileSize, string fileName, Stream stream)
     : base(tox, fileNumber, friendNumber, kind, fileSize, fileName, string.Empty)
 {
     _stream = stream;
 }
Exemplo n.º 28
0
        public void TestToxId()
        {
            var tox = new Tox(ToxOptions.Default);
            var toxId = new ToxId(tox.Id.PublicKey.GetBytes(), tox.Id.Nospam);

            if (toxId != tox.Id)
                Assert.Fail("Tox id's are not equal");
        }
Exemplo n.º 29
0
        private async void mv_Loaded(object sender, RoutedEventArgs e)
        {
            ToxOptions options;
            if (config.ProxyType != ToxProxyType.None)
                options = new ToxOptions(config.Ipv6Enabled, config.ProxyType, config.ProxyAddress, config.ProxyPort);
            else
                options = new ToxOptions(config.Ipv6Enabled, !config.UdpDisabled);

            tox = new Tox(options);

            var data = await loadTox();
            if (data != null)
                tox = new Tox(options, data);

            tox.OnFriendNameChanged += tox_OnFriendNameChanged;
            tox.OnFriendMessageReceived += tox_OnFriendMessageReceived;
            tox.OnFriendRequestReceived += tox_OnFriendRequestReceived;
            tox.OnFriendStatusChanged += tox_OnFriendStatusChanged;
            tox.OnFriendStatusMessageChanged += tox_OnFriendStatusMessageChanged;
            tox.OnFriendTypingChanged += tox_OnFriendTypingChanged;
            tox.OnConnectionStatusChanged += tox_OnConnectionStatusChanged;
            tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged;
            tox.OnFileSendRequestReceived += tox_OnFileSendRequestReceived;
            tox.OnFileChunkReceived += tox_OnFileChunkReceived;
            tox.OnFileControlReceived += tox_OnFileControlReceived;
            tox.OnFileChunkRequested += tox_OnFileChunkRequested;
            tox.OnReadReceiptReceived += tox_OnReadReceiptReceived;
            tox.OnGroupTitleChanged += tox_OnGroupTitleChanged;

            tox.OnGroupInvite += tox_OnGroupInvite;
            tox.OnGroupMessage += tox_OnGroupMessage;
            tox.OnGroupAction += tox_OnGroupAction;
            tox.OnGroupNamelistChange += tox_OnGroupNamelistChange;

            toxav = new ToxAv(tox.Handle, 1);
            toxav.OnInvite += toxav_OnInvite;
            toxav.OnStart += toxav_OnStart;
            toxav.OnEnd += toxav_OnEnd;
            toxav.OnPeerTimeout += toxav_OnEnd;
            toxav.OnRequestTimeout += toxav_OnEnd;
            toxav.OnReject += toxav_OnEnd;
            toxav.OnCancel += toxav_OnEnd;
            toxav.OnReceivedAudio += toxav_OnReceivedAudio;
            toxav.OnReceivedVideo += toxav_OnReceivedVideo;
            toxav.OnPeerCodecSettingsChanged += toxav_OnPeerCodecSettingsChanged;
            toxav.OnReceivedGroupAudio += toxav_OnReceivedGroupAudio;

            DoBootstrap();
            tox.Start();
            toxav.Start();

            if (string.IsNullOrEmpty(getSelfName()))
                tox.Name = "Tox User";

            if (string.IsNullOrEmpty(getSelfStatusMessage()))
                tox.StatusMessage = "Toxing on Toxy";

            ViewModel.MainToxyUser.Name = getSelfName();
            ViewModel.MainToxyUser.StatusMessage = getSelfStatusMessage();

            InitializeNotifyIcon();

            SetStatus(null, false);
            InitFriends();

            TextToSend.AddHandler(DragOverEvent, new DragEventHandler(Chat_DragOver), true);
            TextToSend.AddHandler(DropEvent, new DragEventHandler(Chat_Drop), true);

            ChatBox.AddHandler(DragOverEvent, new DragEventHandler(Chat_DragOver), true);
            ChatBox.AddHandler(DropEvent, new DragEventHandler(Chat_Drop), true);

            if (tox.Friends.Length > 0)
                ViewModel.SelectedChatObject = ViewModel.ChatCollection.OfType<IFriendObject>().FirstOrDefault();

            initDatabase();
            loadAvatars();
        }