added save with path (close #88)

This commit is contained in:
iAmAsval 2020-07-05 22:41:57 +02:00
parent b7c133dffb
commit ec51b7dd14
5 changed files with 41 additions and 25 deletions

View File

@ -404,7 +404,7 @@ namespace FModel
{
if (FModel_AssetsList.HasItems && FModel_AssetsList.SelectedIndex >= 0 && FModel_AssetsList.SelectedItem is ListBoxViewModel selectedItem)
{
if (selectedItem.Content.Equals(AvalonEditVm.avalonEditViewModel.OwerName)) // if selected item is actually displayed, just save
if (selectedItem.Content.Equals(AvalonEditVm.avalonEditViewModel.OwnerName)) // if selected item is actually displayed, just save
AvalonEditVm.avalonEditViewModel.Save(false);
else // extract (aka display) and save
{

View File

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
namespace PakReader.Parsers.Objects
{
@ -8,10 +9,12 @@ namespace PakReader.Parsers.Objects
/** Holds the ticks in 100 nanoseconds resolution since January 1, 0001 A.D. */
public readonly long Ticks;
public readonly string Date;
internal FDateTime(BinaryReader reader)
{
Ticks = reader.ReadInt64();
Date = new DateTime(Ticks).ToString("F");
}
}
}

View File

@ -22,7 +22,6 @@ namespace PakReader.Parsers.PropertyTagData
FAssetPackageData fAssetPackageData => fAssetPackageData.GetValue(),
FGameplayTagContainer fGameplayTagContainer => fGameplayTagContainer.GetValue(),
FSoftObjectPath fSoftObjectPath => fSoftObjectPath.GetValue(),
FDateTime fDateTime => fDateTime.Ticks,
FGuid fGuid => fGuid.Hex,
_ => Value
};

View File

@ -76,7 +76,7 @@ namespace FModel.Utils
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
using var reader = new StreamReader(asset);
AvalonEditVm.avalonEditViewModel.Set(reader.ReadToEnd(), selected.PakEntry.GetNameWithExtension(), AvalonEditVm.IniHighlighter);
AvalonEditVm.avalonEditViewModel.Set(reader.ReadToEnd(), mount + selected.PakEntry.Name, AvalonEditVm.IniHighlighter);
break;
}
case ".uproject":
@ -86,28 +86,28 @@ namespace FModel.Utils
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
using var reader = new StreamReader(asset);
AvalonEditVm.avalonEditViewModel.Set(reader.ReadToEnd(), selected.PakEntry.GetNameWithExtension());
AvalonEditVm.avalonEditViewModel.Set(reader.ReadToEnd(), mount + selected.PakEntry.Name);
break;
}
case ".locmeta":
{
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new LocMetaReader(asset), Formatting.Indented), selected.PakEntry.GetNameWithExtension());
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new LocMetaReader(asset), Formatting.Indented), mount + selected.PakEntry.Name);
break;
}
case ".locres":
{
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new LocResReader(asset).Entries, Formatting.Indented), selected.PakEntry.GetNameWithExtension());
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new LocResReader(asset).Entries, Formatting.Indented), mount + selected.PakEntry.Name);
break;
}
case ".udic":
{
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new FOodleDictionaryArchive(asset).Header, Formatting.Indented), selected.PakEntry.GetNameWithExtension());
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new FOodleDictionaryArchive(asset).Header, Formatting.Indented), mount + selected.PakEntry.Name);
break;
}
case ".bin":
@ -118,7 +118,7 @@ namespace FModel.Utils
{
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new FAssetRegistryState(asset), Formatting.Indented), selected.PakEntry.GetNameWithExtension());
AvalonEditVm.avalonEditViewModel.Set(JsonConvert.SerializeObject(new FAssetRegistryState(asset), Formatting.Indented), mount + selected.PakEntry.Name);
}
break;
}
@ -126,14 +126,14 @@ namespace FModel.Utils
{
using var asset = GetMemoryStream(selected.PakEntry.PakFileName, mount + selected.PakEntry.GetPathWithoutExtension());
asset.Position = 0;
ImageBoxVm.imageBoxViewModel.Set(SKBitmap.Decode(asset), selected.PakEntry.GetNameWithExtension());
ImageBoxVm.imageBoxViewModel.Set(SKBitmap.Decode(asset), mount + selected.PakEntry.Name);
break;
}
case ".ushaderbytecode":
case ".pck":
break;
default:
AvalonEditVm.avalonEditViewModel.Set(GetJsonProperties(selected.PakEntry, mount, true), selected.PakEntry.GetNameWithExtension());
AvalonEditVm.avalonEditViewModel.Set(GetJsonProperties(selected.PakEntry, mount, true), mount + selected.PakEntry.Name);
break;
}
@ -199,7 +199,8 @@ namespace FModel.Utils
var s = p.GetExport<USoundWave>();
if (s != null && (s.AudioFormat.String.Equals("OGG") || s.AudioFormat.String.Equals("OGG10000-1-1-1-1-1")))
{
string path = Properties.Settings.Default.OutputPath + "\\Sounds\\" + entry.GetNameWithoutExtension() + ".ogg";
string path = Properties.Settings.Default.OutputPath + "\\Sounds\\" + mount + entry.GetPathWithoutExtension() + ".ogg";
Directory.CreateDirectory(Path.GetDirectoryName(path));
if (File.Exists(path))
{
if (!Paks.IsFileWriteLocked(new FileInfo(path))) // aka isn't already being played, rewrite it
@ -233,7 +234,8 @@ namespace FModel.Utils
}
else if (s != null) // ADPCM and others
{
string path = Properties.Settings.Default.OutputPath + "\\Sounds\\" + entry.GetNameWithoutExtension() + "." + s.AudioFormat.String.ToLowerInvariant();
string path = Properties.Settings.Default.OutputPath + "\\Sounds\\" + mount + entry.GetPathWithoutExtension() + "." + s.AudioFormat.String.ToLowerInvariant();
Directory.CreateDirectory(Path.GetDirectoryName(path));
using var stream = new FileStream(path, FileMode.Create, FileAccess.Write);
using var writer = new BinaryWriter(stream);
writer.Write(s.Sound);

View File

@ -17,12 +17,13 @@ namespace FModel.ViewModels.AvalonEdit
static class AvalonEditVm
{
public static readonly AvalonEditViewModel avalonEditViewModel = new AvalonEditViewModel();
public static void Set(this AvalonEditViewModel vm, string assetProperties, string ownerName, IHighlightingDefinition format = null)
public static void Set(this AvalonEditViewModel vm, string assetProperties, string ownerPath, IHighlightingDefinition format = null)
{
Application.Current.Dispatcher.Invoke(delegate
{
vm.Document = new TextDocument(assetProperties);
vm.OwerName = ownerName;
vm.OwnerName = Path.GetFileName(ownerPath);
vm.OwnerPath = Path.GetDirectoryName(ownerPath);
vm.Highlighter = format ?? JsonHighlighter;
});
@ -33,7 +34,7 @@ namespace FModel.ViewModels.AvalonEdit
Application.Current.Dispatcher.Invoke(delegate
{
vm.Document = new TextDocument();
vm.OwerName = string.Empty;
vm.OwnerName = string.Empty;
vm.Highlighter = JsonHighlighter;
});
}
@ -48,21 +49,25 @@ namespace FModel.ViewModels.AvalonEdit
{
if (autoSave)
{
string path = Folders.GetUniqueFilePath(Properties.Settings.Default.OutputPath + "\\JSONs\\" + Path.ChangeExtension(vm.OwerName, ".json"));
File.WriteAllText(path, vm.Document.Text);
if (File.Exists(path))
string path = Properties.Settings.Default.OutputPath + "\\JSONs" + vm.OwnerPath + "\\";
string file = Folders.GetUniqueFilePath(path + Path.ChangeExtension(vm.OwnerName, ".json"));
Directory.CreateDirectory(path);
File.WriteAllText(file, vm.Document.Text);
if (File.Exists(file))
{
DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AvalonEditViewModel]", $"{vm.OwerName} successfully saved");
FConsole.AppendText(string.Format(Properties.Resources.SaveSuccess, Path.GetFileName(path)), FColors.Green, true);
DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AvalonEditViewModel]", $"{vm.OwnerName} successfully saved");
FConsole.AppendText(string.Format(Properties.Resources.SaveSuccess, Path.GetFileName(file)), FColors.Green, true);
}
}
else
{
Directory.CreateDirectory(Properties.Settings.Default.OutputPath + "\\JSONs" + vm.OwnerPath);
var saveFileDialog = new SaveFileDialog
{
Title = Properties.Resources.Save,
FileName = Path.ChangeExtension(vm.OwerName, ".json"),
InitialDirectory = Properties.Settings.Default.OutputPath + "\\JSONs\\",
FileName = Path.ChangeExtension(vm.OwnerName, ".json"),
InitialDirectory = Properties.Settings.Default.OutputPath + "\\JSONs" + vm.OwnerPath,
Filter = Properties.Resources.JsonFilter
};
if ((bool)saveFileDialog.ShowDialog())
@ -70,7 +75,7 @@ namespace FModel.ViewModels.AvalonEdit
File.WriteAllText(saveFileDialog.FileName, vm.Document.Text);
if (File.Exists(saveFileDialog.FileName))
{
DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AvalonEditViewModel]", $"{vm.OwerName} successfully saved");
DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AvalonEditViewModel]", $"{vm.OwnerName} successfully saved");
Globals.gNotifier.ShowCustomMessage(Properties.Resources.Success, Properties.Resources.DataSaved, string.Empty, saveFileDialog.FileName);
}
}
@ -116,12 +121,19 @@ namespace FModel.ViewModels.AvalonEdit
public class AvalonEditViewModel : PropertyChangedBase
{
private string _ownerName; // used to get the name of the file when saving or exporting
public string OwerName
public string OwnerName
{
get { return _ownerName; }
set { this.SetProperty(ref this._ownerName, value); }
}
private string _ownerPath;
public string OwnerPath
{
get { return _ownerPath; }
set { this.SetProperty(ref this._ownerPath, value); }
}
private TextDocument _document;
public TextDocument Document
{