Unverified Commit 2fd46994 authored by tunip3's avatar tunip3 Committed by GitHub
Browse files

Add files via upload

parent ac080d52
Loading
Loading
Loading
Loading

Appx packer.sln

0 → 100644
+25 −0
Original line number Diff line number Diff line

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Appx Packer", "Appxpacker\Appx Packer.csproj", "{1DBFB5B0-7D32-46F1-BBE0-79D80F00D96A}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{1DBFB5B0-7D32-46F1-BBE0-79D80F00D96A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{1DBFB5B0-7D32-46F1-BBE0-79D80F00D96A}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{1DBFB5B0-7D32-46F1-BBE0-79D80F00D96A}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{1DBFB5B0-7D32-46F1-BBE0-79D80F00D96A}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {D9454159-8720-4D0A-B4B6-8B7053999238}
	EndGlobalSection
EndGlobal

Appxpacker/App.config

0 → 100644
+6 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
</configuration>
 No newline at end of file
+84 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{1DBFB5B0-7D32-46F1-BBE0-79D80F00D96A}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <RootNamespace>Appxpacker</RootNamespace>
    <AssemblyName>Appx packer</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <EmbeddedResource Include="Form1.resx">
      <DependentUpon>Form1.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
 No newline at end of file
+149 −0
Original line number Diff line number Diff line
namespace WindowsFormsApp1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.inputdir = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.outputdir = new System.Windows.Forms.TextBox();
            this.start = new System.Windows.Forms.Button();
            this.status = new System.Windows.Forms.Label();
            this.id = new System.Windows.Forms.Button();
            this.od = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(9, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(50, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "App path";
            this.label1.Click += new System.EventHandler(this.label1_Click);
            // 
            // inputdir
            // 
            this.inputdir.Location = new System.Drawing.Point(12, 25);
            this.inputdir.Name = "inputdir";
            this.inputdir.Size = new System.Drawing.Size(356, 20);
            this.inputdir.TabIndex = 1;
            this.inputdir.TextChanged += new System.EventHandler(this.inputdir_TextChanged);
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(9, 48);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(68, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "Output folder";
            this.label2.Click += new System.EventHandler(this.label2_Click);
            // 
            // outputdir
            // 
            this.outputdir.Location = new System.Drawing.Point(12, 64);
            this.outputdir.Name = "outputdir";
            this.outputdir.Size = new System.Drawing.Size(356, 20);
            this.outputdir.TabIndex = 3;
            this.outputdir.TextChanged += new System.EventHandler(this.outputdir_TextChanged);
            // 
            // start
            // 
            this.start.Location = new System.Drawing.Point(12, 90);
            this.start.Name = "start";
            this.start.Size = new System.Drawing.Size(356, 26);
            this.start.TabIndex = 4;
            this.start.Text = "Create appx";
            this.start.UseVisualStyleBackColor = true;
            this.start.Click += new System.EventHandler(this.start_Click);
            // 
            // status
            // 
            this.status.AutoSize = true;
            this.status.Location = new System.Drawing.Point(12, 132);
            this.status.Name = "status";
            this.status.Size = new System.Drawing.Size(0, 13);
            this.status.TabIndex = 5;
            this.status.Click += new System.EventHandler(this.label3_Click);
            // 
            // id
            // 
            this.id.Location = new System.Drawing.Point(374, 24);
            this.id.Name = "id";
            this.id.Size = new System.Drawing.Size(26, 20);
            this.id.TabIndex = 6;
            this.id.Text = "...";
            this.id.UseVisualStyleBackColor = true;
            this.id.Click += new System.EventHandler(this.id_Click);
            // 
            // od
            // 
            this.od.Location = new System.Drawing.Point(374, 64);
            this.od.Name = "od";
            this.od.Size = new System.Drawing.Size(26, 19);
            this.od.TabIndex = 7;
            this.od.Text = "...";
            this.od.UseVisualStyleBackColor = true;
            this.od.Click += new System.EventHandler(this.od_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(412, 203);
            this.Controls.Add(this.od);
            this.Controls.Add(this.id);
            this.Controls.Add(this.status);
            this.Controls.Add(this.start);
            this.Controls.Add(this.outputdir);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.inputdir);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "Appx packer";
            this.Load += new System.EventHandler(this.Form1_Load_1);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox inputdir;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox outputdir;
        private System.Windows.Forms.Button start;
        private System.Windows.Forms.Label status;
        private System.Windows.Forms.Button id;
        private System.Windows.Forms.Button od;
    }
}

Appxpacker/Form1.cs

0 → 100644
+332 −0
Original line number Diff line number Diff line
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string AppCurrentDirctory = Directory.GetCurrentDirectory();

        private string WSAppXmlFile = "AppxManifest.xml";

        private string WSAppName;

        private string WSAppPath;

        private string WSAppVersion;

        private string WSAppFileName;

        private string WSAppOutputPath;

        private string WSAppProcessorArchitecture;

        private string WSAppPublisher;

        private bool Checking = true;

        public void Run()
        {
            ReadArg();
        }

        private string RunProcess(string fileName, string args)
        {
            string text = "";
            string result = "";
            Process process = new Process();
            process.StartInfo = new ProcessStartInfo
            {
                FileName = fileName,
                Arguments = args,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                CreateNoWindow = true
            };
            Process process2 = process;
            process2.Start();
            while (!process2.StandardOutput.EndOfStream)
            {
                text = process2.StandardOutput.ReadLine();
                if (text.Length > 0)
                {
                    result = text;
                }
            }
            return result;
        }

        private void ReadArg()
        {
            while (Checking)
            {
                WSAppPath = inputdir.Text;
                if (WSAppPath.Contains("\""))
                {
                    WSAppPath = WSAppPath.Replace("\"", "");
                    WSAppPath = "\"" + WSAppPath + "\"";
                }
                else if (File.Exists(WSAppPath + "\\" + WSAppXmlFile))
                {
                    while (Checking)
                    {
                        WSAppOutputPath = outputdir.Text;
                        if (WSAppOutputPath.Contains("\""))
                        {
                            WSAppOutputPath = WSAppOutputPath.Replace("\"", "");
                            WSAppOutputPath = "\"" + WSAppOutputPath + "\"";
                        }
                        else if (Directory.Exists(WSAppOutputPath))
                        {
                            WSAppFileName = Path.GetFileName(WSAppPath);
                            using (XmlReader xmlReader = XmlReader.Create(WSAppPath + "\\" + WSAppXmlFile))
                            {
                                while (xmlReader.Read())
                                {
                                    if (xmlReader.IsStartElement() && xmlReader.Name == "Identity")
                                    {
                                        string text = xmlReader["Name"];
                                        if (text != null)
                                        {
                                            WSAppName = text;
                                        }
                                        text = xmlReader["Publisher"];
                                        if (text != null)
                                        {
                                            WSAppPublisher = text;
                                        }
                                        text = xmlReader["Version"];
                                        if (text != null)
                                        {
                                            WSAppVersion = text;
                                        }
                                        text = xmlReader["ProcessorArchitecture"];
                                        if (text != null)
                                        {
                                            WSAppProcessorArchitecture = text;
                                        }
                                    }
                                }
                            }
                            while (Checking)
                            {
                                MakeAppx();
                            }
                        }
                        else
                        {
                            Checking = true;
                            throw new ArgumentException("Invailed Output Path, '{0}' Directory not found!", WSAppOutputPath);
                        }
                    }
                }
                else
                {
                    Checking = true;
                    throw new ArgumentException("Invailed App Path, '{0}' file not found!", WSAppXmlFile);
                }
            }
        }

        private void MakeAppx()
        {
            string text = AppCurrentDirctory + "\\Appxpacker\\MakeAppx.exe";
            string args = "pack -d \"" + WSAppPath + "\" -p \"" + WSAppOutputPath + "\\" + WSAppFileName + ".appx\" -l";
            if (File.Exists(text))
            {
                if (File.Exists(WSAppOutputPath + "\\" + WSAppFileName + ".appx"))
                {
                    File.Delete(WSAppOutputPath + "\\" + WSAppFileName + ".appx");
                }
                status.Text += ("Please wait.. Creating '.appx' package file.");

                string tempvar = WSAppFileName + ".appx";
                if (RunProcess(text, args).ToLower().Contains("succeeded"))
                {
                    status.Text += ("\nPackage "+ tempvar + " creation succeeded.");
                    while (Checking)
                    {
                        MakeCert();
                    }
                }
                else
                {
                    Checking = false;
                    throw new ArgumentException("Package '{0}' creation failed. ", WSAppFileName + ".appx");
                }
            }
            else
            {
                Checking = false;
                throw new ArgumentException("Can't create '.appx' file, 'MakeAppx.exe' file not found!");
            }
        }

        private void MakeCert()
        {
            string text = AppCurrentDirctory + "\\Appxpacker\\MakeCert.exe";
            string args = "-n \"" + WSAppPublisher + "\" -r -a sha256 -len 2048 -cy end -h 0 -eku 1.3.6.1.5.5.7.3.3 -b 01/01/2000 -sv \"" + WSAppOutputPath + "\\" + WSAppFileName + ".pvk\" \"" + WSAppOutputPath + "\\" + WSAppFileName + ".cer\"";
            if (File.Exists(text))
            {
                if (File.Exists(WSAppOutputPath + "\\" + WSAppFileName + ".pvk"))
                {
                    File.Delete(WSAppOutputPath + "\\" + WSAppFileName + ".pvk");
                }
                if (File.Exists(WSAppOutputPath + "\\" + WSAppFileName + ".cer"))
                {
                    File.Delete(WSAppOutputPath + "\\" + WSAppFileName + ".cer");
                }
                status.Text += ("\nPlease wait.. Creating certificate for the package.");
                if (RunProcess(text, args).ToLower().Contains("succeeded"))
                {
                    while (Checking)
                    {
                        Pvk2Pfx();
                    }
                }
                else
                {
                    Checking = false;
                    throw new ArgumentException("Failed to create Certificate for the package... Prees any Key exit.");
                }
            }
            else
            {
                Checking = false;
                throw new ArgumentException("Can't create Certificate for the package, 'MakeCert.exe' file not found!");
            }
        }

        private void Pvk2Pfx()
        {
            string text = AppCurrentDirctory + "\\Appxpacker\\Pvk2Pfx.exe";
            string args = "-pvk \"" + WSAppOutputPath + "\\" + WSAppFileName + ".pvk\" -spc \"" + WSAppOutputPath + "\\" + WSAppFileName + ".cer\" -pfx \"" + WSAppOutputPath + "\\" + WSAppFileName + ".pfx\"";
            if (File.Exists(text))
            {
                if (File.Exists(WSAppOutputPath + "\\" + WSAppFileName + ".pfx"))
                {
                    File.Delete(WSAppOutputPath + "\\" + WSAppFileName + ".pfx");
                }
                //Converting certificate to sign the package.
                if (RunProcess(text, args).Length == 0)
                {
                    while (Checking)
                    {
                        SignApp();
                    }
                }
                else
                {
                    Checking = false;
                    throw new ArgumentException("Can't convert certificate to sign the package... Prees any Key exit...");
                }
            }
            else
            {
                Checking = false;
                throw new ArgumentException("Can't convert Certificate to sign the package, 'Pvk2Pfx.exe' file not found!");
            }
        }

        private void SignApp()
        {
            string text = AppCurrentDirctory + "\\Appxpacker\\SignTool.exe";
            string args = "sign -fd SHA256 -a -f \"" + WSAppOutputPath + "\\" + WSAppFileName + ".pfx\" \"" + WSAppOutputPath + "\\" + WSAppFileName + ".appx\"";
            if (File.Exists(text))
            {
                status.Text += ("Please wait.. Signing the package, this may take some minutes.");
                if (RunProcess(text, args).ToLower().Contains("successfully signed"))
                {
                    Checking = false;
                    MessageBox.Show("Package signed and created. Please install the '.cer' file to [Local Computer\\Trusted Root Certification Authorities] before installing the Appx Package (if installing on pc)");
                }
                else
                {
                    Checking = false;
                    throw new ArgumentException("Can't Sign the package, Press any Key to exit...");
                }
            }
            else
            {
                Checking = false;
                throw new ArgumentException("Can't Sign the package, 'SignTool.exe' file not found!");
            }
        }

        private void start_Click(object sender, EventArgs e)
        {
            Run();
        }

        private void inputdir_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void outputdir_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load_1(object sender, EventArgs e)
        {

        }

        private void id_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog di = new FolderBrowserDialog();
            di.Description = " select download path";
            if (di.ShowDialog() == DialogResult.OK)
                inputdir.Text = di.SelectedPath;
        }

        private void od_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog duo = new FolderBrowserDialog();
            duo.Description = " select download path";
            if (duo.ShowDialog() == DialogResult.OK)
                outputdir.Text = duo.SelectedPath;
        }
    }
}
Loading