private void copyToStore(RealmFile file, Stream data) { data.Seek(0, SeekOrigin.Begin); using (var output = Storage.GetStream(file.GetStoragePath(), FileAccess.Write)) data.CopyTo(output); data.Seek(0, SeekOrigin.Begin); }
private void copyToStore(RealmFile file, Stream data) { data.Seek(0, SeekOrigin.Begin); using (var output = Storage.CreateFileSafely(file.GetStoragePath())) data.CopyTo(output); data.Seek(0, SeekOrigin.Begin); }
private bool checkFileExistsAndMatchesHash(RealmFile file) { string path = file.GetStoragePath(); // we may be re-adding a file to fix missing store entries. if (!Storage.Exists(path)) { return(false); } // even if the file already exists, check the existing checksum for safety. using (var stream = Storage.GetStream(path)) return(stream.ComputeSHA2Hash() == file.Hash); }
private static void migrateFiles <T>(IHasFiles <T> fileSource, Realm realm, IHasRealmFiles realmObject) where T : INamedFileInfo { foreach (var file in fileSource.Files) { var realmFile = realm.Find <RealmFile>(file.FileInfo.Hash); if (realmFile == null) { realm.Add(realmFile = new RealmFile { Hash = file.FileInfo.Hash }); } realmObject.Files.Add(new RealmNamedFileUsage(realmFile, file.Filename)); } }
//Adds realmlist file from file private void BAddFile_Click(object sender, EventArgs e) { if (game != "") { RealmFile.ShowDialog(); if (RealmFile.FileName.Contains(".wtf")) { string fileloc = RealmFile.FileName; string filenm = RealmFile.SafeFileName; string realmip = File.ReadAllText(fileloc); game = LCName.Text; realmip = realmip.Replace("set realmlist ", ""); if (!File.Exists(Path.Combine(datadir, game, realmip + ".wtf"))) { File.Copy(fileloc, Path.Combine(datadir, game, realmip + ".wtf")); RLList.Items.Clear(); string[] RealmLists = Directory.GetFiles(Path.Combine(datadir, game)); for (int i = 0; i < RealmLists.Length; i++) { int rem = Path.Combine(datadir + game).Length + 1; string add = RealmLists[i].Remove(0, (rem + 1)); string addclean = add.Replace(".wtf", ""); RLList.Items.Add(addclean); } } else if (File.Exists(Path.Combine(datadir, game, realmip + ".wtf"))) { MessageBox.Show("That realmlist already exists", "Input error"); } } else if (!RealmFile.FileName.Contains(".wtf")) { MessageBox.Show("Not a valid format", "Input error"); } } else { MessageBox.Show("Please select a client", "Input error"); } }
private void migrateSkins(DatabaseWriteUsage db) { // can be removed 20220530. var existingSkins = db.Context.SkinInfo .Include(s => s.Files) .ThenInclude(f => f.FileInfo) .ToList(); // previous entries in EF are removed post migration. if (!existingSkins.Any()) { return; } var userSkinChoice = config.GetBindable <string>(OsuSetting.Skin); int.TryParse(userSkinChoice.Value, out int userSkinInt); switch (userSkinInt) { case EFSkinInfo.DEFAULT_SKIN: userSkinChoice.Value = SkinInfo.DEFAULT_SKIN.ToString(); break; case EFSkinInfo.CLASSIC_SKIN: userSkinChoice.Value = SkinInfo.CLASSIC_SKIN.ToString(); break; } using (var realm = realmContextFactory.CreateContext()) using (var transaction = realm.BeginWrite()) { // only migrate data if the realm database is empty. // note that this cannot be written as: `realm.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`. if (!realm.All <SkinInfo>().Any(s => !s.Protected)) { foreach (var skin in existingSkins) { var realmSkin = new SkinInfo { Name = skin.Name, Creator = skin.Creator, Hash = skin.Hash, Protected = false, InstantiationInfo = skin.InstantiationInfo, }; foreach (var file in skin.Files) { var realmFile = realm.Find <RealmFile>(file.FileInfo.Hash); if (realmFile == null) { realm.Add(realmFile = new RealmFile { Hash = file.FileInfo.Hash }); } realmSkin.Files.Add(new RealmNamedFileUsage(realmFile, file.Filename)); } realm.Add(realmSkin); if (skin.ID == userSkinInt) { userSkinChoice.Value = realmSkin.ID.ToString(); } } } db.Context.RemoveRange(existingSkins); // Intentionally don't clean up the files, so they don't get purged by EF. transaction.Commit(); } }