Skip to content

Commit

Permalink
Implement RefreshAppxManifestVersion in NanaZip.RefreshPackageVersion.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Aug 14, 2024
1 parent dcbbec1 commit ca0fbdb
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion NanaZip.RefreshPackageVersion/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
namespace NanaZip.RefreshPackageVersion
using Mile.Project.Helpers;
using System.Xml;

namespace NanaZip.RefreshPackageVersion
{
internal class Program
{
static (int Major, int Minor) Version = (3, 5);
static string BuildStartDay = "2021-08-31";

static string GenerateVersionString()
{
return string.Format(
"{0}.{1}.{2}.0",
Version.Major,
Version.Minor,
DateTime.Today.Subtract(DateTime.Parse(BuildStartDay)).TotalDays);
}

static string RepositoryRoot = GitRepository.GetRootPath();

static void RefreshAppxManifestVersion()
{
string FilePath = string.Format(
@"{0}\NanaZipPackage\Package.appxmanifest",
RepositoryRoot);

XmlDocument Document = new XmlDocument();
Document.PreserveWhitespace = true;
Document.Load(FilePath);

XmlNode? PackageNode = Document["Package"];
if (PackageNode != null)
{
XmlNode? IdentityNode = PackageNode["Identity"];
if (IdentityNode != null)
{
XmlAttribute? VersionAttribute =
IdentityNode.Attributes["Version"];
if (VersionAttribute != null)
{
FileUtilities.SaveTextToFileAsUtf8Bom(
FilePath,
File.ReadAllText(FilePath).Replace(
VersionAttribute.Value,
GenerateVersionString()));
}
}
}
}

static void Main(string[] args)
{
RefreshAppxManifestVersion();

Console.WriteLine(
"NanaZip.RefreshPackageVersion task has been completed.");
Console.ReadKey();
Expand Down

0 comments on commit ca0fbdb

Please sign in to comment.