mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-10-05 14:46:39 -05:00
first pass at implementing the UI. Not sure that everything actually works yet, still needs more testing.
This commit is contained in:
42
Gen3Hex/View/WindowsFileSystem.cs
Normal file
42
Gen3Hex/View/WindowsFileSystem.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using HavenSoft.Gen3Hex.Model;
|
||||
using Microsoft.Win32;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace HavenSoft.Gen3Hex.View {
|
||||
public class WindowsFileSystem : IFileSystem {
|
||||
public LoadedFile OpenFile(params string[] extensionOptions) {
|
||||
var dialog = new OpenFileDialog { Filter = CreateFilterFromOptions(extensionOptions) };
|
||||
var result = dialog.ShowDialog();
|
||||
if (result != true) return null;
|
||||
if (!File.Exists(dialog.FileName)) return null;
|
||||
var data = File.ReadAllBytes(dialog.FileName);
|
||||
return new LoadedFile(dialog.FileName, data);
|
||||
}
|
||||
|
||||
public string RequestNewName(string currentName, params string[] extensionOptions) {
|
||||
var dialog = new SaveFileDialog { FileName = currentName, Filter = CreateFilterFromOptions(extensionOptions) };
|
||||
var result = dialog.ShowDialog();
|
||||
if (result != true) return null;
|
||||
return dialog.FileName;
|
||||
}
|
||||
|
||||
public bool Save(LoadedFile file) {
|
||||
if (!File.Exists(file.Name)) return false;
|
||||
File.WriteAllBytes(file.Name, file.Contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool? TrySavePrompt(LoadedFile file) {
|
||||
var result = MessageBox.Show($"Would you like to save {file.Name}?", Application.Current.MainWindow.Title, MessageBoxButton.YesNoCancel);
|
||||
if (result == MessageBoxResult.Cancel) return null;
|
||||
if (result == MessageBoxResult.No) return false;
|
||||
return Save(file);
|
||||
}
|
||||
|
||||
private static string CreateFilterFromOptions(string[] extensionOptions) {
|
||||
return string.Join(",", extensionOptions.Select(option => $"*.{option}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user