Skip to content

Commit

Permalink
Fix synchronous-related properties being set in an async thread
Browse files Browse the repository at this point in the history
  • Loading branch information
LaughingLeader committed Jul 17, 2022
1 parent 15382f9 commit 87cea21
Showing 1 changed file with 110 additions and 101 deletions.
211 changes: 110 additions & 101 deletions GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,149 +666,158 @@ private async Task<Unit> LoadExtenderSettingsAsync(CancellationToken t)
OpenRepoLinkToDownload = true;
}

try
{
string extenderSettingsJson = PathwayData.OsirisExtenderSettingsFile(Settings);
if (extenderSettingsJson.IsExistingFile())
{
var osirisExtenderSettings = DivinityJsonUtils.SafeDeserializeFromPath<OsiExtenderSettings>(extenderSettingsJson);
if (osirisExtenderSettings != null)
{
DivinityApp.Log($"Loaded extender settings from '{extenderSettingsJson}'.");
Settings.ExtenderSettings.Set(osirisExtenderSettings);
}
}
}
catch (Exception ex)
await Observable.Start(() =>
{
DivinityApp.Log($"Error loading extender settings: {ex}");
}

string extenderUpdaterPath = Path.Combine(Path.GetDirectoryName(Settings.GameExecutablePath), DivinityApp.EXTENDER_UPDATER_FILE);
DivinityApp.Log($"Looking for OsiExtender at '{extenderUpdaterPath}'.");
if (File.Exists(extenderUpdaterPath))
{
DivinityApp.Log($"Checking {DivinityApp.EXTENDER_UPDATER_FILE} for Osiris ASCII bytes.");
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(extenderUpdaterPath);
if (fvi != null && fvi.ProductName.IndexOf("Script Extender", StringComparison.OrdinalIgnoreCase) >= 0)
string extenderSettingsJson = PathwayData.OsirisExtenderSettingsFile(Settings);
if (extenderSettingsJson.IsExistingFile())
{
Settings.ExtenderSettings.ExtenderUpdaterIsAvailable = true;
DivinityApp.Log($"Found the Extender at '{extenderUpdaterPath}'.");
FileVersionInfo extenderInfo = FileVersionInfo.GetVersionInfo(extenderUpdaterPath);
if (!String.IsNullOrEmpty(extenderInfo.FileVersion))
var osirisExtenderSettings = DivinityJsonUtils.SafeDeserializeFromPath<OsiExtenderSettings>(extenderSettingsJson);
if (osirisExtenderSettings != null)
{
var version = extenderInfo.FileVersion.Split('.')[0];
if (int.TryParse(version, out int intVersion))
{
if (intVersion >= 3)
{
//Assume we're at least at v56 is the updater is 3.0.0.0
Settings.ExtenderSettings.ExtenderVersion = 56;
}
}
else
{
Settings.ExtenderSettings.ExtenderVersion = -1;
}
DivinityApp.Log($"Loaded extender settings from '{extenderSettingsJson}'.");
Settings.ExtenderSettings.Set(osirisExtenderSettings);
}
}
else
{
DivinityApp.Log($"'{extenderUpdaterPath}' isn't the Script Extender?");
}
}
catch (System.IO.IOException ex)
{
// This can happen if the game locks up the dll.
// Assume it's the extender for now.
Settings.ExtenderSettings.ExtenderUpdaterIsAvailable = true;
DivinityApp.Log($"WARNING: {extenderUpdaterPath} is locked by a process.");
}
catch (Exception ex)
{
DivinityApp.Log($"Error reading: '{extenderUpdaterPath}'\n\t{ex}");
DivinityApp.Log($"Error loading extender settings: {ex}");
}
}
else
{
Settings.ExtenderSettings.ExtenderUpdaterIsAvailable = false;
DivinityApp.Log($"Extender updater {DivinityApp.EXTENDER_UPDATER_FILE} not found.");
}

string extenderDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DOS2ScriptExtender\\ScriptExtender");
if(Directory.Exists(extenderDirectory))
{
var extenderFiles = Directory.EnumerateFiles(extenderDirectory, DirectoryEnumerationOptions.Files | DirectoryEnumerationOptions.Recursive, new DirectoryEnumerationFilters
{
InclusionFilter = (f) => f.FileName.Equals("OsiExtenderEoCApp.dll", StringComparison.OrdinalIgnoreCase)
});
int latestVersion = -1;
foreach(var f in extenderFiles)
string extenderUpdaterPath = Path.Combine(Path.GetDirectoryName(Settings.GameExecutablePath), DivinityApp.EXTENDER_UPDATER_FILE);
DivinityApp.Log($"Looking for OsiExtender at '{extenderUpdaterPath}'.");
if (File.Exists(extenderUpdaterPath))
{
Settings.ExtenderSettings.ExtenderIsAvailable = true;
DivinityApp.Log($"Checking {DivinityApp.EXTENDER_UPDATER_FILE} for Osiris ASCII bytes.");
try
{
FileVersionInfo extenderInfo = FileVersionInfo.GetVersionInfo(f);
if (!String.IsNullOrEmpty(extenderInfo.FileVersion))
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(extenderUpdaterPath);
if (fvi != null && fvi.ProductName.IndexOf("Script Extender", StringComparison.OrdinalIgnoreCase) >= 0)
{
var version = extenderInfo.FileVersion.Split('.')[0];
if (int.TryParse(version, out int intVersion))
Settings.ExtenderSettings.ExtenderUpdaterIsAvailable = true;
DivinityApp.Log($"Found the Extender at '{extenderUpdaterPath}'.");
FileVersionInfo extenderInfo = FileVersionInfo.GetVersionInfo(extenderUpdaterPath);
if (!String.IsNullOrEmpty(extenderInfo.FileVersion))
{
if(intVersion > latestVersion)
var version = extenderInfo.FileVersion.Split('.')[0];
if (int.TryParse(version, out int intVersion))
{
latestVersion = intVersion;
if (intVersion >= 3)
{
//Assume we're at least at v56 is the updater is 3.0.0.0
Settings.ExtenderSettings.ExtenderVersion = 56;
}
}
else
{
Settings.ExtenderSettings.ExtenderVersion = -1;
}
}
else
{
Settings.ExtenderSettings.ExtenderVersion = -1;
}
}
else
{
DivinityApp.Log($"'{extenderUpdaterPath}' isn't the Script Extender?");
}
}
catch (System.IO.IOException ex)
{
// This can happen if the game locks up the dll.
// Assume it's the extender for now.
Settings.ExtenderSettings.ExtenderUpdaterIsAvailable = true;
DivinityApp.Log($"WARNING: {extenderUpdaterPath} is locked by a process.");
}
catch (Exception ex)
{
DivinityApp.Log($"Error getting file info from: '{f}'\n\t{ex}");
DivinityApp.Log($"Error reading: '{extenderUpdaterPath}'\n\t{ex}");
}
}
if(latestVersion > -1)
else
{
Settings.ExtenderSettings.ExtenderVersion = latestVersion;
DivinityApp.Log($"Current OsiExtender version found: '{Settings.ExtenderSettings.ExtenderVersion}'.");
Settings.ExtenderSettings.ExtenderUpdaterIsAvailable = false;
DivinityApp.Log($"Extender updater {DivinityApp.EXTENDER_UPDATER_FILE} not found.");
}
}

//Look in old path
if (!Settings.ExtenderSettings.ExtenderIsAvailable)
{
string extenderAppFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DivinityApp.EXTENDER_APPDATA_DLL_OLD);
if (File.Exists(extenderAppFile))
string extenderDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DOS2ScriptExtender\\ScriptExtender");
if (Directory.Exists(extenderDirectory))
{
Settings.ExtenderSettings.ExtenderIsAvailable = true;
try
var extenderFiles = Directory.EnumerateFiles(extenderDirectory, DirectoryEnumerationOptions.Files | DirectoryEnumerationOptions.Recursive, new DirectoryEnumerationFilters
{
InclusionFilter = (f) => f.FileName.Equals("OsiExtenderEoCApp.dll", StringComparison.OrdinalIgnoreCase)
}).ToList();
int latestVersion = -1;
if (extenderFiles.Count > 0)
{
FileVersionInfo extenderInfo = FileVersionInfo.GetVersionInfo(extenderAppFile);
if (!String.IsNullOrEmpty(extenderInfo.FileVersion))
Settings.ExtenderSettings.ExtenderIsAvailable = true;

foreach (var f in extenderFiles)
{
var version = extenderInfo.FileVersion.Split('.')[0];
if (int.TryParse(version, out int intVersion))
try
{
Settings.ExtenderSettings.ExtenderVersion = intVersion;
DivinityApp.Log($"Current OsiExtender version found: '{Settings.ExtenderSettings.ExtenderVersion}'.");
FileVersionInfo extenderInfo = FileVersionInfo.GetVersionInfo(f);
if (!String.IsNullOrEmpty(extenderInfo.FileVersion))
{
var version = extenderInfo.FileVersion.Split('.')[0];
if (int.TryParse(version, out int intVersion))
{
if (intVersion > latestVersion)
{
latestVersion = intVersion;
}
}
else
{
Settings.ExtenderSettings.ExtenderVersion = -1;
}
}
}
else
catch (Exception ex)
{
Settings.ExtenderSettings.ExtenderVersion = -1;
DivinityApp.Log($"Error getting file info from: '{f}'\n\t{ex}");
}
}
if (latestVersion > -1)
{
Settings.ExtenderSettings.ExtenderVersion = latestVersion;
DivinityApp.Log($"Current OsiExtender version found: '{Settings.ExtenderSettings.ExtenderVersion}'.");
}
}
catch (Exception ex)
}

//Look in old path
if (!Settings.ExtenderSettings.ExtenderIsAvailable)
{
string extenderAppFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DivinityApp.EXTENDER_APPDATA_DLL_OLD);
if (File.Exists(extenderAppFile))
{
DivinityApp.Log($"Error getting file info from: '{extenderAppFile}'\n\t{ex}");
Settings.ExtenderSettings.ExtenderIsAvailable = true;
try
{
FileVersionInfo extenderInfo = FileVersionInfo.GetVersionInfo(extenderAppFile);
if (!String.IsNullOrEmpty(extenderInfo.FileVersion))
{
var version = extenderInfo.FileVersion.Split('.')[0];
if (int.TryParse(version, out int intVersion))
{
Settings.ExtenderSettings.ExtenderVersion = intVersion;
DivinityApp.Log($"Current OsiExtender version found: '{Settings.ExtenderSettings.ExtenderVersion}'.");
}
else
{
Settings.ExtenderSettings.ExtenderVersion = -1;
}
}
}
catch (Exception ex)
{
DivinityApp.Log($"Error getting file info from: '{extenderAppFile}'\n\t{ex}");
}
}
}
}
return Unit.Default;
}, RxApp.MainThreadScheduler);

return Unit.Default;
}
Expand Down

0 comments on commit 87cea21

Please sign in to comment.