Skip to content

Commit

Permalink
Added check for .dll vs .gluj version and report error if appropriate
Browse files Browse the repository at this point in the history
Renamed FileErrorReporter to clarify intent.
Fixed crash on About page when there is no internet.
fixes #1647
  • Loading branch information
vchelaru committed Nov 22, 2024
1 parent 8a7379b commit 170c16a
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\Primitives\*.cs">
<Link>Controls\Primitives\%(Filename)%(Extension)</Link>
</Compile>

<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\Button.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>
Expand All @@ -31,42 +30,33 @@
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\ListBox.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>

<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\ListBoxItem.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>

<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\PasswordBox.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>

<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\RadioButton.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>

<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\ScrollBar.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\ScrollViewer.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\Slider.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>


</Compile>
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\TextBox.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\TextBoxBase.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\Gum\MonoGameGum\Forms\Controls\ToggleButton.cs">
<Link>Controls\%(Filename)%(Extension)</Link>
</Compile>



</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IListExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FrameworkElementTemplate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CursorExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace FlatRedBall.Glue.Errors
{
public static class ErrorReporter
public static class FileErrorReporter
{
static List<string> mFilesAlreadyReported = new List<string>();
// used to invoke.
Expand Down
4 changes: 2 additions & 2 deletions FRBDK/Glue/Glue/FormHelpers/RightClickHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,15 +2254,15 @@ private static async void RebuildFileClick(object sender, EventArgs e)
rfs.RefreshSourceFileCache(buildOnMissingFile, out error);
if (!string.IsNullOrEmpty(error))
{
ErrorReporter.ReportError(rfs.Name, error, false);
FileErrorReporter.ReportError(rfs.Name, error, false);
}
else
{
error = rfs.PerformExternalBuild(runAsync: true);

if (!string.IsNullOrEmpty(error))
{
ErrorReporter.ReportError(FileManager.MakeAbsolute(rfs.Name), error, true);
FileErrorReporter.ReportError(FileManager.MakeAbsolute(rfs.Name), error, true);
}

var absoluteFileName =
Expand Down
2 changes: 1 addition & 1 deletion FRBDK/Glue/Glue/IO/ProjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ private static void BuildIfOutOfDate(bool runBuildsAsync, ReferencedFileSave rfs

if (!string.IsNullOrEmpty(error))
{
ErrorReporter.ReportError(GlueCommands.Self.GetAbsoluteFileName(rfs), error, false);
FileErrorReporter.ReportError(GlueCommands.Self.GetAbsoluteFileName(rfs), error, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion FRBDK/Glue/Glue/IO/UpdateReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static async Task<bool> UpdateFile(FilePath changedFile, FileChangeType c

if (!string.IsNullOrEmpty(error))
{
ErrorReporter.ReportError(rfs.Name, error, false);
FileErrorReporter.ReportError(rfs.Name, error, false);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion FRBDK/Glue/Glue/MainGlueWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private async void StartUpGlue(object sender, EventArgs e)
}

SetScreenSubMessage(Localization.Texts.InitializeErrorReporting);
ErrorReporter.Initialize(this);
FileErrorReporter.Initialize(this);

SetScreenSubMessage(Localization.Texts.InitializingRightClickMenus);
RightClickHelper.Initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,23 @@ internal async void RefreshVersionInfo()
{

var location = "https://files.flatredball.com/content/FrbXnaTemplates/DailyBuild/FRBDK.zip";
using var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Head, new Uri(location));

HttpResponseMessage response = null;

await GlueCommands.Self.TryMultipleTimes(async () =>

try
{
await GlueCommands.Self.TryMultipleTimes(async () =>
{
using var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Head, new Uri(location));
response = await client.SendAsync(request);
});
}
catch(Exception)
{
response = await client.SendAsync(request);
});
if (response.IsSuccessStatusCode)
// do nothing, perhaps offline?
}
if (response?.IsSuccessStatusCode == true)
{
if (response.Headers.TryGetValues("Last-Modified", out var values))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using FlatRedBall.IO;
using GlueFormsCore.Controls;
using Microsoft.Build.Evaluation;
using Mono.Cecil;
using PropertyTools.Wpf;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -93,74 +92,7 @@ private void RefreshAboutViewModel(GlueProjectSave glueProject)
aboutViewModel.MainProjectTypeText = GlueState.Self.CurrentMainProject?.GetType().Name;
}

aboutViewModel.DllSyntaxVersion = GetDllSyntaxSupportedVersion();
}

private static int? GetDllSyntaxSupportedVersion()
{
// for now we'll use the main project, but eventually we may want to include synced projects too:
var project = GlueState.Self.CurrentMainProject;
var referenceItems = project.EvaluatedItems.Where(item =>
{
return item.ItemType == "PackageReference" && item.EvaluatedInclude.StartsWith("FlatRedBall");
});

foreach(var item in referenceItems)
{
var path = GetFilePathFor(item);

if (path != null)
{
var module = ModuleDefinition.ReadModule(path.FullPath);
var frbServicesType = module.Types.FirstOrDefault(item => item.FullName == "FlatRedBall.FlatRedBallServices");
foreach(var attribute in frbServicesType.CustomAttributes)
{
if(attribute.AttributeType.Name == "SyntaxVersionAttribute" && attribute.Fields.Count > 0)
{
var version = int.Parse( attribute.Fields[0].Argument.Value.ToString());
return version;
}
}
}

}
return null;
}

private static FilePath GetFilePathFor(ProjectItem item)
{
string packageName = item.EvaluatedInclude;
string packageVersion = item.Metadata.FirstOrDefault(item => item.Name == "Version")?.EvaluatedValue;

var userName = System.Environment.UserName;


if (userName != null)
{
string[] searchPaths = {
@"C:\Program Files\dotnet\packs",
$@"C:\Users\{userName}\.nuget\packages"
};

foreach (string path in searchPaths)
{
string fullPath = System.IO.Path.Combine(path, $"{packageName}",$"{packageVersion}", $"{packageName}.{packageVersion}.nupkg");
if (System.IO.File.Exists(fullPath))
{
var directory = FileManager.GetDirectory(fullPath);
// find a .dll with matching file
var allFiles = FlatRedBall.IO.FileManager.GetAllFilesInDirectory(directory, "dll");
foreach (var file in allFiles)
{
if (file.Contains($"{packageName}.dll"))
{
return file;
}
}
}
}
}
return null;
aboutViewModel.DllSyntaxVersion = GlueState.Self.EngineDllSyntaxVersion;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void findFileReferencesToolStripMenuItem_Click(object sender, EventArgs
}
catch (FileNotFoundException fnfe)
{
ErrorReporter.ReportError(absoluteFileName, String.Format("Trying to find file references, but could not find contained file {0}", fnfe.FileName), true);
FileErrorReporter.ReportError(absoluteFileName, String.Format("Trying to find file references, but could not find contained file {0}", fnfe.FileName), true);
}

if (referencedFiles == null) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ public ReferencedFileSave CreateReferencedFileSaveForExistingFile(IElement conta

if (!string.IsNullOrEmpty(error))
{
ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false);
FileErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ public ReferencedFileSave CreateReferencedFileSaveForExistingFile(GlueElement co

if (!string.IsNullOrEmpty(error))
{
ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false);
FileErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false);
}
}
}
Expand Down
73 changes: 73 additions & 0 deletions FRBDK/Glue/Glue/Plugins/ExportedImplementations/GlueState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using FlatRedBall.Glue.Navigation;
using FlatRedBall.Glue.Tiled;
using GlueFormsCore.ViewModels;
using Microsoft.Build.Evaluation;
using Mono.Cecil;


namespace FlatRedBall.Glue.Plugins.ExportedImplementations
{
Expand Down Expand Up @@ -414,6 +417,76 @@ public GlueSettingsSave GlueSettingsSave
set => ProjectManager.GlueSettingsSave = value;
}

public int? EngineDllSyntaxVersion
{
get
{
// for now we'll use the main project, but eventually we may want to include synced projects too:
var project = GlueState.Self.CurrentMainProject;
var referenceItems = project.EvaluatedItems.Where(item =>
{
return item.ItemType == "PackageReference" && item.EvaluatedInclude.StartsWith("FlatRedBall");
});

foreach (var item in referenceItems)
{
var path = GetFilePathFor(item);

if (path != null)
{
var module = ModuleDefinition.ReadModule(path.FullPath);
var frbServicesType = module.Types.FirstOrDefault(item => item.FullName == "FlatRedBall.FlatRedBallServices");
foreach (var attribute in frbServicesType.CustomAttributes)
{
if (attribute.AttributeType.Name == "SyntaxVersionAttribute" && attribute.Fields.Count > 0)
{
var version = int.Parse(attribute.Fields[0].Argument.Value.ToString());
return version;
}
}
}

}
return null;
}
}

private static FilePath GetFilePathFor(ProjectItem item)
{
string packageName = item.EvaluatedInclude;
string packageVersion = item.Metadata.FirstOrDefault(item => item.Name == "Version")?.EvaluatedValue;

var userName = System.Environment.UserName;


if (userName != null)
{
string[] searchPaths = {
@"C:\Program Files\dotnet\packs",
$@"C:\Users\{userName}\.nuget\packages"
};

foreach (string path in searchPaths)
{
string fullPath = System.IO.Path.Combine(path, $"{packageName}", $"{packageVersion}", $"{packageName}.{packageVersion}.nupkg");
if (System.IO.File.Exists(fullPath))
{
var directory = FileManager.GetDirectory(fullPath);
// find a .dll with matching file
var allFiles = FlatRedBall.IO.FileManager.GetAllFilesInDirectory(directory, "dll");
foreach (var file in allFiles)
{
if (file.Contains($"{packageName}.dll"))
{
return file;
}
}
}
}
}
return null;
}

#endregion

#region Sub-containers and Self
Expand Down
7 changes: 7 additions & 0 deletions FRBDK/Glue/Glue/Plugins/ExportedInterfaces/IGlueState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ string ContentDirectory
List<ProjectBase> GetProjects();
IEnumerable<ReferencedFileSave> GetAllReferencedFiles();
bool IsProjectLoaded(VisualStudioProject project);
int? EngineDllSyntaxVersion { get; }

}

public class GlueStateSnapshot : IGlueState
Expand Down Expand Up @@ -205,6 +207,7 @@ public string ProjectSpecificSettingsFolder

public bool IsReferencingFrbSource { get; set; }

public int? EngineDllSyntaxVersion { get; private set; }
// STOP! If adding more properties, here be sure to add to SetFrom too

public void SetFrom(IGlueState glueState)
Expand Down Expand Up @@ -244,6 +247,8 @@ public void SetFrom(IGlueState glueState)

this.IsReferencingFrbSource = glueState.IsReferencingFrbSource;

this.EngineDllSyntaxVersion = glueState.EngineDllSyntaxVersion;

if(glueState.CurrentGlueProject != null)
{
this.ProjectSpecificSettingsFolder = glueState.ProjectSpecificSettingsFolder;
Expand Down Expand Up @@ -276,5 +281,7 @@ public IEnumerable<ReferencedFileSave> GetAllReferencedFiles()
{
throw new System.NotImplementedException();
}


}
}
Loading

0 comments on commit 170c16a

Please sign in to comment.