Skip to content

Commit a6c69e4

Browse files
committed
Refactoring.
1 parent 4d87285 commit a6c69e4

File tree

4 files changed

+59
-57
lines changed

4 files changed

+59
-57
lines changed
Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
1-
using System.Runtime.InteropServices;
1+
using System.IO;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices;
24

35
[assembly: ComVisible(false)]
46
[assembly: Guid("ab848ecd-76aa-41c0-b63d-86a8591b25aa")]
7+
8+
namespace WindowsDesktop.Properties;
9+
10+
internal static class AssemblyInfo
11+
{
12+
private static readonly Assembly _assembly = Assembly.GetExecutingAssembly();
13+
private static string? _title;
14+
private static string? _description;
15+
private static string? _company;
16+
private static string? _product;
17+
private static string? _copyright;
18+
private static string? _trademark;
19+
private static string? _versionString;
20+
21+
public static string Title
22+
=> _title ??= Prop<AssemblyTitleAttribute>(x => x.Title);
23+
24+
public static string Description
25+
=> _description ??= Prop<AssemblyDescriptionAttribute>(x => x.Description);
26+
27+
public static string Company
28+
=> _company ??= Prop<AssemblyCompanyAttribute>(x => x.Company);
29+
30+
public static string Product
31+
=> _product ??= Prop<AssemblyProductAttribute>(x => x.Product);
32+
33+
public static string Copyright
34+
=> _copyright ??= Prop<AssemblyCopyrightAttribute>(x => x.Copyright);
35+
36+
public static string Trademark
37+
=> _trademark ??= Prop<AssemblyTrademarkAttribute>(x => x.Trademark);
38+
39+
public static Version Version
40+
=> _assembly.GetName().Version ?? new Version();
41+
42+
public static string VersionString
43+
=> _versionString ??= Version.ToString(3);
44+
45+
private static string Prop<T>(Func<T, string> propSelector)
46+
where T : Attribute
47+
{
48+
var attribute = _assembly.GetCustomAttribute<T>();
49+
return attribute != null ? propSelector(attribute) : "";
50+
}
51+
}
52+
53+
internal static class LocationInfo
54+
{
55+
private static DirectoryInfo? _localAppData;
56+
57+
internal static DirectoryInfo LocalAppData
58+
=> _localAppData ??= new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AssemblyInfo.Company, AssemblyInfo.Product));
59+
}

src/VirtualDesktop/Properties/Configurations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public record VirtualDesktopCompilerConfiguration
3232
/// <returns>
3333
/// A value indicating whether the compiled assembly should be saved or not. Default is %LocalAppData%.
3434
/// </returns>
35-
public DirectoryInfo CompiledAssemblySaveDirectory { get; init; } = new(Path.Combine(ProductInfo.LocalAppData.FullName, "assemblies"));
35+
public DirectoryInfo CompiledAssemblySaveDirectory { get; init; } = new(Path.Combine(LocationInfo.LocalAppData.FullName, "assemblies"));
3636
}

src/VirtualDesktop/Properties/ProductInfo.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/VirtualDesktop/VirtualDesktop.system.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ static VirtualDesktop()
4040
_ => new VirtualDesktopProvider.NotSupported()
4141
};
4242

43-
Debug.WriteLine("*** VirtualDesktop Library ***");
43+
Debug.WriteLine($"*** {AssemblyInfo.Title} Library ***");
44+
Debug.WriteLine($"Version: {AssemblyInfo.VersionString}");
4445
Debug.WriteLine($"OS Build: {Environment.OSVersion.Version.Build}");
4546
Debug.WriteLine($"Provider: {_provider.GetType().Name}");
4647
}

0 commit comments

Comments
 (0)