GetData() public method

Retrieves a ToxData object that contains the profile data of this Tox instance.
public GetData ( ) : ToxData
return ToxData
コード例 #1
0
ファイル: CoreSelfTests.cs プロジェクト: WELL-E/SharpTox
        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();
        }
コード例 #2
0
ファイル: CoreSelfTests.cs プロジェクト: WELL-E/SharpTox
        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();
        }
コード例 #3
0
ファイル: ToxManager.cs プロジェクト: hexafluoride/Detox
        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";
        }
コード例 #4
0
ファイル: CoreSelfTests.cs プロジェクト: WELL-E/SharpTox
        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();
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        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);
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: WELL-E/Toxy-WPF
        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.");
                        }
                    }
                }
            }
        }