Skip to content

Commit

Permalink
- Fixed small bug that occured when opening a project while another p…
Browse files Browse the repository at this point in the history
…roject was already loaded

- A backup is now created before importing project data
- Fixed a bug that occured if not all expected .json files existed during backup
- Added log file %appdata%\Eos Toolset\eos.log for better bug reporting
  • Loading branch information
Cjreek committed Mar 28, 2023
1 parent fa7b24a commit 3edd8b4
Show file tree
Hide file tree
Showing 13 changed files with 893 additions and 557 deletions.
6 changes: 6 additions & 0 deletions eos-edit/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Eos.Config;
using Eos.Nwn;
using Eos.Repositories;
using Eos.Services;
using Eos.ViewModels;
using Eos.Views;
using Nwn.Tga;
Expand All @@ -19,6 +20,7 @@ public partial class App : Application
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
Log.Info("Initializing Eos-Toolset");
}

public override void OnFrameworkInitializationCompleted()
Expand All @@ -35,6 +37,8 @@ public override void OnFrameworkInitializationCompleted()
}

base.OnFrameworkInitializationCompleted();

Log.Info("Avalonia Framework initialization completed");
}

private void Desktop_Startup(object? sender, ControlledApplicationLifetimeStartupEventArgs e)
Expand All @@ -46,6 +50,8 @@ private void Desktop_Startup(object? sender, ControlledApplicationLifetimeStartu
MasterRepository.Resources.RegisterResourceLoader(NWNResourceType.NSS, ScriptSourceLoader);

MasterRepository.Load();

Log.Info("Initialization complete!");
}

private object? TargaResourceLoader(Stream stream)
Expand Down
6 changes: 5 additions & 1 deletion eos-edit/ViewModels/Dialogs/ImportDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Eos.Services;
using Eos.Repositories;
using Eos.Services;
using Eos.ViewModels.Base;
using ReactiveUI;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -168,6 +170,8 @@ protected override bool GetCanResize()
return;
}
MasterRepository.Project.CreateBackup();
var importService = new ImportService(vm.Files, vm.TlkFile, vm.OverrideSettingIndex > 0, vm.OverrideSettingIndex == 2, vm.NewDataSettingIndex > 0, vm.ExtractOther ? vm.ExtractTo : "");
importService.DoImport();
Expand Down
2 changes: 2 additions & 0 deletions eos-edit/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ private void MessageHandler(MessageType type, object? message, object? param)
case MessageType.OpenProject:
if (!inProjectUpdate)
{
CloseAllProjectDetails();

MasterRepository.Project.Load((String?)message ?? "");
MessageDispatcher.Send(MessageType.ChangeLanguage, MasterRepository.Project.DefaultLanguage, null);
MessageDispatcher.Send(MessageType.UpdateProject, MasterRepository.Project, null);
Expand Down
2 changes: 1 addition & 1 deletion eos-edit/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Eos.Views.MainWindow" MinHeight="300" MinWidth="500"
Height="700" Width="1100" Loaded="mainWindow_Loaded"
x:Name="mainWindow" Tag="Eos Toolset v0.63a" FontFamily="Segoe UI"
x:Name="mainWindow" Tag="Eos Toolset v0.63b" FontFamily="Segoe UI"
Closing="mainWindow_Closing"
Icon="/Assets/Icons/Eos.ico">
<Window.Title>
Expand Down
95 changes: 75 additions & 20 deletions eos/Config/EosConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Eos.Nwn.Tlk;
using Eos.Services;
using Eos.Types;
using Microsoft.Win32;
using System;
Expand Down Expand Up @@ -55,7 +56,11 @@ private static String FindNwnBasePath()
string path;

path = Environment.GetEnvironmentVariable("NWN_ROOT") ?? "";
if ((path != "") && (Directory.Exists(path))) return path;
if ((path != "") && (Directory.Exists(path)))
{
Log.Info("Found installation via NWN_ROOT at: {0}", path);
return path;
}

// Steam
var steamPath = Path.Combine("Steam", "steamapps", "common", "Neverwinter Nights");
Expand All @@ -66,23 +71,32 @@ private static String FindNwnBasePath()
path = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)") ?? "", steamPath);

if (Directory.Exists(Path.Combine(path, "data")))
{
Log.Info("Found Steam installation at: {0}", path);
return path;
}
}
else if (Environment.OSVersion.Platform == PlatformID.Unix)
{
var home = Environment.GetEnvironmentVariable("HOME") ?? "";
path = Path.Combine(home, ".local", "share", steamPath);

if (Directory.Exists(Path.Combine(path, "data")))
{
Log.Info("Found Steam installation at: {0}", path);
return path;
}
}
else if (Environment.OSVersion.Platform == PlatformID.Other)
{
var home = Environment.GetEnvironmentVariable("HOME") ?? "";
path = Path.Combine(home, "Library", "Application Support", steamPath);

if (Directory.Exists(Path.Combine(path, "data")))
{
Log.Info("Found Steam installation at: {0}", path);
return path;
}
}

// Beamdog
Expand All @@ -106,6 +120,8 @@ private static String FindNwnBasePath()

