Disable Windows-specific code on other platforms

dhcp-server v0.0.3
Pat Hartl 2023-08-07 17:46:36 -05:00
parent 2106ca6a1d
commit 4e99b648ff
7 changed files with 49 additions and 19 deletions

View File

@ -10,6 +10,16 @@
<Content Remove="wwwroot\js\Upload.ts" />
</ItemGroup>
<PropertyGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
<DefineConstants>WINDOWS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
<DefineConstants>LINUX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
<DefineConstants>MACOS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AntDesign" Version="0.15.4" />
<PackageReference Include="AntDesign.Charts" Version="0.3.1" />
@ -64,6 +74,12 @@
<TypeScriptCompile Include="wwwroot\js\Upload.ts" />
</ItemGroup>
<ItemGroup>
<None Update="favicon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<TypeScriptCompile Update="wwwroot\js\Upload.ts">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>

View File

@ -65,6 +65,7 @@
private async Task RefreshData()
{
#if WINDOWS
var category = new PerformanceCounterCategory("Network Interface");
foreach (var instance in category.GetInstanceNames())
@ -83,5 +84,6 @@
await Chart.ChangeData(Data.SelectMany(x => x.Value.Select((y, i) => new { value = y, index = i, series = x.Key })), true);
}
catch { }
#endif
}
}

View File

@ -65,6 +65,7 @@
private async Task RefreshData()
{
#if WINDOWS
var category = new PerformanceCounterCategory("Network Interface");
foreach (var instance in category.GetInstanceNames())
@ -83,5 +84,6 @@
await Chart.ChangeData(Data.SelectMany(x => x.Value.Select((y, i) => new { value = y, index = i, series = x.Key })), true);
}
catch { }
#endif
}
}

View File

@ -68,6 +68,7 @@
private async Task RefreshData()
{
#if WINDOWS
Data = Data.ShiftArrayAndInsert((double)Math.Ceiling(PerformanceCounter.NextValue()), TimerHistory);
try
@ -75,5 +76,6 @@
await Chart.ChangeData(Data.Select((x, i) => new { value = x, index = i }), true);
}
catch { }
#endif
}
}

View File

@ -120,6 +120,7 @@ namespace LANCommander.Services
return File.ReadAllBytes(cachedPath);
else
{
#if WINDOWS
if (game.Archives == null || game.Archives.Count == 0)
throw new FileNotFoundException();
@ -127,31 +128,38 @@ namespace LANCommander.Services
Bitmap bitmap = null;
var iconReference = ArchiveService.ReadFile(archive.ObjectKey, game.Icon);
if (IsWinPEFile(iconReference))
try
{
var tmp = System.IO.Path.GetTempFileName();
var iconReference = ArchiveService.ReadFile(archive.ObjectKey, game.Icon);
System.IO.File.WriteAllBytes(tmp, iconReference);
var icon = System.Drawing.Icon.ExtractAssociatedIcon(tmp);
bitmap = icon.ToBitmap();
}
else
{
using (var ms = new MemoryStream(iconReference))
if (IsWinPEFile(iconReference))
{
bitmap = (Bitmap)Bitmap.FromStream(ms);
var tmp = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllBytes(tmp, iconReference);
var icon = System.Drawing.Icon.ExtractAssociatedIcon(tmp);
bitmap = icon.ToBitmap();
}
else
{
using (var ms = new MemoryStream(iconReference))
{
bitmap = (Bitmap)Bitmap.FromStream(ms);
}
}
var iconPng = ConvertToPng(bitmap);
File.WriteAllBytes(cachedPath, iconPng);
return iconPng;
}
catch (Exception ex) { }
#endif
var iconPng = ConvertToPng(bitmap);
File.WriteAllBytes(cachedPath, iconPng);
return iconPng;
return File.ReadAllBytes("favicon.png");
}
}

BIN
LANCommander/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB