internal class InstallApp
{
public InstallApp()
{
}
public static string CreateMD5(string input)
{
string str;
MD5 mD5 = MD5.Create();
try
{
byte[] bytes = Encoding.Unicode.GetBytes(input);
byte[] numArray = mD5.ComputeHash(bytes);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 5; i++)
{
stringBuilder.Append(numArray[i].ToString("x2"));
}
str = stringBuilder.ToString();
}
finally
{
if (mD5 != null)
{
((IDisposable)mD5).Dispose();
}
}
return str;
}
public static void Main(string[] args)
{
Console.Write("Registering universal app...");
try
{
PackageManager packageManager = new PackageManager();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("AppxManifest.xml");
string value = xmlDocument.DocumentElement.SelectSingleNode("//*[local-name()='Identity']").Attributes["Name"].Value;
string str = InstallApp.CreateMD5(Environment.UserName);
if (!value.EndsWith(string.Concat(".", str)))
{
XmlAttribute itemOf = xmlDocument.DocumentElement.SelectSingleNode("//*[local-name()='Identity']").Attributes["Name"];
itemOf.Value = string.Concat(itemOf.Value, ".", str);
XmlDocument xmlDocument1 = new XmlDocument();
xmlDocument1.LoadXml("<rescap:Capability xmlns:rescap=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities\" Name=\"packageQuery\"/>");
XmlNode xmlNodes = xmlDocument.DocumentElement.SelectSingleNode("//*[local-name()='Capabilities']");
XmlNode xmlNodes1 = xmlNodes.OwnerDocument.ImportNode(xmlDocument1.DocumentElement, true);
xmlNodes.PrependChild(xmlNodes1);
xmlDocument.Save("AppxManifest.xml");
}
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
string str1 = string.Concat(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "\\AppxManifest.xml");
System.Uri uri = new System.Uri(str1);
if (!uri.IsAbsoluteUri)
{
throw new FormatException("The current path is somehow invalid?!");
}
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> asyncOperationWithProgress = packageManager.RegisterPackageAsync(uri, null, DeploymentOptions.DevelopmentMode);
asyncOperationWithProgress.Completed = (IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> depProgress, AsyncStatus status) => manualResetEvent.Set();
if (asyncOperationWithProgress.Status == AsyncStatus.Started)
{
manualResetEvent.WaitOne();
}
if (asyncOperationWithProgress.Status == AsyncStatus.Error)
{
throw new Exception(asyncOperationWithProgress.GetResults().ErrorText);
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("done!");
Console.ForegroundColor = ConsoleColor.Gray;
Environment.Exit(0);
}
catch (Exception exception1)
{
Exception exception = exception1;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("failed!");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(exception.Message);
Environment.Exit(-1);
}
}
}