private void OpenFromDialog() { if (IDEWindow.Instance.ViewModel.CurrentProject is null) { string path = this.CommonFileDialog(); if (path is null) { return; } ProjectFile file = JFile.Load <ProjectFile>(Path.GetDirectoryName(path), "project.json"); IDEWindow.Instance.ViewModel.CurrentProject = file.CreateModel(); App.Metadata.RecentlyOpenedProjects.Add(new RecentItem { Name = IDEWindow.Instance.ViewModel.CurrentProject.Name, Path = IDEWindow.Instance.ViewModel.CurrentProject.FilePath }); IDEWindow.Instance.ViewModel.CurrentProject.LoadMods(); App.Metadata.Save(); } else { MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show($"Changes have been made to {IDEWindow.Instance.ViewModel.CurrentProject.Name}. Would you like to save these changes before closing the project?", "Save Changes?", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { string path = this.CommonFileDialog(); if (path is null) { return; } IDEWindow.Instance.ViewModel.CurrentProject.Close(true); ProjectFile file = JFile.Load <ProjectFile>(Path.GetDirectoryName(path), "project.json"); IDEWindow.Instance.ViewModel.CurrentProject = file.CreateModel(); App.Metadata.RecentlyOpenedProjects.Add(new RecentItem { Name = IDEWindow.Instance.ViewModel.CurrentProject.Name, Path = IDEWindow.Instance.ViewModel.CurrentProject.FilePath }); IDEWindow.Instance.ViewModel.CurrentProject.LoadMods(); App.Metadata.Save(); } else if (result == MessageBoxResult.No) { string path = this.CommonFileDialog(); if (path is null) { return; } IDEWindow.Instance.ViewModel.CurrentProject.Close(false); ProjectFile file = JFile.Load <ProjectFile>(Path.GetDirectoryName(path), "project.json"); IDEWindow.Instance.ViewModel.CurrentProject = file.CreateModel(); App.Metadata.RecentlyOpenedProjects.Add(new RecentItem { Name = IDEWindow.Instance.ViewModel.CurrentProject.Name, Path = IDEWindow.Instance.ViewModel.CurrentProject.FilePath }); IDEWindow.Instance.ViewModel.CurrentProject.LoadMods(); App.Metadata.Save(); } else { return; } } }
public void LoadMods() { foreach (string x in Directory.GetDirectories(Path.Combine(this.FilePath, "mods"))) { MetadataFile metadataFile = JFile.Load <MetadataFile>(x, ".metadata"); Mod mod = metadataFile.CreateModel(); this.Mods.Add(mod); } }
private void AppStartup(object sender, StartupEventArgs args) { Instance = this; Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly()); Metadata = JFile.Load <UserMetaFile>(AssemblyDirectory, "metadata.json").CreateModel(); bool?_ = new Splash().ShowDialog(); }
private static void InitializePreferences() { if (!Directory.Exists(Metadata.AppDataDirectory)) { Directory.CreateDirectory(Metadata.AppDataDirectory); } Preferences = JFile.Load <PreferencesFile>(Metadata.AppDataDirectory, "preferences.json").CreateModel(); Preferences.Save(); Preferences.Load(); }
public void ItemFile_should_be_savable_and_loadable_without_error(ItemFile itemFile) { "Assume we have a file" .Hypothesize(x => { itemFile = new ItemFile { FilePath = Path.Combine(Testing.AssemblyDirectory, "testfiles"), FileName = "testitem.item" }; itemFile.Category = "TestCategory"; itemFile.Description = "Test Description"; itemFile.ID = "testitem"; itemFile.ImageName = "\testimage.png"; itemFile.Name = "Test Item"; itemFile.Price = 30; itemFile.Rarity = "Rare"; itemFile.Tags = new List <string>() { "reagent" }; itemFile.UnlocksBlueprint = new List <string> { "testitem2", "testitem3" }; }); "If we save the file" .Observe(x => { itemFile.Save(); }); "Then we should be able to load it with the information intact" .Conclude(x => { ItemFile loadedFile = JFile.Load <ItemFile>(Path.Combine(Testing.AssemblyDirectory, "testfiles"), "testitem.item"); itemFile.Category.Should().Be(loadedFile.Category); itemFile.Description.Should().Be(loadedFile.Description); itemFile.ID.Should().Be(loadedFile.ID); itemFile.ImageName.Should().Be(loadedFile.ImageName); itemFile.Name.Should().Be(loadedFile.Name); itemFile.Price.Should().Be(loadedFile.Price); itemFile.Rarity.Should().Be(loadedFile.Rarity); itemFile.Tags.Should().Contain(loadedFile.Tags); itemFile.UnlocksBlueprint.Should().Contain(loadedFile.UnlocksBlueprint); }); }
public static List <Template> GetTemplates() { Directory.CreateDirectory(TemplateDirectory); List <Template> templates = new List <Template> { BlankTemplate, DefaultUITemplate }; foreach (string directory in Directory.GetDirectories(TemplateDirectory)) { Log.Information("Template found: {Directory}. Loading...", Path.GetDirectoryName(directory)); string templateFile = Path.Combine(directory, "Template.json"); if (!File.Exists(templateFile)) { Log.Warning("{Directory} Template could not be loaded. Template.json file is invalid or missing.", Path.GetDirectoryName(directory)); continue; } templates.Add(JFile.Load <TemplateFile>(templateFile).CreateModel()); Log.Information("Load template {Directory} was successful.", Path.GetDirectoryName(directory)); } Log.Information("Total templates loaded: {Templates}", templates.Count); return(templates); }