Skip to content

Commit

Permalink
Refactored code and embedded used assemblies.
Browse files Browse the repository at this point in the history
  • Loading branch information
jetspiking committed Apr 8, 2022
1 parent 0295aac commit 8e5662f
Show file tree
Hide file tree
Showing 35 changed files with 920 additions and 555 deletions.
4 changes: 2 additions & 2 deletions WPAppInstall/WPAppInstall/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
28 changes: 27 additions & 1 deletion WPAppInstall/WPAppInstall/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using WPAppInstall.Misc;

namespace WPAppInstall
{
public partial class App : Application
public partial class App : System.Windows.Application
{
private const String phoneRegDll = "PhoneRegDll.dll";

/// <summary>
/// Load embedded assemblies.
/// </summary>
[STAThread]
public static void Main()
{
EmbeddedAssemblyLoader embeddedAssemblyLoader = new EmbeddedAssemblyLoader();
embeddedAssemblyLoader.LoadUnmanagedLibraryFromResource(phoneRegDll);
StartProgram();
}

/// <summary>
/// Called after loading the neccessary assemblies.
/// </summary>
public static void StartProgram()
{
var application = new App();
application.InitializeComponent();
application.Run();
}
}
}
108 changes: 61 additions & 47 deletions WPAppInstall/WPAppInstall/Fragments/Apps.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
Expand All @@ -17,14 +14,16 @@ namespace WPAppInstall.Fragments
/// <summary>
/// This class builds the view / window to browse and display apps.
/// </summary>

public class Apps : IFragment
{
private readonly StackPanel _rootPanel = new StackPanel();
private readonly String _wp81FileExtension = "{0}|*.xap;*.appx;*.appxbundle";
private Grid _applicationsGrid = new Grid();
private int _applicationGridRowIndex = 0;

private readonly StackPanel rootPanel = new StackPanel();
private readonly String wp81FileExtension = "{0}|*.xap;*.appx;*.appxbundle";
private Grid applicationsGrid = new Grid();
private Int32 applicationGridRowIndex = 0;

/// <summary>
/// Build the view / window to browse and display apps.
/// </summary>
public Apps()
{
// Browse Apps Section
Expand All @@ -40,7 +39,7 @@ public Apps()
{
Content = deploymentAppsTextblock
};
_rootPanel.Children.Add(deploymentAppsLabel);
rootPanel.Children.Add(deploymentAppsLabel);

Button deploymentAppsButton = new Button
{
Expand All @@ -49,7 +48,7 @@ public Apps()
HorizontalAlignment = HorizontalAlignment.Left
};
deploymentAppsButton.Click += DeploymentAppsButton_Click;
_rootPanel.Children.Add(deploymentAppsButton);
rootPanel.Children.Add(deploymentAppsButton);

// Apps List
TextBlock appListTextblock = new TextBlock
Expand All @@ -64,7 +63,7 @@ public Apps()
{
Content = appListTextblock
};
_rootPanel.Children.Add(appListLabel);
rootPanel.Children.Add(appListLabel);

Button appListButton = new Button
{
Expand All @@ -73,71 +72,82 @@ public Apps()
HorizontalAlignment = HorizontalAlignment.Left
};
appListButton.Click += AppListButton_Click;
_rootPanel.Children.Add(appListButton);
rootPanel.Children.Add(appListButton);

ColumnDefinition appName = new ColumnDefinition();
ColumnDefinition appPath = new ColumnDefinition();
ColumnDefinition appGuid = new ColumnDefinition();

_applicationsGrid.ColumnDefinitions.Add(appName);
//_applicationsGrid.ColumnDefinitions.Add(appPath);
_applicationsGrid.ColumnDefinitions.Add(appGuid);
applicationsGrid.ColumnDefinitions.Add(appName);
applicationsGrid.ColumnDefinitions.Add(appGuid);

_applicationsGrid.Background = new SolidColorBrush(Colors.Black);
_rootPanel.Children.Add(_applicationsGrid);
applicationsGrid.Background = new SolidColorBrush(Colors.Black);
rootPanel.Children.Add(applicationsGrid);


if (Misc.Application.Lifecycle.paths.Length > 0) FillInfo();
if (Misc.Application.Lifecycle.Paths.Length > 0) FillInfo();
}

/// <summary>
/// On click clear and (re)load the list of apps.
/// </summary>
private void AppListButton_Click(object sender, RoutedEventArgs e)
{
_applicationsGrid.Children.Clear();
_applicationGridRowIndex = 0;
Misc.Application.Lifecycle.manifestInfoList = new Microsoft.Phone.Tools.Deploy.IAppManifestInfo[0];
Misc.Application.Lifecycle.paths = new String[0];
applicationsGrid.Children.Clear();
applicationGridRowIndex = 0;
Misc.Application.Lifecycle.ManifestInfoList = new Microsoft.Phone.Tools.Deploy.IAppManifestInfo[0];
Misc.Application.Lifecycle.Paths = new String[0];
}

/// <summary>
/// Open a file picker to select the applications to deploy.
/// </summary>
private void DeploymentAppsButton_Click(object sender, RoutedEventArgs e)
{
OpenFilePicker();
}

/// <summary>
/// Get the root of this view for displaying purposes.
/// </summary>
/// <returns>Root of this view.</returns>
public StackPanel GetRoot()
{
return _rootPanel;
return rootPanel;
}

/// <summary>
/// Fill the application grid.
/// </summary>
private void FillInfo()
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
_applicationsGrid.Children.Clear();
_applicationGridRowIndex = 0;
applicationsGrid.Children.Clear();
applicationGridRowIndex = 0;
for (int i = 0; i < Misc.Application.Lifecycle.manifestInfoList.Length; i++)
for (int i = 0; i < Misc.Application.Lifecycle.ManifestInfoList.Length; i++)
{
RowDefinition row = new RowDefinition();
_applicationsGrid.RowDefinitions.Add(row);
applicationsGrid.RowDefinitions.Add(row);
Label appName = new Label
{
Content = Misc.Application.Lifecycle.manifestInfoList[i].Name
Content = Misc.Application.Lifecycle.ManifestInfoList[i].Name
};
Label appPath = new Label
{
Content = Misc.Application.Lifecycle.paths[i].ToString()
Content = Misc.Application.Lifecycle.Paths[i].ToString()
};
Label appGuid = new Label
{
Content = Misc.Application.Lifecycle.manifestInfoList[i].ProductId.ToString()
Content = Misc.Application.Lifecycle.ManifestInfoList[i].ProductId.ToString()
};
_applicationsGrid.Children.Add(appName);
//_applicationsGrid.Children.Add(appPath);
_applicationsGrid.Children.Add(appGuid);
applicationsGrid.Children.Add(appName);
applicationsGrid.Children.Add(appGuid);
appName.Background = new SolidColorBrush(Colors.White);
appPath.Background = new SolidColorBrush(Colors.White);
Expand All @@ -148,38 +158,40 @@ private void FillInfo()
if (i==0)
topMargin = 1;
if (i==Misc.Application.Lifecycle.manifestInfoList.Length-1)
if (i==Misc.Application.Lifecycle.ManifestInfoList.Length-1)
bottomMargin = 1;
appName.Margin = new Thickness(1, topMargin, 0, bottomMargin);
appPath.Margin = new Thickness(1, topMargin, 1, bottomMargin);
appGuid.Margin = new Thickness(0, topMargin, 1, bottomMargin);
appName.SetValue(Grid.ColumnProperty, 0);
appName.SetValue(Grid.RowProperty, _applicationGridRowIndex);
appName.SetValue(Grid.RowProperty, applicationGridRowIndex);
appPath.SetValue(Grid.ColumnProperty, 1);
appPath.SetValue(Grid.RowProperty, _applicationGridRowIndex);
appPath.SetValue(Grid.RowProperty, applicationGridRowIndex);
appGuid.SetValue(Grid.ColumnProperty, 2);
appGuid.SetValue(Grid.RowProperty, _applicationGridRowIndex);
appGuid.SetValue(Grid.RowProperty, applicationGridRowIndex);
_applicationGridRowIndex++;
applicationGridRowIndex++;
}
}));
}

