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(); }
public void TestToxEncryptionLoad() { var tox1 = new Tox(ToxOptions.Default); tox1.Name = "Test"; tox1.StatusMessage = "Hey"; string password = "******"; var data = tox1.GetData(password); 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), password); 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(); }
public async Task RestoreDataAsync() { try { var currentUserPublicKey = ApplicationData.Current.RoamingSettings.Values["currentUserPublicKey"]; var file = await ApplicationData.Current.RoamingFolder.GetFileAsync(currentUserPublicKey + ".tox"); var toxData = (await FileIO.ReadBufferAsync(file)).ToArray(); SetCurrent(new ExtendedTox(new ToxOptions(true, true), ToxData.FromBytes(toxData))); } catch { // TODO: Exception handling! } }
public static async Task <ProfileViewModel> GetProfileViewModelFromFile(IDataService dataService, StorageFile file) { var data = (await FileIO.ReadBufferAsync(file)).ToArray(); var toxData = ToxData.FromBytes(data); ToxDataInfo toxDataInfo; toxData.TryParse(out toxDataInfo); if (toxDataInfo == null) { return(null); } return(new ProfileViewModel(dataService, toxData, toxDataInfo)); }
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); })); }