Changeset - a5faa82faf6a
[Not reviewed]
default
0 6 0
Tess Snider (Malkyne) - 3 years ago 2021-07-21 08:10:50
this@malkyne.org
Import and Export should be working correctly. Can now import Practical Paint
reactions.txt files. Fixed a crash taht occurred when switching profiles.
6 files changed with 132 insertions and 32 deletions:
0 comments (0 inline, 0 general)
App.axaml.cs
Show inline comments
...
 
@@ -32,2 +32,11 @@ namespace DesertPaintCodex
 

	
 
        public void RefreshMainWindow()
 
        {
 
            if (ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return;
 
            
 
            desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
 
            CloseMainWindow();
 
            ShowMainWindow();
 
        }
 

	
 
        private void ShowWelcomeView()
Models/PlayerProfile.cs
Show inline comments
...
 
@@ -4,2 +4,3 @@ using System.IO.Compression;
 
using System.Collections.Generic;
 
using System.Diagnostics;
 
using System.Text.RegularExpressions;
...
 
@@ -129,3 +130,3 @@ namespace DesertPaintCodex.Models
 
            using StreamReader reader = new(ppFile);
 
            using StreamWriter writer = new(dpFile);
 
            using StreamWriter writer = new(dpFile, false);
 
            string?            line;
...
 
@@ -135,3 +136,3 @@ namespace DesertPaintCodex.Models
 
                //if ((tokens.Length > 0) && (tokens [0] != "//"))
 
                if ((tokens.Length != 5) && (tokens[0].Trim() != "//"))
 
                if ((tokens.Length == 5) && (tokens[0].Trim() != "//"))
 
                {
...
 
@@ -241,8 +242,6 @@ namespace DesertPaintCodex.Models
 

	
 
        public void ImportFromPP(string importDir)
 
        public void ImportFromPP(string reactionsFile)
 
        {
 
            // Convert old file.
 
            ConvertFromPP(
 
                Path.Combine(importDir, "reactions.txt"),
 
                _reactFile);
 
            ConvertFromPP(reactionsFile, _reactFile);
 
            try
...
 
@@ -250,2 +249,3 @@ namespace DesertPaintCodex.Models
 
                // If there is an ingredients file, move it in.
 
                string importDir = Path.GetDirectoryName(reactionsFile) ?? "";
 
                File.Copy(
...
 
@@ -263,3 +263,8 @@ namespace DesertPaintCodex.Models
 
        {
 
            ZipFile.ExtractToDirectory(file, Directory);
 
            if (!File.Exists(file))
 
            {
 
                Debug.WriteLine("Import file does not exist: " + file);
 
                // TODO: Show message dialog.
 
            }
 
            ZipFile.ExtractToDirectory(file, Directory, true);
 
        }
Services/PaletteService.cs
Show inline comments
...
 
@@ -26,2 +26,4 @@ namespace DesertPaintCodex.Services
 
            Load(colorsPath);
 

	
 
            _initialized = true;
 
        }
Services/ProfileManager.cs
Show inline comments
...
 
@@ -53,2 +53,8 @@ namespace DesertPaintCodex.Services
 

	
 
        public static void ReloadProfile()
 
        {
 
            if (CurrentProfile == null) return;
 
            LoadProfile(CurrentProfile.Name);
 
        }
 

	
 
        public static PlayerProfile CreateNewProfile(string name)
ViewModels/MainWindowViewModel.cs
Show inline comments
 
using System.Collections.Generic;
 
using System;
 
using System.Collections.Generic;
 
using System.Diagnostics;
...
 
@@ -19,8 +20,18 @@ namespace DesertPaintCodex.ViewModels
 
        private string _statusText = string.Empty;
 
        public string StatusText { get => _statusText; private set => this.RaiseAndSetIfChanged(ref _statusText, value); }
 

	
 
        public string StatusText
 
        {
 
            get => _statusText;
 
            private set => this.RaiseAndSetIfChanged(ref _statusText, value);
 
        }
 
        
 
        private static readonly List<string> ZipFileExtensions = new() { $"*.zip;" };
 
        private static readonly FileDialogFilter ZipDialogFilter = new() {Extensions = ZipFileExtensions};
 
        private static readonly List<FileDialogFilter> ZipDialogFilters = new() { ZipDialogFilter };
 
        private static readonly List<FileDialogFilter> NoFilters = new();
 
        private static readonly List<string> ZipFileExtensions = new() {"zip"};
 
        private static readonly FileDialogFilter ZipFileFilter = new() {Extensions = ZipFileExtensions, Name = "Zip"};
 
        private static readonly List<FileDialogFilter> ZipFileFilters = new() {ZipFileFilter};
 

	
 
        private static readonly List<string> TxtFileExtensions = new() {"txt"};
 
        private static readonly FileDialogFilter TxtFileFilter = new() {Extensions = TxtFileExtensions, Name = "Text"};
 
        private static readonly List<FileDialogFilter> TxtFileFilters = new() {TxtFileFilter};
 
        
 
        private static readonly List<FileDialogFilter> NoFileFilters = new();
 

	
...
 
@@ -55,6 +66,9 @@ namespace DesertPaintCodex.ViewModels
 

	
 
        public static async void ImportProfile()
 
        public async void ImportProfile()
 
        {
 
            string? fileName = await GetLoadFileName("Open Zipped Profile", ZipDialogFilters);
 
            if (!string.IsNullOrEmpty(fileName))
 
            string? fileName = await GetLoadFileName("Open Zipped Profile", ZipFileFilters);
 
            
 
            if (string.IsNullOrEmpty(fileName)) return;
 

	
 
            try
 
            {
...
 
@@ -62,10 +76,49 @@ namespace DesertPaintCodex.ViewModels
 
            }
 
            catch (Exception e)
 
            {
 
                Debug.WriteLine("ImportProfile threw exception " + e);
 
                await ShowMessageBox("Import Failed",
 
                    "Your file could not be imported. It must be a zip file containing a Desert Paint Codex profile.", "OK");
 
            }
 

	
 
            ProfileManager.ReloadProfile();
 
            
 
            if (Application.Current is not App app) return;
 
            
 
            app.RefreshMainWindow();
 
        }
 

	
 
        public async void ExportProfile()
 
        {
 
            string? fileName = await GetSaveFileName("Save Zipped Profile", ZipFileFilters);
 
            
 
            if (string.IsNullOrEmpty(fileName)) return;
 
            
 
            try
 
            {
 
                ProfileManager.CurrentProfile?.Export(fileName);
 
            }
 
            catch (Exception e)
 
            {
 
                Debug.WriteLine("ExportProfile threw exception " + e);
 
                await ShowMessageBox("Export Failed",
 
                    "Your profile could not be exported. Please ensure that you are providing a valid filename for the zip file that we are creating.", "OK");
 
            }
 
        }
 

	
 
        public static async void ExportProfile()
 
        public async void ExportForPP(object f)
 
        {
 
            string? fileName = await GetSaveFileName("Save Practical Paint File", TxtFileFilters, "reactions.txt");
 
            
 
            if (string.IsNullOrEmpty(fileName)) return;
 
            
 
            try
 
        {
 
            string? fileName = await GetSaveFileName("Save Zipped Profile", ZipDialogFilters);
 
            if (!string.IsNullOrEmpty(fileName))
 
                ProfileManager.CurrentProfile?.SaveToPP(fileName);
 
            }
 
            catch (Exception e)
 
            {
 
                ProfileManager.CurrentProfile?.Import(fileName);
 
                Debug.WriteLine("ExportForPP threw exception " + e);
 
                await ShowMessageBox("Export Failed",
 
                    "Please ensure that you have provided a valid file path for your reactions file.", "OK");
 
            }
...
 
@@ -73,9 +126,24 @@ namespace DesertPaintCodex.ViewModels
 

	
 
        public static async void ExportForPP()
 
        public async void ImportFromPP()
 
        {
 
            string? fileName = await GetLoadFileName("Import Reactions File", TxtFileFilters, "reactions.txt");
 
            
 
            if (string.IsNullOrEmpty(fileName)) return;
 

	
 
            try
 
        {
 
            string? fileName = await GetSaveFileName("Save Practical Paint File", NoFilters);
 
            if (!string.IsNullOrEmpty(fileName))
 
                ProfileManager.CurrentProfile?.ImportFromPP(fileName);
 
            }
 
            catch (Exception e)
 
            {
 
                ProfileManager.CurrentProfile?.SaveToPP(fileName);
 
                Debug.WriteLine("ImportFromPP threw exception " + e);
 
                await ShowMessageBox("Import Failed",
 
                    "Your file could not be imported. It must be a valid Practical Paint reactions.txt file.", "OK");
 
            }
 

	
 
            ProfileManager.ReloadProfile();
 
            
 
            if (Application.Current is not App app) return;
 
            
 
            app.RefreshMainWindow();
 
        }
...
 
@@ -84,3 +152,3 @@ namespace DesertPaintCodex.ViewModels
 
        {
 
            string? fileName = await GetSaveFileName("Export Paint Recipes", NoFilters);
 
            string? fileName = await GetSaveFileName("Export Paint Recipes", NoFileFilters);
 
            if (!string.IsNullOrEmpty(fileName))
...
 
@@ -93,3 +161,3 @@ namespace DesertPaintCodex.ViewModels
 
        {
 
            string? fileName = await GetSaveFileName("Export Ribbon Recipes", NoFilters);
 
            string? fileName = await GetSaveFileName("Export Ribbon Recipes", NoFileFilters);
 
            if (!string.IsNullOrEmpty(fileName))
...
 
@@ -138,3 +206,3 @@ namespace DesertPaintCodex.ViewModels
 

	
 
        private static async Task<string?> GetLoadFileName(string title, List<FileDialogFilter> filters)
 
        private static async Task<string?> GetLoadFileName(string title, List<FileDialogFilter> filters, string? fileName = null)
 
        {
...
 
@@ -147,3 +215,4 @@ namespace DesertPaintCodex.ViewModels
 
                Title         = title,
 
                Filters       = NoFilters, // filters,
 
                Filters         = filters,
 
                InitialFileName = fileName,
 
                AllowMultiple = false
...
 
@@ -156,3 +225,3 @@ namespace DesertPaintCodex.ViewModels
 
        
 
        private static async Task<string?> GetSaveFileName(string title, List<FileDialogFilter> filters)
 
        private static async Task<string?> GetSaveFileName(string title, List<FileDialogFilter> filters, string? fileName = null)
 
        {
...
 
@@ -165,3 +234,4 @@ namespace DesertPaintCodex.ViewModels
 
                Title   = title,
 
                Filters = NoFilters, // filters
 
                Filters         = filters,
 
                InitialFileName = fileName
 
            };
Views/MainWindow.axaml
Show inline comments
...
 
@@ -63,2 +63,3 @@
 
                        <MenuItem Header="Manage Profiles..." Command="{Binding ManageProfiles}"></MenuItem>
 
                        <Separator/>
 
                        <MenuItem Header="Import Profile..." Command="{Binding ImportProfile}">
...
 
@@ -73,3 +74,9 @@
 
                        </MenuItem>
 
                        <MenuItem Header="Export for PracticalPaint..." Command="{Binding ExportForPP}">
 
                        <Separator/>
 
                        <MenuItem Header="Import PracticalPaint Reactions..." Command="{Binding ImportFromPP}">
 
                            <ToolTip.Tip>
 
                                Will import a Practical Paint reactions file, replacing this profile's reactions.
 
                            </ToolTip.Tip>
 
                        </MenuItem>
 
                        <MenuItem Header="Export PracticalPaint Reactions..." Command="{Binding ExportForPP}">
 
                            <ToolTip.Tip>
...
 
@@ -79,3 +86,3 @@
 
                    </MenuItem>
 

	
 
                    <Separator/>
 
                    <MenuItem Header="Recipes">
...
 
@@ -91,2 +98,3 @@
 
                        </MenuItem>
 
                        <Separator/>
 
                        <MenuItem Header="Copy Paint Recipes to Clipboard" Command="{Binding CopyPaintRecipes}">
0 comments (0 inline, 0 general)