static public bool AddTagToPwad(Tag tag, Pwad pwad) { var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { var pwadInTable = context.Pwads.First(p => p.Name == pwad.Name); var tagInTable = context.Tags.First(t => t.Name == tag.Name); PwadTag pwadTag = new PwadTag() { Pwad = pwadInTable, Tag = tagInTable }; pwadInTable.PwadTags.Add(pwadTag); tagInTable.PwadTags.Add(pwadTag); context.Pwads.Update(pwadInTable); context.Tags.Update(tagInTable); context.SaveChanges(); } return(true); }
static public bool ModifyPwad(Pwad pwad) { var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { try { var pwadToUpdate = context.Pwads.First(p => p.FileName == pwad.FileName); pwadToUpdate.Name = pwad.Name; pwadToUpdate.IsAMod = pwad.IsAMod; pwadToUpdate.IsALevelPack = pwad.IsALevelPack; pwadToUpdate.RequiredCompatibility = pwad.RequiredCompatibility; context.Pwads.Update(pwadToUpdate); context.SaveChanges(); } catch { return(false); } } return(true); }
static public bool CheckIfPwadExistsByFileLocation(Pwad pwad) { var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { return(context.Pwads.Any <Pwad>(p => p.FileLocation == pwad.FileLocation)); // returns true if file location match found; false if not. } }
private void btnPwad_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "WAD and PK3 files (*.wad;*.pk3)|*.wad;*.pk3|All files (*.*)|*.*", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; if (openFileDialog.ShowDialog() == true) { var newPwad = new Pwad() { FileLocation = openFileDialog.FileName }; var pwadOptions = new PwadOptions(newPwad); NavigationService.Navigate(pwadOptions, newPwad); } }
static public bool CheckPwadForTag(Pwad pwad, Tag tag) { var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { try { var pwadInTable = context.Pwads.Include(p => p.PwadTags).First(p => p.Name == pwad.Name); var tagInTable = context.Tags.First(t => t.Name == tag.Name); return(pwadInTable.PwadTags.Any(pt => pt.TagId == tagInTable.Id)); } catch (Exception) { return(false); } } }
static public bool DeletePwadByName(Pwad pwad) { var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { try { var pwadToUpdate = context.Pwads.First(p => p.FileName == pwad.FileName); context.Pwads.Remove(pwadToUpdate); context.SaveChanges(); } catch { return(false); } } return(true); }
static public bool AddNewPwad(Pwad pwad) { pwad.Completion = CompletionLevel.NotStarted; var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { try { context.Pwads.Add(pwad); context.SaveChanges(); } catch (Exception) { return(false); } } return(true); }
private void btnAddTag_Click(object sender, RoutedEventArgs e) { tagInProgress.Name = tbTagName.Text; tagInProgress.Description = tbDescription.Text; if (CheckValidity()) { Repository.AddNewTag(tagInProgress); foreach (var i in lbPwadsWithTag.Items) { var pwadToAddTag = new Pwad() { Name = i.ToString() }; Repository.AddTagToPwad(tagInProgress, pwadToAddTag); } Window.GetWindow(this).Close(); } else { MessageBox.Show("Unable to add tag: Name not unique", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public ModifyPwad(Pwad pwad) { InitializeComponent(); pwadInProgress = pwad; }
public EstablishDummyData() { var optionsBuilder = new DbContextOptionsBuilder <Context>(); string databaseLocation = "Data Source="; databaseLocation += System.AppDomain.CurrentDomain.BaseDirectory; databaseLocation += "malo.db"; Debug.WriteLine(databaseLocation); optionsBuilder.UseSqlite(databaseLocation); using (Context context = new Context(optionsBuilder.Options)) { //test data goes here Pwad scythe = new Pwad { FileName = "scythe.zip", Name = "Scythe", Description = "Scythe by Erik Alm", FileLocation = "C:\\DOOM\\scythe.wad", IsALevelPack = true, IsAMod = false }; context.Pwads.Add(scythe); Pwad tenSector = new Pwad { FileName = "10sector.zip", Name = "10 Sectors", Description = "Ten Sectors", FileLocation = "C:\\DOOM\\10sector.zip", IsALevelPack = true, IsAMod = false }; context.Pwads.Add(tenSector); Iwad doom2Iwad = new Iwad { FileName = "doom2.wad", Name = "Doom II", DescriptiveName = "Doom II v1.9", FileLocation = "C:\\DOOM\\doom2.wad" }; context.Iwads.Add(doom2Iwad); SourcePort crispyDoom = new SourcePort { FileName = "crispy-doom.exe", Name = "Crispy Doom", FileLocation = "C:\\DOOM\\crispy-doom.exe", ConfigFileLocation = "C:\\DOOM\\crispy-doom.cfg", HasCompLevel = false, MaximumCompatibility = Compatibility.LimitRemoving }; context.SourcePorts.Add(crispyDoom); context.SaveChanges(); var readwad = context.Pwads.ToList(); foreach (Pwad p in readwad) { Debug.WriteLine($"PWAD PK ID number {p.Id}"); Debug.WriteLine($"Name: {p.Name}"); Debug.WriteLine($"Description: {p.Description}"); Debug.WriteLine("---"); } new CommandLine(crispyDoom, doom2Iwad, new List <Pwad> { scythe }); } }
public PwadOptions(Pwad pwad) { pwadInProgress = pwad; InitializeComponent(); }