Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<OutputType>WinExe</OutputType>
<Version>1.5.2</Version>
<Version>1.6.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Version>1.5.2</Version>
<Version>1.6.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<OutputType>WinExe</OutputType>
<Version>1.5.2</Version>
<Version>1.6.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion src/War3App.MapAdapter/Environment/MapEnvironmentAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using War3Net.Build.Common;
using War3Net.Build.Environment;
using War3Net.Build.Extensions;
using War3Net.Common.Providers;

namespace War3App.MapAdapter.Environment
{
Expand Down Expand Up @@ -40,7 +41,24 @@ public AdaptResult AdaptFile(Stream stream, AdaptFileContext context)
return context.ReportParseError(e);
}

return MapFileStatus.Compatible;
if (!mapEnvironment.Adapt(context, out var status))
{
return status;
}

try
{
var memoryStream = new MemoryStream();

using var writer = new BinaryWriter(memoryStream, UTF8EncodingProvider.StrictUTF8, true);
writer.Write(mapEnvironment);

return AdaptResult.Create(memoryStream, status);
}
catch (Exception e)
{
return context.ReportSerializeError(e);
}
}

public string SerializeFileToJson(Stream stream, GamePatch gamePatch, JsonSerializerOptions options)
Expand Down
62 changes: 62 additions & 0 deletions src/War3App.MapAdapter/Environment/MapEnvironmentExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using War3Net.Build.Common;
using War3Net.Build.Environment;

namespace War3App.MapAdapter.Environment
{
public static class MapEnvironmentExtensions
{
public static bool Adapt(this MapEnvironment mapEnvironment, AdaptFileContext context, out MapFileStatus status)
{
if (mapEnvironment.GetMinimumPatch() <= context.TargetPatch.Patch)
{
status = MapFileStatus.Compatible;
return false;
}

status = mapEnvironment.TryDowngrade(context.TargetPatch.Patch)
? MapFileStatus.Compatible
: MapFileStatus.Incompatible;

return status == MapFileStatus.Compatible;
}

public static bool TryDowngrade(this MapEnvironment mapEnvironment, GamePatch targetPatch)
{
try
{
while (mapEnvironment.GetMinimumPatch() > targetPatch)
{
mapEnvironment.DowngradeOnce();
}

return true;
}
catch
{
throw;
}
}

public static void DowngradeOnce(this MapEnvironment mapEnvironment)
{
switch (mapEnvironment.FormatVersion)
{
case MapEnvironmentFormatVersion.v12:
mapEnvironment.FormatVersion = MapEnvironmentFormatVersion.v11;
break;

default:
break;
}
}

public static GamePatch GetMinimumPatch(this MapEnvironment mapEnvironment)
{
return mapEnvironment.FormatVersion switch
{
MapEnvironmentFormatVersion.v11 => GamePatch.v1_00,
MapEnvironmentFormatVersion.v12 => GamePatch.v2_0_3,
};
}
}
}
4 changes: 2 additions & 2 deletions src/War3App.MapAdapter/War3App.MapAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Version>1.5.2</Version>
<Version>1.6.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="War3Api.Blizzard" Version="1.33.0" />
<PackageReference Include="War3Net.Build.Core" Version="5.8.1" />
<PackageReference Include="War3Net.Build.Core" Version="5.8.2" />
</ItemGroup>

</Project>
Loading