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
4 changes: 2 additions & 2 deletions BedrockLauncher.Core/BedrockLauncher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<Version>2.0.3-dev</Version>
<Version>2.0.4-dev</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Version>2.0.3</Version>
<Version>2.0.4</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion BedrockLauncher.Core/Utils/ManifestEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.RegularExpressions;
using System.Xml.Linq;
using BedrockLauncher.Core.BackGround;
using BedrockLauncher.Core.VersionJsons;

namespace BedrockLauncher.Core.Utils
{
Expand Down Expand Up @@ -47,7 +48,8 @@ public async static Task<bool> EditManifest(string directory, string gameName, B
XElement application = applications?.Element(ns + "Application");
XElement extenElement = application?.Element(ns + "Extensions");
XElement identElement = package?.Element(ns + "Identity");
identElement.SetAttributeValue("Version", TimeBasedVersion.GetVersion());
string version = identElement?.Attribute("Version")?.Value;
identElement.SetAttributeValue("Version",VersionsHelper.GetNextVersion(new Version(version)));
extenElement.RemoveAll();
application.SetAttributeValue(desktop4 + "SupportsMultipleInstances", "true");
XElement? xElement = application.Element(uap + "VisualElements");
Expand Down
42 changes: 42 additions & 0 deletions BedrockLauncher.Core/VersionJsons/VersionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,48 @@ namespace BedrockLauncher.Core.VersionJsons;

public static class VersionsHelper
{
private static readonly object _lock = new object();
public static string GetNextVersion(Version currentVersion)
{
lock (_lock)
{

long ticks = DateTime.Now.Ticks;
int seed = (int)(ticks & 0xFFFFFFFF) ^ (int)(ticks >> 32) ^ Environment.TickCount;
Random rand = new Random(seed);
int sevenDigitNumber = rand.Next(1_000_000, 10_000_000);
string sevenDigitStr = sevenDigitNumber.ToString();


int[] positions = Enumerable.Range(0, 7).OrderBy(x => rand.Next()).Take(2).ToArray();
Array.Sort(positions);
int buildSuffix = int.Parse(sevenDigitStr[positions[0]].ToString() + sevenDigitStr[positions[1]]);


string originalBuildStr = currentVersion.Build.ToString();

string paddedBuild = originalBuildStr.PadRight(5, '0');
string buildPrefix = paddedBuild.Substring(0, 3);


string newBuildStr = buildPrefix + buildSuffix.ToString().PadLeft(2, '0');
int newBuild = int.Parse(newBuildStr);

if (newBuild > 65535) newBuild = newBuild % 65535;
if (newBuild == 0) newBuild = 1;


var remainingIndices = Enumerable.Range(0, 7).Except(positions).OrderBy(i => i).ToArray();
string revisionStr = new string(remainingIndices.Select(i => sevenDigitStr[i]).ToArray());
int revision = int.Parse(revisionStr);

if (revision > 65535) revision = revision % 65535;
if (revision == 0) revision = 1;


return $"{currentVersion.Major}.{currentVersion.Minor}.{newBuild}.{revision}";
}
}
/// <summary>
/// Asynchronously retrieves and deserializes a build database from the specified HTTP address(e.g. mcappx).
/// </summary>
Expand Down
24 changes: 12 additions & 12 deletions CoreTest/InstallTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public void Test()
}))),
Type = MinecraftBuildTypeVersion.UWP,
GameTypeVersion = MinecraftGameTypeVersion.Release,
InstallDstFolder = Path.GetFullPath("./Test7"),
GameName = "8899",
FileFullPath = @"D:\Windows11\Download\Microsoft.MinecraftUWP_0.140.1.0_x64__8wekyb3d8bbwe.Appx"
InstallDstFolder = Path.GetFullPath("./Test7829"),
GameName = "88991",
FileFullPath = @"D:\Windows11\Download\Microsoft.MinecraftUWP_1.7.100.0_x64__8wekyb3d8bbwe.Appx"
};
//bedrockCore.InstallPackageAsync(localGamePackageOptions).Wait();
var launchOptions = new LaunchOptions()
{
GameFolder = Path.GetFullPath("./Test7"),
GameType = MinecraftGameTypeVersion.Release,
MinecraftBuildType = MinecraftBuildTypeVersion.UWP,
};
var process = bedrockCore.LaunchGameAsync(launchOptions).Result;
Assert.IsNotNull(process);
bedrockCore.InstallPackageAsync(localGamePackageOptions).Wait();
//var launchOptions = new LaunchOptions()
//{
// GameFolder = Path.GetFullPath("./Test78"),
// GameType = MinecraftGameTypeVersion.Release,
// MinecraftBuildType = MinecraftBuildTypeVersion.UWP,
//};
//var process = bedrockCore.LaunchGameAsync(launchOptions).Result;
//Assert.IsNotNull(process);
}
}
}
25 changes: 25 additions & 0 deletions CoreTest/VersionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
using BedrockLauncher.Core.Utils;

namespace CoreTest
{
[TestClass]
public class VersionTest
{


[TestMethod]
public void Test()
{


for (long i = 0; i < 1000; i++)
{

Console.WriteLine(VersionHelper.GetNextVersion(new Version("1.21.10006.0")));
}
}
}
}
Loading