if ((settingsFile != "") && (File.Exists(settingsFile)))
{
Log.Info("Found Beamdog settings.json at: {0}", path);

var fs = new FileStream(settingsFile, FileMode.Open, FileAccess.Read);
try
{
Expand All @@ -120,11 +136,17 @@ private static String FindNwnBasePath()

var release00829 = Path.Combine(folderStr, "00829");
if (Directory.Exists(Path.Combine(release00829, "data")))
{
Log.Info("Found Beamdog installation at: {0}", release00829);
return release00829;
}

var release00785 = Path.Combine(folderStr, "00785");
if (Directory.Exists(Path.Combine(release00785, "data")))
{
Log.Info("Found Beamdog installation at: {0}", release00785);
return release00785;
}
}
}
}
Expand All @@ -143,64 +165,97 @@ private static String FindNwnBasePath()
path = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)") ?? "", "GOG Galaxy", "Games", "Neverwinter Nights Enhanced Edition");

if (Directory.Exists(Path.Combine(path, "data")))
{
Log.Info("Found GOG installation at: {0}", path);
return path;
}
}
else
{
var home = Environment.GetEnvironmentVariable("HOME") ?? "";
path = Path.Combine(home, "GOG Games", "Neverwinter Nights Enhanced Edition");

if (Directory.Exists(Path.Combine(path, "data")))
{
Log.Info("Found GOG installation at: {0}", path);
return path;
}
}

return "";
}

private static DateTime GetGameBuildDate()
public static DateTime GetGameBuildDate(string nwnBasePath)
{
DateTime buildDate = DateTime.MinValue;
Log.Info("Detecting game build date...");

var buildTxtContents = File.ReadAllLines(Path.Combine(NwnBasePath, "bin", "win32", "build.txt"));
if (buildTxtContents.Length > 1)
DateTime buildDate = DateTime.MinValue;
try
{
var buildDateStr = buildTxtContents[1];

var match = Regex.Match(buildDateStr, "((Mon|Tue|Wed|Thu|Fri|Sat|Sun) *(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) *[0-9]{1,2} *[0-9]{2}:[0-9]{2}:[0-9]{2}) *(\\w+) *([0-9]{4})");
if (match.Success)
var buildTxtContents = File.ReadAllLines(Path.Combine(nwnBasePath, "bin", "win32", "build.txt"));
if (buildTxtContents.Length > 1)
{
buildDateStr = match.Groups[1].Value + " " + match.Groups[5].Value;
buildDate = DateTime.ParseExact(buildDateStr, "ddd MMM d HH:mm:ss yyyy", new CultureInfo("en-US"));
var buildDateStr = Regex.Replace(buildTxtContents[1], " {2,}", " ");

var match = Regex.Match(buildDateStr, "((Mon|Tue|Wed|Thu|Fri|Sat|Sun) *(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) *[0-9]{1,2} *[0-9]{2}:[0-9]{2}:[0-9]{2}) *(\\w+) *([0-9]{4})");
if (match.Success)
{
buildDateStr = match.Groups[1].Value + " " + match.Groups[5].Value;
buildDate = DateTime.ParseExact(buildDateStr, "ddd MMM d HH:mm:ss yyyy", new CultureInfo("en-US"));
}
}
}
catch (Exception e)
{
Log.Error(e.Message);
}

if (buildDate == DateTime.MinValue)
Log.Warning("No valid build date found! This might create problems when updating projects.");
else
Log.Info("Build date found: {0}", buildDate);

return buildDate;
}

public static void Load()
{
Log.Info("Loading config from \"{0}\"", Constants.ConfigPath);
if (File.Exists(Constants.ConfigPath))
{
var fs = new FileStream(Constants.ConfigPath, FileMode.Open, FileAccess.Read);
try
{
if (JsonNode.Parse(fs) is JsonObject configJson)
var fs = new FileStream(Constants.ConfigPath, FileMode.Open, FileAccess.Read);
try
{
if (JsonNode.Parse(fs) is JsonObject configJson)
{
NwnBasePath = configJson[nameof(NwnBasePath)]?.GetValue<String>() ?? "";
BaseGameDataBuildDate = configJson[nameof(BaseGameDataBuildDate)]?.GetValue<DateTime>() ?? DateTime.MinValue;
LastProject = configJson[nameof(LastProject)]?.GetValue<String>() ?? "";
TabLayout = JsonToEnum<TabLayout>(configJson[nameof(TabLayout)]) ?? TabLayout.Multiline;
}
}
finally
{
NwnBasePath = configJson[nameof(NwnBasePath)]?.GetValue<String>() ?? "";
BaseGameDataBuildDate = configJson[nameof(BaseGameDataBuildDate)]?.GetValue<DateTime>() ?? DateTime.MinValue;
LastProject = configJson[nameof(LastProject)]?.GetValue<String>() ?? "";
TabLayout = JsonToEnum<TabLayout>(configJson[nameof(TabLayout)]) ?? TabLayout.Multiline;
fs.Close();
}
}
finally
catch (Exception e)
{
fs.Close();
Log.Error(e.Message);
throw;
}
}
if (NwnBasePath == String.Empty)
{
Log.Info("NwnBasePath is empty -> Searching for NWN installation...");
NwnBasePath = FindNwnBasePath();
}

CurrentGameBuildDate = GetGameBuildDate(NwnBasePath);

CurrentGameBuildDate = GetGameBuildDate();
Log.Info("Config loaded successfully!");
}

public static void Save()
Expand Down
Loading

0 comments on commit 3edd8b4

Please sign in to comment.