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"; }
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 ProfileInfo CreateNew(string profileName) { string path = Path.Combine(ProfileDataPath, profileName + ".tox"); if (File.Exists(path)) { return(null); } var tox = new Tox(ToxOptions.Default); tox.Name = profileName; tox.StatusMessage = "Toxing on Toxy"; try { if (!Directory.Exists(ProfileDataPath)) { Directory.CreateDirectory(ProfileDataPath); } } catch { return(null); } if (!tox.GetData().Save(path)) { return(null); } tox.Dispose(); return(new ProfileInfo(path)); }
public void TestToxIsDataEncrypted() { var tox = new Tox(ToxOptions.Default); var data = tox.GetData(); Assert.IsFalse(data.IsEncrypted); }
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 ProfileInfo CreateNew(string userName, string statusMessage) { string profilePath = Path.Combine(ProfileDataPath, userName + ProfileInfo.DotExt); if (File.Exists(profilePath)) { Logger.Log(LogLevel.Warning, "Attempt to override existing profile: " + userName); return(null); } using (Tox tox = new Tox(ToxOptions.Default)) { tox.Name = userName; tox.StatusMessage = statusMessage; try { if (!Directory.Exists(ProfileDataPath)) { Directory.CreateDirectory(ProfileDataPath); } } catch { return(null); } if (!tox.GetData().Save(profilePath)) { return(null); } } return(new ProfileInfo(profilePath)); }
public void SaveData(string newUserName = null, string newUserStatusMessage = null) { if (this.CurrentProfile == null || this.Tox == null) { Logger.Log(LogLevel.Warning, "Tried to save profile but there is no profile in use!"); return; } try { if (!Directory.Exists(ProfileDataPath)) { Directory.CreateDirectory(ProfileDataPath); } string oldProfilePath = null; if (!string.IsNullOrEmpty(newUserName)) { string newProfilePath = Path.Combine(ProfileDataPath, newUserName + ProfileInfo.DotExt); if (File.Exists(newProfilePath)) { Logger.Log(LogLevel.Warning, "Attempt to override existing profile: " + newUserName); return; } oldProfilePath = this.CurrentProfile.Path; this.CurrentProfile = this.CreateNew(newUserName, newUserStatusMessage); } using (FileStream fs = new FileStream(this.CurrentProfile.Path, FileMode.Create)) { byte[] data = Tox.GetData().Bytes; fs.Write(data, 0, data.Length); Logger.Log(LogLevel.Info, "Saved profile to disk"); } if (!string.IsNullOrEmpty(oldProfilePath)) { File.Delete(oldProfilePath); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "Could not save profile: " + ex.ToString()); } }
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 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(); }
public async Task SaveAsync() { if (CurrentProfile != null && Tox != null) { try { Directory.CreateDirectory(ProfileDataPath); using (var stream = new FileStream(CurrentProfile.Path, FileMode.Create)) { byte[] data = Tox.GetData().Bytes; await stream.WriteAsync(data, 0, data.Length); Debugging.Write("Saved profile to disk"); } } catch (Exception ex) { Debugging.Write("Could not save profile: " + ex.ToString()); } } else { Debugging.Write("Tried to save profile but there is no profile in use!"); } }
public void Save() { if (CurrentProfile != null && Tox != null) { try { Directory.CreateDirectory(ProfileDataPath); if (Tox.GetData().Save(CurrentProfile.Path)) { Debugging.Write("Saved profile to disk"); } else { Debugging.Write("Could not save profile"); } } catch (Exception ex) { Debugging.Write("Could not save profile: " + ex.ToString()); } } else { Debugging.Write("Tried to save profile but there is no profile in use!"); } }
public void Save(string filename) { tox.GetData().Save(filename); }