/// <summary>
/// Open a file picker to select the applications to deploy.
/// </summary>
private void OpenFilePicker()
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
Multiselect = true,
Title = Resources.Strings.AppStrings.DEPLOY_SELECT_APPS,

Filter = String.Format(_wp81FileExtension, Resources.Strings.AppStrings.DEPLOY_WP81_XAP_EXTENSION)
Filter = String.Format(wp81FileExtension, Resources.Strings.AppStrings.DEPLOY_WP81_XAP_EXTENSION)
};

bool? flag = openFileDialog.ShowDialog();
Boolean? flag = openFileDialog.ShowDialog();

if (flag != null && flag.Value)
{
Expand All @@ -189,7 +201,7 @@ private void OpenFilePicker()
List<Microsoft.Phone.Tools.Deploy.IAppManifestInfo> manifestList = new List<Microsoft.Phone.Tools.Deploy.IAppManifestInfo>();
List<String> pathList = new List<String>();
for (int i = 0; i < paths.Length; i++)
for (Int32 i = 0; i < paths.Length; i++)
{
try
{
Expand All @@ -203,17 +215,19 @@ private void OpenFilePicker()
}));
}
}
Misc.Application.Lifecycle.manifestInfoList = manifestList.ToArray();
Misc.Application.Lifecycle.paths = pathList.ToArray();
Misc.Application.Lifecycle.ManifestInfoList = manifestList.ToArray();
Misc.Application.Lifecycle.Paths = pathList.ToArray();
FillInfo();
}).Start();


}
}

/// <summary>
/// Show an error dialog for when reading the applications fails.
/// </summary>
/// <param name="error">Error to display.</param>
private void ShowErrorDialog(String error)
{
BitmapImage errorImage = Misc.Image.GetResourceImage(AppStrings.APP_DIALOG_ERROR, Misc.Image.Extensions.png);
Expand Down
Loading

0 comments on commit 8e5662f

Please sign in to comment.