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
...
 
@@ -31,4 +31,13 @@ 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
...
 
@@ -3,4 +3,5 @@ using System.IO;
 
using System.IO.Compression;
 
using System.Collections.Generic;
 
using System.Diagnostics;
 
using System.Text.RegularExpressions;
 
using DesertPaintCodex.Util;
...
 
@@ -128,5 +129,5 @@ namespace DesertPaintCodex.Models
 
        {
 
            using StreamReader reader = new(ppFile);
 
            using StreamWriter writer = new(dpFile);
 
            using StreamWriter writer = new(dpFile, false);
 
            string?            line;
 
            while ((line = reader.ReadLine()) != null)
...
 
@@ -134,5 +135,5 @@ namespace DesertPaintCodex.Models
 
                string[] tokens = line.Split('|');
 
                //if ((tokens.Length > 0) && (tokens [0] != "//"))
 
                if ((tokens.Length != 5) && (tokens[0].Trim() != "//"))
 
                if ((tokens.Length == 5) && (tokens[0].Trim() != "//"))
 
                {
 
                    string reagent1  = tokens[0].Trim();
...
 
@@ -240,13 +241,12 @@ 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
 
            {
 
                // If there is an ingredients file, move it in.
 
                string importDir = Path.GetDirectoryName(reactionsFile) ?? "";
 
                File.Copy(
 
                    Path.Combine(importDir, "ingredients.txt"),
...
 
@@ -262,5 +262,10 @@ namespace DesertPaintCodex.Models
 
        public void Import(string file)
 
        {
 
            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
...
 
@@ -25,4 +25,6 @@ namespace DesertPaintCodex.Services
 
    
 
            Load(colorsPath);
 

	
 
            _initialized = true;
 
        }
 

	
Services/ProfileManager.cs
Show inline comments
...
 
@@ -52,4 +52,10 @@ 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;
 
using System.IO;
...
 
@@ -18,10 +19,20 @@ 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();
 

	
 
        public MainWindowViewModel()
...
 
@@ -54,34 +65,91 @@ 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
 
            {
 
                ProfileManager.CurrentProfile?.Import(fileName);
 
            }
 
            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");
 
            }
 
        }
 

	
 
        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();
 
        }
 

	
 
        public static async void ExportPaintRecipes()
 
        {
 
            string? fileName = await GetSaveFileName("Export Paint Recipes", NoFilters);
 
            string? fileName = await GetSaveFileName("Export Paint Recipes", NoFileFilters);
 
            if (!string.IsNullOrEmpty(fileName))
 
            {
...
 
@@ -92,5 +160,5 @@ namespace DesertPaintCodex.ViewModels
 
        public static async void ExportRibbonRecipes()
 
        {
 
            string? fileName = await GetSaveFileName("Export Ribbon Recipes", NoFilters);
 
            string? fileName = await GetSaveFileName("Export Ribbon Recipes", NoFileFilters);
 
            if (!string.IsNullOrEmpty(fileName))
 
            {
...
 
@@ -137,5 +205,5 @@ 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)
 
        {
 
            if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return null;
...
 
@@ -146,5 +214,6 @@ namespace DesertPaintCodex.ViewModels
 
            {
 
                Title         = title,
 
                Filters       = NoFilters, // filters,
 
                Filters         = filters,
 
                InitialFileName = fileName,
 
                AllowMultiple = false
 
            };
...
 
@@ -155,5 +224,5 @@ 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)
 
        {
 
            if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return null;
...
 
@@ -164,5 +233,6 @@ namespace DesertPaintCodex.ViewModels
 
            {
 
                Title   = title,
 
                Filters = NoFilters, // filters
 
                Filters         = filters,
 
                InitialFileName = fileName
 
            };
 

	
Views/MainWindow.axaml
Show inline comments
...
 
@@ -62,4 +62,5 @@
 
                    <MenuItem Header="Profile">
 
                        <MenuItem Header="Manage Profiles..." Command="{Binding ManageProfiles}"></MenuItem>
 
                        <Separator/>
 
                        <MenuItem Header="Import Profile..." Command="{Binding ImportProfile}">
 
                            <ToolTip.Tip>
...
 
@@ -72,5 +73,11 @@
 
                            </ToolTip.Tip>
 
                        </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>
 
                                Will generate a Practical Paint reactions file from the current profile.
...
 
@@ -78,5 +85,5 @@
 
                        </MenuItem>
 
                    </MenuItem>
 

	
 
                    <Separator/>
 
                    <MenuItem Header="Recipes">
 
                        <MenuItem Header="Export Paint Recipes..." Command="{Binding ExportPaintRecipes}">
...
 
@@ -90,4 +97,5 @@
 
                            </ToolTip.Tip>
 
                        </MenuItem>
 
                        <Separator/>
 
                        <MenuItem Header="Copy Paint Recipes to Clipboard" Command="{Binding CopyPaintRecipes}">
 
                            <ToolTip.Tip>
0 comments (0 inline, 0 general)